You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/10/20 20:39:38 UTC

[GitHub] [commons-math] aherbert commented on a diff in pull request #216: JUnit5 assertThrows NeuronSquareMesh2DTest

aherbert commented on code in PR #216:
URL: https://github.com/apache/commons-math/pull/216#discussion_r1001090847


##########
commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/twod/NeuronSquareMesh2DTest.java:
##########
@@ -35,33 +35,39 @@
 import org.apache.commons.math4.neuralnet.Network;
 import org.apache.commons.math4.neuralnet.Neuron;
 import org.apache.commons.math4.neuralnet.SquareNeighbourhood;
+import org.junit.jupiter.api.function.Executable;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 /**
  * Tests for {@link NeuronSquareMesh2D} and {@link Network} functionality for
  * a two-dimensional network.
  */
 public class NeuronSquareMesh2DTest {
+
     private final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create();
     private final FeatureInitializer init = FeatureInitializerFactory.uniform(rng, 0, 2);
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testMinimalNetworkSize1() {
         final FeatureInitializer[] initArray = {init};
 
-        new NeuronSquareMesh2D(1, false,
-                               2, false,
-                               SquareNeighbourhood.VON_NEUMANN,
-                               initArray);
+        final Executable testMethod = () -> new NeuronSquareMesh2D(1, false,

Review Comment:
   Again, remove `Executable`. It is good practice to have only one potential source for the exception inside the assertThrows lambda. E.g. this is bad as the exception could be from either line:
   ```Java
   assertThrows(IllegalArgumentException.class, () -> {
       ClassA a = new ClassA();
       ClassB b = new ClassB(a);
   });
   ```
   This would be where we create object `a` outside the assertThrows and then isolate where we expect the exception (from `b`).
   
   Since we have a clean lambda function here then just put it in assertThrows.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org