Functional Programming in Java, Second Edition: p. 117, Nitpicking "verbose test"

In the given “old-school” test for the generation of an exception:

@Test public void VerboseExceptionTest() {
   rodCutter.setPrices(prices);
   try {
      rodCutter.maxProfit(0);
      fail("Expected exception for zero length");
   } catch(RodCutterException ex) {
      assertTrue(true);
   }
}
  • The name of the method is capitalized
  • The purpose of assertTrue(true) is unclear. Is there just for documentation? One would write a statement like assertTrue(someComplexBooleanExpression) but assertTrue(true) does nothing.

Thank you, David. Good catch on the method name. Fixed it.

The assertTrue is to avoid empty catch block or a comment to say that it is intended.

1 Like