Fixed bug testing regular parameters in the test code

Both possibilities are now tested (with test verification check)


git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4823 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Wouter Zelle
2006-11-21 17:51:41 +00:00
parent 222563dc32
commit 9b937f6191

View File

@ -1,29 +1,41 @@
package test.net.sourceforge.pmd.ast;
import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.TargetJDK1_4;
import net.sourceforge.pmd.TargetJDK1_5;
import net.sourceforge.pmd.ast.ASTBooleanLiteral;
import net.sourceforge.pmd.ast.ASTFormalParameter;
import test.net.sourceforge.pmd.testframework.ParserTst;
import java.util.Iterator;
import java.util.Set;
import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.TargetJDK1_5;
import net.sourceforge.pmd.ast.ASTFormalParameter;
import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;
import test.net.sourceforge.pmd.testframework.ParserTst;
public class ASTFormalParameterTest extends ParserTst {
public void testVarargs() throws Throwable {
int nrOfVarArgs = 0;
int nrOfNoVarArgs = 0;
Set ops = getNodes(new TargetJDK1_5(), ASTFormalParameter.class, TEST1);
ASTFormalParameter b = (ASTFormalParameter) ops.iterator().next();
if (!"x".equals(b.getImage())) {
assertTrue(b.isVarargs());
} else {
assertFalse(b.isVarargs());
for (Iterator iter = ops.iterator(); iter.hasNext();) {
ASTFormalParameter b = (ASTFormalParameter) iter.next();
ASTVariableDeclaratorId variableDeclId = (ASTVariableDeclaratorId)b.getFirstChildOfType(ASTVariableDeclaratorId.class);
if (!"x".equals(variableDeclId.getImage())) {
assertTrue(b.isVarargs());
nrOfVarArgs++;
} else {
assertFalse(b.isVarargs());
nrOfNoVarArgs++;
}
}
//Ensure that both possibilities are tested
assertEquals(1, nrOfVarArgs);
assertEquals(1, nrOfNoVarArgs);
}
private static final String TEST1 =
"class Foo { " + PMD.EOL +
" void bar(int x, int... others) {} " + PMD.EOL +
"} ";
"class Foo {" + PMD.EOL +
" void bar(int x, int... others) {}" + PMD.EOL +
"}";
}