Skip to content

Commit

Permalink
Added m4_10_testExistenceOfToString
Browse files Browse the repository at this point in the history
  • Loading branch information
hhimanshu committed May 22, 2020
1 parent a0defac commit faf0c80
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/test/java/com/h2/Module04_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.*;
import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -302,7 +303,25 @@ public void m4_09_testCalculateMonthlyPaymentCorrectness() throws IllegalAccessE
}

@Test
public void m3_10_testMainMethodExists() {
public void m4_10_testExistenceOfToString() {
final String methodName = "toString";

final Optional<Class<?>> maybeMortgageCalculator = getMortgageClass();
assertTrue(maybeMortgageCalculator.isPresent(), classToFind + " must exist");
final Class<?> mortgageCalculator = maybeMortgageCalculator.get();

final Method[] methods = mortgageCalculator.getDeclaredMethods();
final List<Method> filteredMethod = Arrays.stream(methods).filter(method -> method.getName().equals(methodName)).collect(Collectors.toList());

assertEquals(1, filteredMethod.size(), classToFind + " should contain a method called '" + methodName + "'");

final Method method = filteredMethod.get(0);
assertTrue(isPublic(method), methodName + " must be declared as 'public'");
assertEquals(String.class, method.getReturnType(), methodName + " method must return a value of type 'String'");
}

@Test
public void m3_xx_testMainMethodExists() {
final String methodName = "main";

final Optional<Class<?>> maybeMortgageCalculator = getMortgageClass();
Expand Down

0 comments on commit faf0c80

Please sign in to comment.