commit
1200d8777a
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.reflection.exception.invocationtarget;
|
||||
|
||||
public class InvocationTargetExample {
|
||||
public int divideByZeroExample() {
|
||||
return 1 / 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.baeldung.reflection.exception.invocationtarget;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class InvocationTargetUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCallingMethodThrowsException_thenAssertCauseOfInvocationTargetException() throws Exception {
|
||||
|
||||
InvocationTargetExample targetExample = new InvocationTargetExample();
|
||||
Method method = InvocationTargetExample.class.getMethod("divideByZeroExample");
|
||||
|
||||
Exception exception = assertThrows(InvocationTargetException.class, () -> method.invoke(targetExample));
|
||||
|
||||
assertEquals(ArithmeticException.class, exception.getCause().getClass());
|
||||
}
|
||||
}
|
4
pom.xml
4
pom.xml
|
@ -814,7 +814,7 @@
|
|||
<module>spring-rest-shell</module>
|
||||
<module>spring-rest-simple</module>
|
||||
<module>spring-resttemplate</module>
|
||||
<!-- <module>spring-roo</module>-->
|
||||
<module>spring-roo</module>
|
||||
<module>spring-scheduling</module>
|
||||
<module>spring-security-modules/spring-security-acl</module>
|
||||
<module>spring-security-modules/spring-security-angular/server</module>
|
||||
|
@ -1416,7 +1416,7 @@
|
|||
<module>spring-rest-shell</module>
|
||||
<module>spring-rest-simple</module>
|
||||
<module>spring-resttemplate</module>
|
||||
<!-- <module>spring-roo</module>-->
|
||||
<module>spring-roo</module>
|
||||
|
||||
<module>spring-scheduling</module>
|
||||
<module>spring-security-modules/spring-security-acl</module>
|
||||
|
|
|
@ -413,7 +413,7 @@
|
|||
<repository>
|
||||
<id>spring-roo-repository</id>
|
||||
<name>Spring Roo Repository</name>
|
||||
<url>http://repo.spring.io/spring-roo</url>
|
||||
<url>https://repo.spring.io/spring-roo</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
|
Loading…
Reference in New Issue