While executing PMD Apex on a project I got following parse exception (below). I'm attaching class file for reference.
C:\Projects\CAS\git\cas-2.0\src\classes\C2_Assignment_Report_EOD_Schedule_Test.cls:5: Apex unit tests should System.assert() or assertEquals() or assertNotEquals()
Exception applying rule ApexUnitTestClassShouldHaveAsserts on file C:\Projects\CAS\git\cas-2.0\src\classes\C2_Assignment_Report_Job_Test.cls, continuing with next rule
java.lang.IllegalArgumentException: expected one element but was: <BlockStatement, BlockStatement>
at com.google.common.collect.Iterators.getOnlyElement(Iterators.java:317)
at com.google.common.collect.Iterables.getOnlyElement(Iterables.java:289)
at net.sourceforge.pmd.lang.apex.rule.apexunit.ApexUnitTestClassShouldHaveAsserts.checkForAssertStatements(ApexUnitTestClassShouldHaveAsserts.java:32)
at net.sourceforge.pmd.lang.apex.rule.apexunit.ApexUnitTestClassShouldHaveAsserts.visit(ApexUnitTestClassShouldHaveAsserts.java:27)
at net.sourceforge.pmd.lang.apex.ast.ASTMethod.jjtAccept(ASTMethod.java:15)
at net.sourceforge.pmd.lang.apex.ast.AbstractApexNode.childrenAccept(AbstractApexNode.java:101)
at net.sourceforge.pmd.lang.apex.rule.AbstractApexRule.visit(AbstractApexRule.java:132)
at net.sourceforge.pmd.lang.apex.rule.AbstractApexRule.visit(AbstractApexRule.java:143)
at net.sourceforge.pmd.lang.apex.rule.apexunit.AbstractApexUnitTestRule.visit(AbstractApexUnitTestRule.java:30)
at net.sourceforge.pmd.lang.apex.rule.AbstractApexRule.visitAll(AbstractApexRule.java:121)
at net.sourceforge.pmd.lang.apex.rule.AbstractApexRule.apply(AbstractApexRule.java:115)
at net.sourceforge.pmd.RuleSet.apply(RuleSet.java:306)
at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:125)
at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:146)
at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:76)
at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:43)
at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:79)
at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:25)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
This parsing error add the violation to all testmethods !!!
I get the error message :
in all my test methods (even if the method have assert statement)
When i check the code of this rule i see that you set by default the
isAssertFound = false;See the code https://github.com/pmd/pmd/blob/master/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/apexunit/ApexUnitTestClassShouldHaveAsserts.java#L40
Thanks for your help
Last edit: Reda Benh 2016-09-06
This bug will be fixed with PMD 5.5.2 and later.
Commit: https://github.com/pmd/pmd/commit/9f9124b8fb17285d7326dd5c6f15579af1253f13
Thanks Andreas,
Can you please tell when you will release version 5.5.2 ?
Thanks
Soon - today or tomorrow :)