KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > net > sourceforge > pmd > ast > MethodDeclTest


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