diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptor.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptor.java index fa81a7e..fa46b55 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptor.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptor.java @@ -84,7 +84,7 @@ public class ExceptionHandlerInterceptor implements Serializable { loadHandlers(type); } - Method handler = getMethod(type, cause); + Method handler = getMethod(type, cause.getClass()); if (handler != null) { invoke(handler, ic.getTarget(), cause); handled = true; @@ -103,21 +103,7 @@ public class ExceptionHandlerInterceptor implements Serializable { } return type; - } - - /** - * If there is an handler in the current class for the expected exception, then this method will be returned; Else - * returns null; - * - * @param type - * @param cause - * @return - */ - private final Method getMethod(final Class type, final Exception cause) { - Method handler = null; - handler = getMethod(type, cause.getClass()); - return handler; - } + } /** diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java index d939ae0..f39c751 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java @@ -319,7 +319,7 @@ public class ExceptionHandlerInterceptorTest { public void manageWithClassThatContainsParentExceptionHandleMethod() throws Exception { ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); - expect(this.context.proceed()).andThrow(new TestException("TEST EXCEPTION")); + expect(this.context.proceed()).andThrow(new TestException("")); expect(CoreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); replayAll(this.context, CoreBootstrap.class); @@ -327,5 +327,41 @@ public class ExceptionHandlerInterceptorTest { assertEquals(1, classWithException.times); verifyAll(); } + + @Test + public void manageWithClassThatDoesNotContainsParentExceptionHandleMethod() throws Exception { + ClassWithoutMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithoutMethodsAnnotatedWithExceptionHandler(); + expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); + expect(this.context.proceed()).andThrow(new TestException("")); + expect(CoreBootstrap.isAnnotatedType(ClassWithoutMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); + replayAll(this.context, CoreBootstrap.class); + + try { + this.interceptor.manage(this.context); + fail(); + } catch (TestException e) { + assertTrue(true); + } + + verifyAll(); + } + + @Test + public void manageWithClassThatContainsOnlySubExceptionHandleMethod() throws Exception { + ClassWithExceptionHandlerMethodThatRethrowException classWithException = new ClassWithExceptionHandlerMethodThatRethrowException(); + expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); + expect(this.context.proceed()).andThrow(new DemoiselleException("")); + expect(CoreBootstrap.isAnnotatedType(ClassWithExceptionHandlerMethodThatRethrowException.class)).andReturn(true); + replayAll(this.context, CoreBootstrap.class); + + try { + this.interceptor.manage(this.context); + fail(); + } catch (DemoiselleException e) { + assertTrue(true); + } + + verifyAll(); + } } -- libgit2 0.21.2