KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tirsen > nanning > config > PointcutTest


1 package com.tirsen.nanning.config;
2
3 import com.tirsen.nanning.MixinInstance;
4 import com.tirsen.nanning.attribute.AbstractAttributesTest;
5
6 import java.lang.reflect.Method JavaDoc;
7
8 public class PointcutTest extends AbstractAttributesTest {
9
10     public static interface Interface {
11         void method();
12     }
13
14     public void testFalseAbstractPointcut() {
15         Pointcut falsePointcut = new AbstractPointcut() {
16             public boolean adviseMethod(Method JavaDoc method) {
17                 return false;
18             }
19         };
20         assertEquals(0, falsePointcut.methodsToAdvise(null, new MixinInstance(Interface.class, null)).length);
21     }
22
23     public void testTrueAbstractPointcut() {
24         Pointcut falsePointcut = new AbstractPointcut() {
25             public boolean adviseMethod(Method JavaDoc method) {
26                 return true;
27             }
28         };
29         assertEquals(1, falsePointcut.methodsToAdvise(null, new MixinInstance(Interface.class, null)).length);
30     }
31
32     public void testAttributePointcut() throws NoSuchMethodException JavaDoc {
33         AttributePointcut attributePointcut = new AttributePointcut("attribute");
34         Method JavaDoc methodWithAttribute = AttributesTestClass.class.getMethod("methodWithAttribute", null);
35         Method JavaDoc methodWithoutAttribute = AttributesTestClass.class.getMethod("methodWithoutAttribute", null);
36         assertTrue(attributePointcut.adviseMethod(methodWithAttribute));
37         assertFalse(attributePointcut.adviseMethod(methodWithoutAttribute));
38     }
39
40
41 }
42
Popular Tags