False positive with JUnit4TestShouldUseBeforeAnnotation
A source code analyzer
Brought to you by:
adangel,
juansotuyo
There is a false positive with the example below :
:::xml
<test-code>
<description><![CDATA[
False positive with JUnit4TestShouldUseBeforeAnnotation
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@Before ("@ResetEsSetup")
public void setUp() {
esSetup.execute(EsSetup.deleteAll());
}
}
]]></code>
</test-code>
But, there is not problem if the setUp() method is renamed.
Thanks,
Diff:
"There is no problem if the setUp() method is renamed" - this is intentional. The rule migrating/JUnit4TestShouldUseBeforeAnnotation will only be triggered by methods named "setUp", as this was the Junit3 way of configuring a before hook. If the method is renamed, you already have migrated to the junit4 solution.
However, I don't fully understand your sample code: The @Before annotation doesn't take a value argument (
"@ResetEsSetup") -> https://github.com/junit-team/junit/blob/master/src/main/java/org/junit/Before.javaDoes you code compile?
I'll nevertheless relax the rule, to not stumble over the the "SingleValueAnnotation" type...
This will be fixed with PMD 5.3.4.
Commit: https://github.com/pmd/pmd/commit/f0dd2b0519a4c9647017eeb57df1445ce46fd0c7
Sorry, I was too quick to create this issue. In fact, my @Before annotation is a cucumber annotation which is "Junit-like" and can have parameters.
Thanks for your fix, this will solve my problem.