1 package test.net.sourceforge.pmd.ast;
2
3 import net.sourceforge.pmd.ast.ASTMethodDeclaration;
4
5 import java.util.Iterator;
6 import java.util.Set;
7
8 public class MethodDeclTest extends ParserTst {
9 public void testPublic() throws Throwable {
10 String access[] = {"public"};
11 ASTMethodDeclaration amd = getMethodDecl(access);
12 assertTrue("Expecting method to be public.", amd.isPublic());
13 }
14
15 public void testPrivate() throws Throwable {
16 String access[] = {"private"};
17 ASTMethodDeclaration amd = getMethodDecl(access);
18 assertTrue("Expecting method to be private.", amd.isPrivate());
19 }
20
21 public void testProtected() throws Throwable {
22 String access[] = {"protected"};
23 ASTMethodDeclaration amd = getMethodDecl(access);
24 assertTrue("Expecting method to be protected.", amd.isProtected());
25 }
26
27 public void testFinal() throws Throwable {
28 String access[] = {"public", "final"};
29 ASTMethodDeclaration amd = getMethodDecl(access);
30 assertTrue("Expecting method to be final.", amd.isFinal());
31 assertTrue("Expecting method to be public.", amd.isPublic());
32 }
33
34 public void testSynchronized() throws Throwable {
35 String access[] = {"public", "synchronized"};
36 ASTMethodDeclaration amd = getMethodDecl(access);
37 assertTrue("Expecting method to be synchronized.", amd.isSynchronized());
38 assertTrue("Expecting method to be public.", amd.isPublic());
39 }
40
41 public void testAbstract() throws Throwable {
42 String access[] = {"public", "abstract"};
43 ASTMethodDeclaration amd = getMethodDecl(access);
44 assertTrue("Expecting method to be abstract.", amd.isAbstract());
45 assertTrue("Expecting method to be public.", amd.isPublic());
46 }
47
48 public void testNative() throws Throwable {
49 String access[] = {"private", "native"};
50 ASTMethodDeclaration amd = getMethodDecl(access);
51 assertTrue("Expecting method to be native.", amd.isNative());
52 assertTrue("Expecting method to be private.", amd.isPrivate());
53 }
54
55 public void testStrict() throws Throwable {
56 String access[] = {"public", "strictfp"};
57 ASTMethodDeclaration amd = getMethodDecl(access);
58 assertTrue("Expecting method to be strict.", amd.isStrict());
59 assertTrue("Expecting method to be public.", amd.isPublic());
60 }
61
62 public ASTMethodDeclaration getMethodDecl(String access[]) throws Throwable {
63 String javaCode = "public class Test { ";
64 for (int i = 0; i < access.length; i++) {
65 javaCode += access[i] + " ";
66 }
67
68 javaCode += " void stuff() { } }";
69
70 Set methods = getNodes(ASTMethodDeclaration.class, javaCode);
71
72 assertEquals("Wrong number of methods", 1, methods.size());
73
74 Iterator i = methods.iterator();
75 return (ASTMethodDeclaration) i.next();
76 }
77 }
This page was automatically generated by Maven