Skip to content

Commit e4eaa5e

Browse files
committed
Added m5_04_testExecuteCommandExistence
1 parent f22b7d5 commit e4eaa5e

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/test/java/com/h2/Module05_Test.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.junit.platform.commons.function.Try;
55

66
import java.lang.reflect.Field;
7+
import java.lang.reflect.Method;
8+
import java.lang.reflect.Parameter;
79
import java.util.Map;
810
import java.util.Optional;
911
import java.util.Set;
@@ -89,7 +91,7 @@ public void m5_03_testCommandsToUsage() throws IllegalAccessException {
8991
});
9092

9193
} catch (NoSuchFieldException e) {
92-
fail("Cannot find a field called " + fieldName);
94+
fail("Cannot find a field called " + fieldName + " in class " + classToFind);
9395
}
9496
/*
9597
* 1. Existence of field
@@ -99,4 +101,23 @@ public void m5_03_testCommandsToUsage() throws IllegalAccessException {
99101
*/
100102
}
101103

104+
@Test
105+
public void m5_04_testExecuteCommandExistence() {
106+
final Optional<Class<?>> maybeClass = getFinanceClass();
107+
assertTrue(maybeClass.isPresent(), classToFind + " should be present");
108+
assertEquals(classToFind, maybeClass.get().getCanonicalName());
109+
110+
final Class<?> aClass = maybeClass.get();
111+
final String methodName = "executeCommand";
112+
113+
try {
114+
Method method = aClass.getDeclaredMethod(methodName, String.class, String[].class);
115+
assertTrue(isPrivate(method), methodName + " must be declared 'private'");
116+
assertTrue(isStatic(method), methodName + " must be declared 'static'");
117+
assertEquals(void.class, method.getReturnType(), methodName + " must have a 'void' return type");
118+
119+
} catch (NoSuchMethodException e) {
120+
fail("Can't find a method with name " + methodName + " in class " + classToFind + " with 2 parameters, first with type 'String', second with type 'String[]'");
121+
}
122+
}
102123
}

0 commit comments

Comments
 (0)