From e4eaa5e3740c52fb637048ff249805ff001394ff Mon Sep 17 00:00:00 2001 From: hhimanshu Date: Fri, 22 May 2020 18:37:45 -0700 Subject: [PATCH] Added m5_04_testExecuteCommandExistence --- src/test/java/com/h2/Module05_Test.java | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/h2/Module05_Test.java b/src/test/java/com/h2/Module05_Test.java index 4b45724f8..2d1b5bff8 100644 --- a/src/test/java/com/h2/Module05_Test.java +++ b/src/test/java/com/h2/Module05_Test.java @@ -4,6 +4,8 @@ import org.junit.platform.commons.function.Try; import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -89,7 +91,7 @@ public void m5_03_testCommandsToUsage() throws IllegalAccessException { }); } catch (NoSuchFieldException e) { - fail("Cannot find a field called " + fieldName); + fail("Cannot find a field called " + fieldName + " in class " + classToFind); } /* * 1. Existence of field @@ -99,4 +101,23 @@ public void m5_03_testCommandsToUsage() throws IllegalAccessException { */ } + @Test + public void m5_04_testExecuteCommandExistence() { + final Optional> maybeClass = getFinanceClass(); + assertTrue(maybeClass.isPresent(), classToFind + " should be present"); + assertEquals(classToFind, maybeClass.get().getCanonicalName()); + + final Class aClass = maybeClass.get(); + final String methodName = "executeCommand"; + + try { + Method method = aClass.getDeclaredMethod(methodName, String.class, String[].class); + assertTrue(isPrivate(method), methodName + " must be declared 'private'"); + assertTrue(isStatic(method), methodName + " must be declared 'static'"); + assertEquals(void.class, method.getReturnType(), methodName + " must have a 'void' return type"); + + } catch (NoSuchMethodException e) { + fail("Can't find a method with name " + methodName + " in class " + classToFind + " with 2 parameters, first with type 'String', second with type 'String[]'"); + } + } }