001: /**
002: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
003: */package test.net.sourceforge.pmd.ast;
004:
005: import static org.junit.Assert.assertEquals;
006: import static org.junit.Assert.assertTrue;
007: import net.sourceforge.pmd.ast.ASTMethodDeclaration;
008:
009: import org.junit.Test;
010:
011: import test.net.sourceforge.pmd.testframework.ParserTst;
012:
013: import java.util.Iterator;
014: import java.util.Set;
015:
016: public class MethodDeclTest extends ParserTst {
017:
018: @Test
019: public void testPublic() throws Throwable {
020: String access[] = { "public" };
021: ASTMethodDeclaration amd = getMethodDecl(access);
022: assertTrue("Expecting method to be public.", amd.isPublic());
023: }
024:
025: @Test
026: public void testPrivate() throws Throwable {
027: String access[] = { "private" };
028: ASTMethodDeclaration amd = getMethodDecl(access);
029: assertTrue("Expecting method to be private.", amd.isPrivate());
030: }
031:
032: @Test
033: public void testProtected() throws Throwable {
034: String access[] = { "protected" };
035: ASTMethodDeclaration amd = getMethodDecl(access);
036: assertTrue("Expecting method to be protected.", amd
037: .isProtected());
038: }
039:
040: @Test
041: public void testFinal() throws Throwable {
042: String access[] = { "public", "final" };
043: ASTMethodDeclaration amd = getMethodDecl(access);
044: assertTrue("Expecting method to be final.", amd.isFinal());
045: assertTrue("Expecting method to be public.", amd.isPublic());
046: }
047:
048: @Test
049: public void testSynchronized() throws Throwable {
050: String access[] = { "public", "synchronized" };
051: ASTMethodDeclaration amd = getMethodDecl(access);
052: assertTrue("Expecting method to be synchronized.", amd
053: .isSynchronized());
054: assertTrue("Expecting method to be public.", amd.isPublic());
055: }
056:
057: @Test
058: public void testAbstract() throws Throwable {
059: String access[] = { "public", "abstract" };
060: ASTMethodDeclaration amd = getMethodDecl(access);
061: assertTrue("Expecting method to be abstract.", amd.isAbstract());
062: assertTrue("Expecting method to be public.", amd.isPublic());
063: }
064:
065: @Test
066: public void testNative() throws Throwable {
067: String access[] = { "private", "native" };
068: ASTMethodDeclaration amd = getMethodDecl(access);
069: assertTrue("Expecting method to be native.", amd.isNative());
070: assertTrue("Expecting method to be private.", amd.isPrivate());
071: }
072:
073: @Test
074: public void testStrict() throws Throwable {
075: String access[] = { "public", "strictfp" };
076: ASTMethodDeclaration amd = getMethodDecl(access);
077: assertTrue("Expecting method to be strict.", amd.isStrictfp());
078: assertTrue("Expecting method to be public.", amd.isPublic());
079: }
080:
081: public ASTMethodDeclaration getMethodDecl(String access[])
082: throws Throwable {
083: String javaCode = "public class Test { ";
084: for (int i = 0; i < access.length; i++) {
085: javaCode += access[i] + " ";
086: }
087:
088: javaCode += " void stuff() { } }";
089:
090: Set methods = getNodes(ASTMethodDeclaration.class, javaCode);
091:
092: assertEquals("Wrong number of methods", 1, methods.size());
093:
094: Iterator i = methods.iterator();
095: return (ASTMethodDeclaration) i.next();
096: }
097:
098: public static junit.framework.Test suite() {
099: return new junit.framework.JUnit4TestAdapter(
100: MethodDeclTest.class);
101: }
102: }
|