Commit dc0905e31e3c0ddae697364b758aea4390ff7d66
1 parent
0bc5e8a3
Exists in
master
Alteracao do getMethod
Showing
2 changed files
with
39 additions
and
17 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptor.java
... | ... | @@ -84,7 +84,7 @@ public class ExceptionHandlerInterceptor implements Serializable { |
84 | 84 | loadHandlers(type); |
85 | 85 | } |
86 | 86 | |
87 | - Method handler = getMethod(type, cause); | |
87 | + Method handler = getMethod(type, cause.getClass()); | |
88 | 88 | if (handler != null) { |
89 | 89 | invoke(handler, ic.getTarget(), cause); |
90 | 90 | handled = true; |
... | ... | @@ -103,21 +103,7 @@ public class ExceptionHandlerInterceptor implements Serializable { |
103 | 103 | } |
104 | 104 | |
105 | 105 | return type; |
106 | - } | |
107 | - | |
108 | - /** | |
109 | - * If there is an handler in the current class for the expected exception, then this method will be returned; Else | |
110 | - * returns null; | |
111 | - * | |
112 | - * @param type | |
113 | - * @param cause | |
114 | - * @return | |
115 | - */ | |
116 | - private final Method getMethod(final Class<?> type, final Exception cause) { | |
117 | - Method handler = null; | |
118 | - handler = getMethod(type, cause.getClass()); | |
119 | - return handler; | |
120 | - } | |
106 | + } | |
121 | 107 | |
122 | 108 | |
123 | 109 | /** | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java
... | ... | @@ -319,7 +319,7 @@ public class ExceptionHandlerInterceptorTest { |
319 | 319 | public void manageWithClassThatContainsParentExceptionHandleMethod() throws Exception { |
320 | 320 | ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); |
321 | 321 | expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); |
322 | - expect(this.context.proceed()).andThrow(new TestException("TEST EXCEPTION")); | |
322 | + expect(this.context.proceed()).andThrow(new TestException("")); | |
323 | 323 | expect(CoreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); |
324 | 324 | replayAll(this.context, CoreBootstrap.class); |
325 | 325 | |
... | ... | @@ -327,5 +327,41 @@ public class ExceptionHandlerInterceptorTest { |
327 | 327 | assertEquals(1, classWithException.times); |
328 | 328 | verifyAll(); |
329 | 329 | } |
330 | + | |
331 | + @Test | |
332 | + public void manageWithClassThatDoesNotContainsParentExceptionHandleMethod() throws Exception { | |
333 | + ClassWithoutMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithoutMethodsAnnotatedWithExceptionHandler(); | |
334 | + expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
335 | + expect(this.context.proceed()).andThrow(new TestException("")); | |
336 | + expect(CoreBootstrap.isAnnotatedType(ClassWithoutMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); | |
337 | + replayAll(this.context, CoreBootstrap.class); | |
338 | + | |
339 | + try { | |
340 | + this.interceptor.manage(this.context); | |
341 | + fail(); | |
342 | + } catch (TestException e) { | |
343 | + assertTrue(true); | |
344 | + } | |
345 | + | |
346 | + verifyAll(); | |
347 | + } | |
348 | + | |
349 | + @Test | |
350 | + public void manageWithClassThatContainsOnlySubExceptionHandleMethod() throws Exception { | |
351 | + ClassWithExceptionHandlerMethodThatRethrowException classWithException = new ClassWithExceptionHandlerMethodThatRethrowException(); | |
352 | + expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
353 | + expect(this.context.proceed()).andThrow(new DemoiselleException("")); | |
354 | + expect(CoreBootstrap.isAnnotatedType(ClassWithExceptionHandlerMethodThatRethrowException.class)).andReturn(true); | |
355 | + replayAll(this.context, CoreBootstrap.class); | |
356 | + | |
357 | + try { | |
358 | + this.interceptor.manage(this.context); | |
359 | + fail(); | |
360 | + } catch (DemoiselleException e) { | |
361 | + assertTrue(true); | |
362 | + } | |
363 | + | |
364 | + verifyAll(); | |
365 | + } | |
330 | 366 | |
331 | 367 | } | ... | ... |