Commit 32f550d14567c203e8f2ca25d04ac7e7f68849ec

Authored by Cleverson Sacramento
1 parent 93fd874c
Exists in master

Organização do código

impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java
@@ -93,9 +93,7 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -93,9 +93,7 @@ public class ExceptionHandlerInterceptor implements Serializable {
93 CoreBootstrap bootstrap = Beans.getReference(CoreBootstrap.class); 93 CoreBootstrap bootstrap = Beans.getReference(CoreBootstrap.class);
94 94
95 if (!bootstrap.isAnnotatedType(type)) { 95 if (!bootstrap.isAnnotatedType(type)) {
96 - getLogger().debug(  
97 - getBundle().getString("proxy-detected", type,  
98 - type.getSuperclass())); 96 + getLogger().debug(getBundle().getString("proxy-detected", type, type.getSuperclass()));
99 type = type.getSuperclass(); 97 type = type.getSuperclass();
100 } 98 }
101 99
@@ -103,8 +101,8 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -103,8 +101,8 @@ public class ExceptionHandlerInterceptor implements Serializable {
103 } 101 }
104 102
105 /** 103 /**
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; 104 + * If there is an handler in the current class or superClass for the expected exception, then this method will be
  105 + * returned; Else returns null;
108 * 106 *
109 * @param type 107 * @param type
110 * @param causeClass 108 * @param causeClass
@@ -112,17 +110,15 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -112,17 +110,15 @@ public class ExceptionHandlerInterceptor implements Serializable {
112 */ 110 */
113 private final Method getMethod(final Class<?> type, final Class<?> causeClass) { 111 private final Method getMethod(final Class<?> type, final Class<?> causeClass) {
114 Method handler = null; 112 Method handler = null;
  113 + Map<Class<?>, Method> map = cache.get(type);
115 114
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 - } 115 + if (map != null && Throwable.class.isAssignableFrom(causeClass)) {
  116 + if (map.containsKey(causeClass)) {
  117 + handler = map.get(causeClass);
  118 + } else {
  119 + handler = getMethod(type, causeClass.getSuperclass());
  120 + }
  121 + }
126 122
127 return handler; 123 return handler;
128 } 124 }
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java
@@ -210,19 +210,6 @@ public class ExceptionHandlerInterceptorTest { @@ -210,19 +210,6 @@ 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  
226 public void manageWithClassThatContainsHandleMethodWithDiferentException() throws Exception { 213 public void manageWithClassThatContainsHandleMethodWithDiferentException() throws Exception {
227 ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); 214 ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler();
228 expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); 215 expect(this.context.getTarget()).andReturn(classWithException).anyTimes();
@@ -352,4 +339,3 @@ public class ExceptionHandlerInterceptorTest { @@ -352,4 +339,3 @@ public class ExceptionHandlerInterceptorTest {
352 } 339 }
353 } 340 }
354 } 341 }
355 -