Skip to content

Commit

Permalink
Added m5_04_testExecuteCommandExistence
Browse files Browse the repository at this point in the history
  • Loading branch information
hhimanshu committed May 23, 2020
1 parent f22b7d5 commit e4eaa5e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/test/java/com/h2/Module05_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -99,4 +101,23 @@ public void m5_03_testCommandsToUsage() throws IllegalAccessException {
*/
}

@Test
public void m5_04_testExecuteCommandExistence() {
final Optional<Class<?>> 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[]'");
}
}
}

0 comments on commit e4eaa5e

Please sign in to comment.