Skip to content

Commit

Permalink
Added m4_03_testExistenceOfNumberOfPayments
Browse files Browse the repository at this point in the history
  • Loading branch information
hhimanshu committed May 21, 2020
1 parent 40e4cb6 commit 1270a7b
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/test/java/com/h2/Module04_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Parameter;
import java.lang.reflect.*;
import java.util.*;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -133,4 +131,22 @@ public void m4_03_testMortgageConstructorAndCorrectness() throws IllegalAccessEx
}

}

@Test
public void m4_03_testExistenceOfNumberOfPayments() {
final String methodName = "getNumberOfPayments";

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 sumOfCredits = filteredMethod.get(0);
assertTrue(isPrivate(sumOfCredits), methodName + " must be declared as 'private'");
assertEquals(int.class, sumOfCredits.getReturnType(), methodName + " method must return a value of type 'int'");
}
}

0 comments on commit 1270a7b

Please sign in to comment.