Skip to content

Commit 94feef1

Browse files
committed
Add missing tests for ReflectionSupport.invokeMethod()
1 parent f44052b commit 94feef1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

platform-tests/src/test/java/org/junit/platform/commons/support/ReflectionSupportTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,24 @@ void newInstancePreconditions() {
157157
() -> ReflectionSupport.newInstance(String.class, new Object[] { null }));
158158
}
159159

160+
@Test
161+
void invokeMethodDelegates() throws Exception {
162+
Method method = Boolean.class.getMethod("valueOf", String.class);
163+
assertEquals(ReflectionUtils.invokeMethod(method, null, "true"),
164+
ReflectionSupport.invokeMethod(method, null, "true"));
165+
}
166+
167+
@Test
168+
void invokeMethodPreconditions() throws Exception {
169+
assertPreconditionViolationException("Method", () -> ReflectionSupport.invokeMethod(null, null, "true"));
170+
171+
Method method = Boolean.class.getMethod("toString");
172+
PreconditionViolationException exception = assertThrows(PreconditionViolationException.class,
173+
() -> ReflectionSupport.invokeMethod(method, null));
174+
assertEquals("Cannot invoke non-static method [" + method.toGenericString() + "] on a null target.",
175+
exception.getMessage());
176+
}
177+
160178
@Test
161179
void findFieldsDelegates() {
162180
assertEquals(

0 commit comments

Comments
 (0)