diff --git a/src/test/java/com/h2/Module04_Test.java b/src/test/java/com/h2/Module04_Test.java index 0389b929a..a92ce7722 100644 --- a/src/test/java/com/h2/Module04_Test.java +++ b/src/test/java/com/h2/Module04_Test.java @@ -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> maybeMortgageCalculator = getMortgageClass(); @@ -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> maybeMortgageCalculator = getMortgageClass(); assertTrue(maybeMortgageCalculator.isPresent(), classToFind + " must exist"); final Class mortgageCalculator = maybeMortgageCalculator.get(); @@ -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> maybeMortgageCalculator = getMortgageClass(); + assertTrue(maybeMortgageCalculator.isPresent(), classToFind + " must exist"); + final Class mortgageCalculator = maybeMortgageCalculator.get(); + + final Method[] methods = mortgageCalculator.getDeclaredMethods(); + final List 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'"); + } }