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