KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tirsen > nanning > AttributeFilterTest


1 package com.tirsen.nanning;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import com.tirsen.nanning.attribute.AbstractAttributesTest;
7 import com.tirsen.nanning.definition.AspectClass;
8 import com.tirsen.nanning.definition.InterceptorDefinition;
9
10 /**
11  * TODO document AttributesTest
12  *
13  * <!-- $Id: AttributeFilterTest.java,v 1.8 2003/05/11 13:40:52 tirsen Exp $ -->
14  *
15  * @author $Author: tirsen $
16  * @version $Revision: 1.8 $
17  */

18 public class AttributeFilterTest extends AbstractAttributesTest {
19     private static List JavaDoc expectedMethods;
20
21     protected void setUp() throws Exception JavaDoc {
22         super.setUp();
23
24         // initialize the lists
25
expectedMethods = new ArrayList JavaDoc();
26         AttributeFilterInterceptor.invokedMethods.clear();
27     }
28
29     protected void tearDown() throws Exception JavaDoc {
30         super.tearDown();
31     }
32
33     public void testAttributes() throws Exception JavaDoc {
34         // expected methods
35
expectedMethods.add("doItAgain");
36         expectedMethods.add("oupsIDidItAgain");
37         //create the aspect and execute the methods
38
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 JavaDoc methodName = (String JavaDoc) expectedMethods.get(i);
50             assertTrue(methodName + " was not invoked", AttributeFilterInterceptor.invokedMethods.contains(methodName));
51         }
52     }
53
54     private Object JavaDoc 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