KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > net > sourceforge > pmd > jaxen > MatchesFunctionTest


1 package test.net.sourceforge.pmd.jaxen;
2
3 import junit.framework.TestCase;
4 import net.sourceforge.pmd.ast.JavaParserVisitor;
5 import net.sourceforge.pmd.ast.Node;
6 import net.sourceforge.pmd.jaxen.Attribute;
7 import net.sourceforge.pmd.jaxen.MatchesFunction;
8 import org.jaxen.Context;
9 import org.jaxen.FunctionCallException;
10
11 import java.util.ArrayList JavaDoc;
12 import java.util.List JavaDoc;
13
14 public class MatchesFunctionTest extends TestCase implements Node {
15
16     public void jjtOpen() {
17     }
18
19     public void jjtClose() {
20     }
21
22     public void jjtSetParent(Node n) {
23     }
24
25     public Node jjtGetParent() {
26         return null;
27     }
28
29     public void jjtAddChild(Node n, int i) {
30     }
31
32     public Node jjtGetChild(int i) {
33         return null;
34     }
35
36     public int jjtGetNumChildren() {
37         return 0;
38     }
39
40     public Object JavaDoc jjtAccept(JavaParserVisitor visitor, Object JavaDoc data) {
41         return null;
42     }
43
44     private String JavaDoc className;
45
46     public String JavaDoc getValue() {
47         return className;
48     }
49
50     public void testMatch() throws FunctionCallException, NoSuchMethodException JavaDoc {
51         className = "Foo";
52         assertTrue(tryRegexp("Foo") instanceof List JavaDoc);
53     }
54
55     public void testNoMatch() throws FunctionCallException, NoSuchMethodException JavaDoc {
56         className = "bar";
57         assertTrue(tryRegexp("Foo") instanceof Boolean JavaDoc);
58         className = "FobboBar";
59         assertTrue(tryRegexp("Foo") instanceof Boolean JavaDoc);
60     }
61
62     private Object JavaDoc tryRegexp(String JavaDoc exp) throws FunctionCallException, NoSuchMethodException JavaDoc {
63         MatchesFunction function = new MatchesFunction();
64         List JavaDoc list = new ArrayList JavaDoc();
65         List JavaDoc attrs = new ArrayList JavaDoc();
66         attrs.add(new Attribute(this, "matches", getClass().getMethod("getValue", new Class JavaDoc[0])));
67         list.add(attrs);
68         list.add(exp);
69         Context c = new Context(null);
70         c.setNodeSet(new ArrayList JavaDoc());
71         return function.call(c, list);
72     }
73 }
74
75          
76
Popular Tags