diff --git a/pmd/regress/test/net/sourceforge/pmd/ast/ASTFormalParameterTest.java b/pmd/regress/test/net/sourceforge/pmd/ast/ASTFormalParameterTest.java index 0ff7757365..54ea479a46 100644 --- a/pmd/regress/test/net/sourceforge/pmd/ast/ASTFormalParameterTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/ast/ASTFormalParameterTest.java @@ -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 + + "}"; }