Merge branch 'master' into pr/3415
This commit is contained in:
@ -16,7 +16,16 @@ This is a {{ site.pmd.release_type }} release.
|
||||
|
||||
#### New rules
|
||||
|
||||
This release ships with 1 new Java rule.
|
||||
This release ships with 2 new Java rules.
|
||||
|
||||
* {% rule java/bestpractices/SimplifiableTestAssertion %} suggests rewriting
|
||||
some test assertions to be more readable.
|
||||
|
||||
```xml
|
||||
<rule ref="category/java/bestpractices.xml/SimplifiableTestAssertion" />
|
||||
```
|
||||
|
||||
The rule is part of the quickstart.xml ruleset.
|
||||
|
||||
* {% rule java/errorprone/ReturnEmptyCollectionRatherThanNull %} suggests returning empty collections / arrays
|
||||
instead of null.
|
||||
@ -38,10 +47,20 @@ This release ships with 1 new Java rule.
|
||||
|
||||
#### Deprecated rules
|
||||
|
||||
The following Java rules are deprecated and removed from the quickstart ruleset,
|
||||
as the new rule {% rule java/bestpractices/SimplifiableTestAssertion %} merges
|
||||
their functionality:
|
||||
* {% rule java/bestpractices/UseAssertEqualsInsteadOfAssertTrue %}
|
||||
* {% rule java/bestpractices/UseAssertNullInsteadOfAssertTrue %}
|
||||
* {% rule java/bestpractices/UseAssertSameInsteadOfAssertTrue %}
|
||||
* {% rule java/bestpractices/UseAssertTrueInsteadOfAssertEquals %}
|
||||
* {% rule java/design/SimplifyBooleanAssertion %}
|
||||
|
||||
The rule {% rule java/errorprone/ReturnEmptyArrayRatherThanNull %} is deprecated and removed from
|
||||
the quickstart ruleset, as the new rule {% rule java/errorprone/ReturnEmptyCollectionRatherThanNull %}
|
||||
supersedes it.
|
||||
|
||||
|
||||
### Fixed Issues
|
||||
|
||||
* apex
|
||||
@ -51,6 +70,8 @@ supersedes it.
|
||||
* [#1603](https://github.com/pmd/pmd/issues/1603): \[core] Language version comparison
|
||||
* [#3377](https://github.com/pmd/pmd/issues/3377): \[core] NPE when specifying report file in current directory in PMD CLI
|
||||
* [#3387](https://github.com/pmd/pmd/issues/3387): \[core] CPD should avoid unnecessary copies when running with --skip-lexical-errors
|
||||
* java-bestpractices
|
||||
* [#2908](https://github.com/pmd/pmd/issues/2908): \[java] Merge Junit assertion simplification rules
|
||||
* java-errorprone
|
||||
* [#3361](https://github.com/pmd/pmd/issues/3361): \[java] Rename rule MissingBreakInSwitch to ImplicitSwitchFallThrough
|
||||
* [#3382](https://github.com/pmd/pmd/pull/3382): \[java] New rule ReturnEmptyCollectionRatherThanNull
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1364,6 +1364,50 @@ public class Foo {
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="SimplifiableTestAssertion"
|
||||
language="java"
|
||||
since="6.37.0"
|
||||
message="Assertion may be simplified using {0}"
|
||||
typeResolution="true"
|
||||
class="net.sourceforge.pmd.lang.java.rule.bestpractices.SimplifiableTestAssertionRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#simplifiabletestassertion">
|
||||
<description>
|
||||
Reports test assertions that may be simplified using a more specific
|
||||
assertion method. This enables better error messages, and makes the
|
||||
assertions more readable.
|
||||
|
||||
The rule only applies within test classes for the moment. It replaces
|
||||
the deprecated rules {% rule UseAssertEqualsInsteadOfAssertTrue %},
|
||||
{% rule UseAssertNullInsteadOfAssertTrue %}, {% rule UseAssertSameInsteadOfAssertTrue %},
|
||||
{% rule UseAssertTrueInsteadOfAssertEquals %}, and {% rule java/design/SimplifyBooleanAssertion %}.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
class SomeTestClass {
|
||||
Object a,b;
|
||||
@Test
|
||||
void testMethod() {
|
||||
assertTrue(a.equals(b)); // could be assertEquals(a, b);
|
||||
assertTrue(!a.equals(b)); // could be assertNotEquals(a, b);
|
||||
|
||||
assertTrue(!something); // could be assertFalse(something);
|
||||
assertFalse(!something); // could be assertTrue(something);
|
||||
|
||||
assertTrue(a == b); // could be assertSame(a, b);
|
||||
assertTrue(a != b); // could be assertNotSame(a, b);
|
||||
|
||||
assertTrue(a == null); // could be assertNull(a);
|
||||
assertTrue(a != null); // could be assertNotNull(a);
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="SwitchStmtsShouldHaveDefault"
|
||||
language="java"
|
||||
since="1.0"
|
||||
@ -1690,9 +1734,12 @@ public class Something {
|
||||
message="Use assertEquals(x, y) instead of assertTrue(x.equals(y))"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
typeResolution="true"
|
||||
deprecated="true"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#useassertequalsinsteadofasserttrue">
|
||||
<description>
|
||||
This rule detects JUnit assertions in object equality. These assertions should be made by more specific methods, like assertEquals.
|
||||
|
||||
Deprecated since PMD 6.37.0, use {% rule SimplifiableTestAssertion %} instead.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
@ -1740,10 +1787,13 @@ public class FooTest extends TestCase {
|
||||
message="Use assertNull(x) instead of assertTrue(x==null), or assertNotNull(x) vs assertFalse(x==null)"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
typeResolution="true"
|
||||
deprecated="true"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#useassertnullinsteadofasserttrue">
|
||||
<description>
|
||||
This rule detects JUnit assertions in object references equality. These assertions should be made by
|
||||
more specific methods, like assertNull, assertNotNull.
|
||||
|
||||
Deprecated since PMD 6.37.0, use {% rule SimplifiableTestAssertion %} instead.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
@ -1794,10 +1844,13 @@ public class FooTest extends TestCase {
|
||||
message="Use assertSame(x, y) instead of assertTrue(x==y), or assertNotSame(x,y) vs assertFalse(x==y)"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
typeResolution="true"
|
||||
deprecated="true"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#useassertsameinsteadofasserttrue">
|
||||
<description>
|
||||
This rule detects JUnit assertions in object references equality. These assertions should be made
|
||||
by more specific methods, like assertSame, assertNotSame.
|
||||
|
||||
Deprecated since PMD 6.37.0, use {% rule SimplifiableTestAssertion %} instead.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
@ -1845,9 +1898,12 @@ public class FooTest extends TestCase {
|
||||
since="5.0"
|
||||
message="Use assertTrue(x)/assertFalse(x) instead of assertEquals(true, x)/assertEquals(false, x) or assertEquals(Boolean.TRUE, x)/assertEquals(Boolean.FALSE, x)."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
deprecated="true"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#useasserttrueinsteadofassertequals">
|
||||
<description>
|
||||
When asserting a value is the same as a literal or Boxed boolean, use assertTrue/assertFalse, instead of assertEquals.
|
||||
|
||||
Deprecated since PMD 6.37.0, use {% rule SimplifiableTestAssertion %} instead.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
|
@ -1327,6 +1327,7 @@ public class Foo {
|
||||
message="assertTrue(!expr) can be replaced by assertFalse(expr)"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
typeResolution="true"
|
||||
deprecated="true"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#simplifybooleanassertion">
|
||||
<description>
|
||||
Avoid negation in an assertTrue or assertFalse test.
|
||||
@ -1339,6 +1340,7 @@ as:
|
||||
|
||||
assertFalse(expr);
|
||||
|
||||
Deprecated since PMD 6.37.0, use {% rule java/bestpractices/SimplifiableTestAssertion %} instead.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
|
@ -41,6 +41,7 @@
|
||||
<!-- <rule ref="category/java/bestpractices.xml/ReplaceEnumerationWithIterator" /> -->
|
||||
<!-- <rule ref="category/java/bestpractices.xml/ReplaceHashtableWithMap" /> -->
|
||||
<!-- <rule ref="category/java/bestpractices.xml/ReplaceVectorWithList" /> -->
|
||||
<rule ref="category/java/bestpractices.xml/SimplifiableTestAssertion"/>
|
||||
<rule ref="category/java/bestpractices.xml/SwitchStmtsShouldHaveDefault"/>
|
||||
<!-- <rule ref="category/java/bestpractices.xml/SystemPrintln" /> -->
|
||||
<!-- <rule ref="category/java/bestpractices.xml/UnusedAssignment"/> -->
|
||||
@ -48,10 +49,6 @@
|
||||
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable"/>
|
||||
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
|
||||
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/>
|
||||
<rule ref="category/java/bestpractices.xml/UseAssertEqualsInsteadOfAssertTrue"/>
|
||||
<rule ref="category/java/bestpractices.xml/UseAssertNullInsteadOfAssertTrue"/>
|
||||
<rule ref="category/java/bestpractices.xml/UseAssertSameInsteadOfAssertTrue"/>
|
||||
<rule ref="category/java/bestpractices.xml/UseAssertTrueInsteadOfAssertEquals"/>
|
||||
<rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty"/>
|
||||
<rule ref="category/java/bestpractices.xml/UseStandardCharsets" />
|
||||
<!-- <rule ref="category/java/bestpractices.xml/UseTryWithResources" /> -->
|
||||
@ -155,7 +152,6 @@
|
||||
<!-- <rule ref="category/java/design.xml/NPathComplexity" /> -->
|
||||
<!-- <rule ref="category/java/design.xml/SignatureDeclareThrowsException" /> -->
|
||||
<rule ref="category/java/design.xml/SimplifiedTernary"/>
|
||||
<!-- <rule ref="category/java/design.xml/SimplifyBooleanAssertion" /> -->
|
||||
<!-- <rule ref="category/java/design.xml/SimplifyBooleanExpressions" /> -->
|
||||
<rule ref="category/java/design.xml/SimplifyBooleanReturns"/>
|
||||
<rule ref="category/java/design.xml/SimplifyConditional"/>
|
||||
|
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.java.rule.bestpractices;
|
||||
|
||||
import net.sourceforge.pmd.testframework.PmdRuleTst;
|
||||
|
||||
public class SimplifiableTestAssertionTest extends PmdRuleTst {
|
||||
// no additional unit tests
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
|
||||
|
||||
<test-code>
|
||||
<description>TEST1</description>
|
||||
<description>use assert equals</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import junit.framework.TestCase;
|
||||
|
Reference in New Issue
Block a user