99import java .io .ByteArrayOutputStream ;
1010import java .io .InputStream ;
1111import java .io .PrintStream ;
12+ import java .lang .annotation .Annotation ;
1213import java .lang .reflect .*;
1314import java .util .*;
1415import java .util .stream .Collectors ;
@@ -302,7 +303,25 @@ public void m4_09_testCalculateMonthlyPaymentCorrectness() throws IllegalAccessE
302303 }
303304
304305 @ Test
305- public void m3_10_testMainMethodExists () {
306+ public void m4_10_testExistenceOfToString () {
307+ final String methodName = "toString" ;
308+
309+ final Optional <Class <?>> maybeMortgageCalculator = getMortgageClass ();
310+ assertTrue (maybeMortgageCalculator .isPresent (), classToFind + " must exist" );
311+ final Class <?> mortgageCalculator = maybeMortgageCalculator .get ();
312+
313+ final Method [] methods = mortgageCalculator .getDeclaredMethods ();
314+ final List <Method > filteredMethod = Arrays .stream (methods ).filter (method -> method .getName ().equals (methodName )).collect (Collectors .toList ());
315+
316+ assertEquals (1 , filteredMethod .size (), classToFind + " should contain a method called '" + methodName + "'" );
317+
318+ final Method method = filteredMethod .get (0 );
319+ assertTrue (isPublic (method ), methodName + " must be declared as 'public'" );
320+ assertEquals (String .class , method .getReturnType (), methodName + " method must return a value of type 'String'" );
321+ }
322+
323+ @ Test
324+ public void m3_xx_testMainMethodExists () {
306325 final String methodName = "main" ;
307326
308327 final Optional <Class <?>> maybeMortgageCalculator = getMortgageClass ();
0 commit comments