Skip to content

Commit e19c356

Browse files
author
Vikas Ramsingh Rajput
committed
BAEL-3504: Added Unit test file and removed old class file
1 parent b76640b commit e19c356

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/exception/invocationtarget/InvocationTargetDemo.java

Lines changed: 0 additions & 19 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.reflection.exception.invocationtarget;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
5+
6+
import java.lang.reflect.InvocationTargetException;
7+
import java.lang.reflect.Method;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
public class InvocationTargetUnitTest {
12+
13+
@Test
14+
public void whenCallingMethodThrowsException_thenAssertTrue() throws Exception {
15+
InvocationTargetExample targetExample = new InvocationTargetExample();
16+
Method method = InvocationTargetExample.class.getMethod("divideByZeroExample");
17+
Exception exception = assertThrows(InvocationTargetException.class, () -> method.invoke(targetExample));
18+
assertEquals(ArithmeticException.class, exception.getCause().getClass());
19+
}
20+
}

0 commit comments

Comments
 (0)