forked from phoedos/pmd
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:
@ -1,29 +1,41 @@
|
|||||||
package test.net.sourceforge.pmd.ast;
|
package test.net.sourceforge.pmd.ast;
|
||||||
|
|
||||||
import net.sourceforge.pmd.PMD;
|
import java.util.Iterator;
|
||||||
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.Set;
|
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 class ASTFormalParameterTest extends ParserTst {
|
||||||
|
|
||||||
public void testVarargs() throws Throwable {
|
public void testVarargs() throws Throwable {
|
||||||
|
int nrOfVarArgs = 0;
|
||||||
|
int nrOfNoVarArgs = 0;
|
||||||
|
|
||||||
Set ops = getNodes(new TargetJDK1_5(), ASTFormalParameter.class, TEST1);
|
Set ops = getNodes(new TargetJDK1_5(), ASTFormalParameter.class, TEST1);
|
||||||
ASTFormalParameter b = (ASTFormalParameter) ops.iterator().next();
|
for (Iterator iter = ops.iterator(); iter.hasNext();) {
|
||||||
if (!"x".equals(b.getImage())) {
|
ASTFormalParameter b = (ASTFormalParameter) iter.next();
|
||||||
assertTrue(b.isVarargs());
|
ASTVariableDeclaratorId variableDeclId = (ASTVariableDeclaratorId)b.getFirstChildOfType(ASTVariableDeclaratorId.class);
|
||||||
} else {
|
if (!"x".equals(variableDeclId.getImage())) {
|
||||||
assertFalse(b.isVarargs());
|
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 =
|
private static final String TEST1 =
|
||||||
"class Foo { " + PMD.EOL +
|
"class Foo {" + PMD.EOL +
|
||||||
" void bar(int x, int... others) {} " + PMD.EOL +
|
" void bar(int x, int... others) {}" + PMD.EOL +
|
||||||
"} ";
|
"}";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user