[java] Rename UnitTestShouldIncludeAssert again

to make it consistent and always use singular "UnitTest"
Follow-up on #4532 and #4965
This commit is contained in:
Andreas Dangel 2024-10-04 09:32:55 +02:00
parent 9fbaa4fbfb
commit c0023dd942
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
7 changed files with 38 additions and 38 deletions

View File

@ -20,12 +20,12 @@ This is a {{ site.pmd.release_type }} release.
Several rules for unit testing have been renamed to better reflect their actual scope. Lots of them were called
after JUnit / JUnit 4, even when they applied to JUnit 5 and / or TestNG.
* {% rule java/bestpractices/UnitTestAssertionsShouldIncludeMessage %} (Java Best Practices) has been renamed from `JUnitAssertionsShouldIncludeMessage`.
* {% rule java/bestpractices/UnitTestContainsTooManyAsserts %} (Java Best Practices) has been renamed from `JUnitTestContainsTooManyAsserts`.
* {% rule java/bestpractices/UnitTestShouldIncludeAssert %} (Java Best Practices) has been renamed from `JUnitTestsShouldIncludeAssert`.
* {% rule java/bestpractices/UnitTestShouldUseAfterAnnotation %} (Java Best Practices) has been renamed from `JUnit4TestShouldUseAfterAnnotation`.
* {% rule java/bestpractices/UnitTestShouldUseBeforeAnnotation %} (Java Best Practices) has been renamed from `JUnit4TestShouldUseBeforeAnnotation`.
* {% rule java/bestpractices/UnitTestShouldUseTestAnnotation %} (Java Best Practices) has been renamed from `JUnit4TestShouldUseTestAnnotation`.
* {% rule java/bestpractices/UnitTestAssertionsShouldIncludeMessage %} (Java Best Practices) has been renamed from `JUnitAssertionsShouldIncludeMessage`.
* {% rule java/bestpractices/UnitTestContainsTooManyAsserts %} (Java Best Practices) has been renamed from `JUnitTestContainsTooManyAsserts`.
* {% rule java/bestpractices/UnitTestsShouldIncludeAssert %} (Java Best Practices) has been renamed from `JUnitTestsShouldIncludeAssert`.
The old rule names still work but are deprecated.

View File

@ -5,9 +5,9 @@
package net.sourceforge.pmd.lang.java.rule.bestpractices;
/**
* @deprecated The rule was renamed {@link UnitTestsShouldIncludeAssertRule}
* @deprecated The rule was renamed {@link UnitTestShouldIncludeAssertRule}
*/
@Deprecated
public class JUnitTestsShouldIncludeAssertRule extends UnitTestsShouldIncludeAssertRule {
public class JUnitTestsShouldIncludeAssertRule extends UnitTestShouldIncludeAssertRule {
}

View File

@ -15,7 +15,7 @@ import net.sourceforge.pmd.lang.java.rule.internal.TestFrameworksUtil;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
public class UnitTestsShouldIncludeAssertRule extends AbstractJavaRulechainRule {
public class UnitTestShouldIncludeAssertRule extends AbstractJavaRulechainRule {
private static final PropertyDescriptor<Set<String>> EXTRA_ASSERT_METHOD_NAMES =
PropertyFactory.stringProperty("extraAssertMethodNames")
@ -24,7 +24,7 @@ public class UnitTestsShouldIncludeAssertRule extends AbstractJavaRulechainRule
.emptyDefaultValue()
.build();
public UnitTestsShouldIncludeAssertRule() {
public UnitTestShouldIncludeAssertRule() {
super(ASTMethodDeclaration.class);
definePropertyDescriptor(EXTRA_ASSERT_METHOD_NAMES);
}

View File

@ -748,7 +748,7 @@ class MyTest { // not public, that's fine
<rule name="JUnitTestContainsTooManyAsserts" deprecated="true" ref="UnitTestContainsTooManyAsserts"/>
<rule name="JUnitTestsShouldIncludeAssert" deprecated="true" ref="UnitTestsShouldIncludeAssert" />
<rule name="JUnitTestsShouldIncludeAssert" deprecated="true" ref="UnitTestShouldIncludeAssert" />
<rule name="JUnitUseExpected"
language="java"
@ -1292,6 +1292,34 @@ public class MyTestCase {
</example>
</rule>
<rule name="UnitTestShouldIncludeAssert"
language="java"
since="2.0"
message="This unit test should include assert() or fail()"
class="net.sourceforge.pmd.lang.java.rule.bestpractices.UnitTestShouldIncludeAssertRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#unittestshouldincludeassert">
<description>
Unit tests should include at least one assertion. This makes the tests more robust, and using assert
with messages provide the developer a clearer idea of what the test does.
This rule checks for JUnit (3, 4 and 5) and TestNG Tests.
</description>
<priority>3</priority>
<example>
<![CDATA[
public class Foo {
@Test
public void testSomething() {
Bar b = findBar();
// This is better than having a NullPointerException
// assertNotNull("bar not found", b);
b.work();
}
}
]]>
</example>
</rule>
<rule name="UnitTestShouldUseAfterAnnotation"
language="java"
since="4.0"
@ -1441,34 +1469,6 @@ public class MyTest {
</example>
</rule>
<rule name="UnitTestsShouldIncludeAssert"
language="java"
since="2.0"
message="Unit tests should include assert() or fail()"
class="net.sourceforge.pmd.lang.java.rule.bestpractices.UnitTestsShouldIncludeAssertRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#unittestsshouldincludeassert">
<description>
Unit tests should include at least one assertion. This makes the tests more robust, and using assert
with messages provide the developer a clearer idea of what the test does.
This rule checks for JUnit (3, 4 and 5) and TestNG Tests.
</description>
<priority>3</priority>
<example>
<![CDATA[
public class Foo {
@Test
public void testSomething() {
Bar b = findBar();
// This is better than having a NullPointerException
// assertNotNull("bar not found", b);
b.work();
}
}
]]>
</example>
</rule>
<rule name="UnnecessaryVarargsArrayCreation"
language="java"
since="7.1.0"

View File

@ -41,10 +41,10 @@
<!-- <rule ref="category/java/bestpractices.xml/SystemPrintln" /> -->
<!-- <rule ref="category/java/bestpractices.xml/UnitTestAssertionsShouldIncludeMessage" /> -->
<!-- <rule ref="category/java/bestpractices.xml/UnitTestContainsTooManyAsserts" /> -->
<!-- <rule ref="category/java/bestpractices.xml/UnitTestShouldIncludeAssert" /> -->
<!-- <rule ref="category/java/bestpractices.xml/UnitTestShouldUseAfterAnnotation" /> -->
<!-- <rule ref="category/java/bestpractices.xml/UnitTestShouldUseBeforeAnnotation" /> -->
<!-- <rule ref="category/java/bestpractices.xml/UnitTestShouldUseTestAnnotation" /> -->
<!-- <rule ref="category/java/bestpractices.xml/UnitTestsShouldIncludeAssert" /> -->
<!-- <rule ref="category/java/bestpractices.xml/UnnecessaryVarargsArrayCreation" /> -->
<!-- <rule ref="category/java/bestpractices.xml/UnusedAssignment"/> -->
<rule ref="category/java/bestpractices.xml/UnusedFormalParameter"/>

View File

@ -6,6 +6,6 @@ package net.sourceforge.pmd.lang.java.rule.bestpractices;
import net.sourceforge.pmd.test.PmdRuleTst;
class UnitTestsShouldIncludeAssertTest extends PmdRuleTst {
class UnitTestShouldIncludeAssertTest extends PmdRuleTst {
// no additional unit tests
}