Skip to content

Commit

Permalink
Added m4_06_testExistenceOfMonthlyInterestRate
Browse files Browse the repository at this point in the history
  • Loading branch information
hhimanshu committed May 21, 2020
1 parent c3838d4 commit 92341ed
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/test/java/com/h2/Module04_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void m4_03_testMortgageConstructorAndCorrectness() throws IllegalAccessEx
}

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

final Optional<Class<?>> maybeMortgageCalculator = getMortgageClass();
Expand All @@ -150,7 +150,7 @@ public void m4_03_testExistenceOfNumberOfPayments() {
}

@Test
public void m4_04_testNumberOfPaymentsCorrectness() throws IllegalAccessException, InvocationTargetException, InstantiationException {
public void m4_05_testNumberOfPaymentsCorrectness() throws IllegalAccessException, InvocationTargetException, InstantiationException {
final Optional<Class<?>> maybeMortgageCalculator = getMortgageClass();
assertTrue(maybeMortgageCalculator.isPresent(), classToFind + " must exist");
final Class<?> mortgageCalculator = maybeMortgageCalculator.get();
Expand Down Expand Up @@ -184,4 +184,22 @@ public void m4_04_testNumberOfPaymentsCorrectness() throws IllegalAccessExceptio
int expected = 12 * termInYears;
assertEquals(expected, result, methodName + " should return " + expected + " number of payments for termInYears of " + termInYears);
}

@Test
public void m4_06_testExistenceOfMonthlyInterestRate() {
final String methodName = "getMonthlyInterestRate";

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

0 comments on commit 92341ed

Please sign in to comment.