KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > reflect > MatcherTest


1 package org.sapia.soto.reflect;
2
3 import junit.framework.TestCase;
4
5 import java.util.List JavaDoc;
6
7
8 /**
9  * @author Yanick Duchesne
10  * 18-Aug-2003
11  */

12 public class MatcherTest extends TestCase {
13   /**
14    * Constructor for FilterTest.
15    */

16   public MatcherTest(String JavaDoc name) {
17     super(name);
18   }
19
20   public void testNoMethodName() throws Exception JavaDoc {
21     Matcher m = new Matcher();
22     m.setDeclaredMethods(true);
23     m.setSig("java.lang.String");
24
25     List JavaDoc methods = m.scanMethods(Dog.class);
26     super.assertEquals(2, methods.size());
27   }
28
29   public void testWithMethodName() throws Exception JavaDoc {
30     Matcher m = new Matcher();
31     m.setDeclaredMethods(true);
32     m.setName("setName");
33     m.setSig("java.lang.String");
34
35     List JavaDoc methods = m.scanMethods(Dog.class);
36     super.assertEquals(1, methods.size());
37     m = new Matcher();
38     m.setDeclaredMethods(true);
39     m.setName("getName");
40     m.setSig("");
41     methods = m.scanMethods(Dog.class);
42     super.assertEquals(1, methods.size());
43   }
44
45   public void testNoSig() throws Exception JavaDoc {
46     Matcher m = new Matcher();
47     m.setDeclaredMethods(true);
48     m.setName("*Name");
49
50     List JavaDoc methods = m.scanMethods(Dog.class);
51     super.assertEquals(2, methods.size());
52   }
53
54   public void testNoSigNoMethod() throws Exception JavaDoc {
55     Matcher m = new Matcher();
56     m.setDeclaredMethods(true);
57
58     List JavaDoc methods = m.scanMethods(Dog.class);
59     super.assertEquals(9, methods.size());
60   }
61
62   public void testPublicMethods() throws Exception JavaDoc {
63     Matcher m = new Matcher();
64     m.setDeclaredMethods(true);
65     m.setName("setAttribute*");
66     m.setVisibility("public");
67
68     List JavaDoc methods = m.scanMethods(Dog.class);
69     super.assertEquals(1, methods.size());
70   }
71
72   public void testProtectedMethods() throws Exception JavaDoc {
73     Matcher m = new Matcher();
74     m.setDeclaredMethods(true);
75     m.setName("setAttribute*");
76     m.setVisibility("protected");
77
78     List JavaDoc methods = m.scanMethods(Dog.class);
79     super.assertEquals(1, methods.size());
80   }
81
82   public void testPrivateMethods() throws Exception JavaDoc {
83     Matcher m = new Matcher();
84     m.setDeclaredMethods(true);
85     m.setName("setAttribute*");
86     m.setVisibility("private");
87
88     List JavaDoc methods = m.scanMethods(Dog.class);
89     super.assertEquals(1, methods.size());
90   }
91
92   public void testPublicProtectedMethods() throws Exception JavaDoc {
93     Matcher m = new Matcher();
94     m.setDeclaredMethods(true);
95     m.setName("setAttribute*");
96     m.setVisibility("public, protected");
97
98     List JavaDoc methods = m.scanMethods(Dog.class);
99     super.assertEquals(2, methods.size());
100   }
101
102   public void testIncludeNoExclude() throws Exception JavaDoc {
103     Matcher m = new Matcher();
104     m.setName("*");
105     m.setVisibility("public, protected");
106     m.setIncludes("**.*Dog");
107
108     List JavaDoc methods = m.scanMethods(Dog.class);
109     super.assertEquals(7, methods.size());
110   }
111
112   public void testIncludeExclude() throws Exception JavaDoc {
113     Matcher m = new Matcher();
114     m.setName("*");
115     m.setVisibility("public, protected");
116     m.setIncludes("**.*Dog, java.lang.Object");
117     m.setExcludes("**.Object");
118
119     List JavaDoc methods = m.scanMethods(Dog.class);
120     super.assertEquals(7, methods.size());
121   }
122
123   public void testExcludeNoInclude() throws Exception JavaDoc {
124     Matcher m = new Matcher();
125     m.setName("*");
126     m.setVisibility("public, protected");
127     m.setExcludes("**.Object");
128
129     List JavaDoc methods = m.scanMethods(Dog.class);
130     super.assertEquals(8, methods.size());
131   }
132
133   public static class Dog extends Animal {
134     public String JavaDoc getName() {
135       return null;
136     }
137
138     public void setName(String JavaDoc name) {
139     }
140
141     public int getAge() {
142       return 0;
143     }
144
145     public void setAge(int age) {
146     }
147
148     public String JavaDoc getColor() {
149       return null;
150     }
151
152     public void setColor(String JavaDoc color) {
153     }
154
155     protected void setAttributeProtected(int i) {
156     }
157
158     private void setAttributePrivate(int i) {
159     }
160
161     public void setAttributePublic(int i) {
162     }
163   }
164
165   public static class Animal {
166     public int compareTo(Object JavaDoc arg0) {
167       return 0;
168     }
169   }
170 }
171
Popular Tags