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;
12 import java.util.List;
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 jjtAccept(JavaParserVisitor visitor, Object data) {
41 return null;
42 }
43
44 private String className;
45
46 public String getValue() {
47 return className;
48 }
49
50 public void testMatch() throws FunctionCallException, NoSuchMethodException {
51 className = "Foo";
52 assertTrue(tryRegexp("Foo") instanceof List);
53 }
54
55 public void testNoMatch() throws FunctionCallException, NoSuchMethodException {
56 className = "bar";
57 assertTrue(tryRegexp("Foo") instanceof Boolean);
58 className = "FobboBar";
59 assertTrue(tryRegexp("Foo") instanceof Boolean);
60 }
61
62 private Object tryRegexp(String exp) throws FunctionCallException, NoSuchMethodException {
63 MatchesFunction function = new MatchesFunction();
64 List list = new ArrayList();
65 List attrs = new ArrayList();
66 attrs.add(new Attribute(this, "matches", getClass().getMethod("getValue", new Class[0])));
67 list.add(attrs);
68 list.add(exp);
69 Context c = new Context(null);
70 c.setNodeSet(new ArrayList());
71 return function.call(c, list);
72 }
73 }
74
75