1 package com.tirsen.nanning; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import com.tirsen.nanning.attribute.AbstractAttributesTest; 7 import com.tirsen.nanning.definition.AspectClass; 8 import com.tirsen.nanning.definition.InterceptorDefinition; 9 10 18 public class AttributeFilterTest extends AbstractAttributesTest { 19 private static List expectedMethods; 20 21 protected void setUp() throws Exception { 22 super.setUp(); 23 24 expectedMethods = new ArrayList (); 26 AttributeFilterInterceptor.invokedMethods.clear(); 27 } 28 29 protected void tearDown() throws Exception { 30 super.tearDown(); 31 } 32 33 public void testAttributes() throws Exception { 34 expectedMethods.add("doItAgain"); 36 expectedMethods.add("oupsIDidItAgain"); 37 SomeAspect aspect = (SomeAspect) createAspectProxy(); 39 aspect.doIt(); 40 aspect.doItAgain(); 41 aspect.oupsIDidItAgain(); 42 43 verify(); 44 } 45 46 private void verify() { 47 assertEquals("number of executed methods was not as expected", expectedMethods.size(), AttributeFilterInterceptor.invokedMethods.size()); 48 for (int i = 0; i < expectedMethods.size(); i++) { 49 String methodName = (String ) expectedMethods.get(i); 50 assertTrue(methodName + " was not invoked", AttributeFilterInterceptor.invokedMethods.contains(methodName)); 51 } 52 } 53 54 private Object createAspectProxy() { 55 AspectClass aspectClass = new AspectClass(); 56 aspectClass.setInterface(SomeAspect.class); 57 InterceptorDefinition interceptorDefinition = new InterceptorDefinition(AttributeFilterInterceptor.class); 58 aspectClass.addInterceptor(interceptorDefinition); 59 aspectClass.setTarget(SomeAspectImpl.class); 60 61 return aspectClass.newInstance(); 62 63 } 64 65 66 public static class SomeAspectImpl implements SomeAspect { 67 public boolean doIt() { 68 return true; 69 } 70 71 72 public boolean doItAgain() { 73 return true; 74 } 75 76 public boolean oupsIDidItAgain() { 77 return true; 78 } 79 80 81 } 82 83 public static interface SomeAspect { 84 public boolean doIt(); 85 86 public boolean doItAgain(); 87 88 public boolean oupsIDidItAgain(); 89 90 } 91 92 93 } 94 | Popular Tags |