Commit 93fd874cf949df242bb09a001803506232742b82

Authored by Cleverson Sacramento
2 parents 40ae7b01 ac0bf565
Exists in master

Merge branch '2.4.0' of git@github.com:demoiselle/framework.git into 2.4.0

impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java
@@ -79,7 +79,7 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -79,7 +79,7 @@ public class ExceptionHandlerInterceptor implements Serializable {
79 loadHandlers(type); 79 loadHandlers(type);
80 } 80 }
81 81
82 - Method handler = getMethod(type, cause); 82 + Method handler = getMethod(type, cause.getClass());
83 if (handler != null) { 83 if (handler != null) {
84 invoke(handler, target, cause); 84 invoke(handler, target, cause);
85 handled = true; 85 handled = true;
@@ -103,19 +103,26 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -103,19 +103,26 @@ public class ExceptionHandlerInterceptor implements Serializable {
103 } 103 }
104 104
105 /** 105 /**
106 - * If there is an handler in the current class for the expected exception, then this method will be returned; Else 106 + * If there is an handler in the current class or superClass for the expected exception, then this method will be returned; Else
107 * returns null; 107 * returns null;
108 * 108 *
109 * @param type 109 * @param type
110 - * @param cause 110 + * @param causeClass
111 * @return 111 * @return
112 */ 112 */
113 - private final Method getMethod(final Class<?> type, final Exception cause) { 113 + private final Method getMethod(final Class<?> type, final Class<?> causeClass) {
114 Method handler = null; 114 Method handler = null;
115 115
116 - if (cache.containsKey(type) && cache.get(type).containsKey(cause.getClass())) {  
117 - handler = cache.get(type).get(cause.getClass());  
118 - } 116 + if (cache.containsKey(type) ){
  117 + Map<Class<?>, Method> map = cache.get(type);
  118 + if(Throwable.class.isAssignableFrom(causeClass)){
  119 + if(map.containsKey(causeClass)){
  120 + handler = map.get(causeClass);
  121 + }else{
  122 + handler = getMethod(type, causeClass.getSuperclass());
  123 + }
  124 + }
  125 + }
119 126
120 return handler; 127 return handler;
121 } 128 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptor.java
@@ -65,3 +65,4 @@ public class ExceptionHandlerInterceptor extends br.gov.frameworkdemoiselle.exce @@ -65,3 +65,4 @@ public class ExceptionHandlerInterceptor extends br.gov.frameworkdemoiselle.exce
65 return super.manage(ic); 65 return super.manage(ic);
66 } 66 }
67 } 67 }
  68 +
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java
@@ -210,6 +210,19 @@ public class ExceptionHandlerInterceptorTest { @@ -210,6 +210,19 @@ public class ExceptionHandlerInterceptorTest {
210 } 210 }
211 211
212 @Test 212 @Test
  213 + public void manageWithClassThatContainsParentExceptionHandleMethod() throws Exception {
  214 + ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler();
  215 + expect(this.context.getTarget()).andReturn(classWithException).anyTimes();
  216 + expect(this.context.proceed()).andThrow(new DemoiselleException(""));
  217 + expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true);
  218 + replayAll(this.context, this.coreBootstrap, Beans.class);
  219 +
  220 + assertNull(this.interceptor.manage(this.context));
  221 + assertEquals(1, classWithException.times);
  222 + verifyAll();
  223 + }
  224 +
  225 + @Test
213 public void manageWithClassThatContainsHandleMethodWithDiferentException() throws Exception { 226 public void manageWithClassThatContainsHandleMethodWithDiferentException() throws Exception {
214 ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); 227 ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler();
215 expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); 228 expect(this.context.getTarget()).andReturn(classWithException).anyTimes();
@@ -338,5 +351,5 @@ public class ExceptionHandlerInterceptorTest { @@ -338,5 +351,5 @@ public class ExceptionHandlerInterceptorTest {
338 assertEquals(1, testClass.times); 351 assertEquals(1, testClass.times);
339 } 352 }
340 } 353 }
341 -  
342 } 354 }
  355 +