From eba2eb27f6fcfb9f34bd255b8e4f8d3f242bfbf3 Mon Sep 17 00:00:00 2001 From: hhimanshu Date: Wed, 20 May 2020 17:04:10 -0700 Subject: [PATCH] Updated m3_04_testFieldsValueSetWhenConstructorCalled,m3_06_testSumOfCreditsWorksCorrectly,m3_08_testSumOfDebitsWorksCorrectly with constructor check --- src/test/java/com/h2/Module3_Test.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/com/h2/Module3_Test.java b/src/test/java/com/h2/Module3_Test.java index c247e186a..3246dcc24 100644 --- a/src/test/java/com/h2/Module3_Test.java +++ b/src/test/java/com/h2/Module3_Test.java @@ -109,6 +109,10 @@ public void m3_04_testFieldsValueSetWhenConstructorCalled() throws IllegalAccess float[] credits = new float[]{10.0f, 20.0f}; float[] debits = new float[]{5.0f}; final Constructor constructor = constructors[0]; + + int parameterCount = constructor.getParameterCount(); + assertEquals(2, parameterCount, classToFind + " must have a constructor with 2 parameters - credits and debits, both should be of type 'float[]'"); + Object instance = constructor.newInstance(credits, debits); final Field[] fields = savingsCalculator.getDeclaredFields(); @@ -154,6 +158,10 @@ public void m3_06_testSumOfCreditsWorksCorrectly() throws IllegalAccessException float[] credits = new float[]{10.0f, 20.0f}; float[] debits = new float[]{5.0f}; final Constructor constructor = constructors[0]; + + int parameterCount = constructor.getParameterCount(); + assertEquals(2, parameterCount, classToFind + " must have a constructor with 2 parameters - credits and debits, both should be of type 'float[]'"); + Object instance = constructor.newInstance(credits, debits); final String methodName = "sumOfCredits"; @@ -196,6 +204,10 @@ public void m3_08_testSumOfDebitsWorksCorrectly() throws IllegalAccessException, float[] credits = new float[]{10.0f, 20.0f}; float[] debits = new float[]{5.0f, 10.f}; final Constructor constructor = constructors[0]; + + int parameterCount = constructor.getParameterCount(); + assertEquals(2, parameterCount, classToFind + " must have a constructor with 2 parameters - credits and debits, both should be of type 'float[]'"); + Object instance = constructor.newInstance(credits, debits); final String methodName = "sumOfDebits";