From df6f1afa46355ba21706fe75ecf0a892aa0d60b7 Mon Sep 17 00:00:00 2001 From: Damian Techeira Date: Fri, 24 Jul 2015 12:03:07 -0300 Subject: [PATCH] Add check to Boxed booleans in UseAssertTrueInsteadOfAssertEquals rule Test Plan: mvn test Reviewers: jmsotuyo Reviewed By: jmsotuyo Differential Revision: http://ph.monits.com/D11963 --- .../main/resources/rulesets/java/junit.xml | 17 ++++++-- .../UseAssertTrueInsteadOfAssertEquals.xml | 42 +++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/pmd-java/src/main/resources/rulesets/java/junit.xml b/pmd-java/src/main/resources/rulesets/java/junit.xml index 4b32204938..11d85d1779 100644 --- a/pmd-java/src/main/resources/rulesets/java/junit.xml +++ b/pmd-java/src/main/resources/rulesets/java/junit.xml @@ -403,18 +403,25 @@ public class MyTestCase extends TestCase { -When asserting a value is the same as a boolean literal, use assertTrue/assertFalse, instead of assertEquals. +When asserting a value is the same as a literal or Boxed boolean, use assertTrue/assertFalse, instead of assertEquals. 3 @@ -430,6 +437,10 @@ public class MyTestCase extends TestCase { assertEquals("myVar is true", true, myVar); // Bad assertEquals("myVar is false", false, myVar); + // Bad + assertEquals("myVar is true", Boolean.TRUE, myVar); + // Bad + assertEquals("myVar is false", Boolean.FALSE, myVar); } } ]]> diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/junit/xml/UseAssertTrueInsteadOfAssertEquals.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/junit/xml/UseAssertTrueInsteadOfAssertEquals.xml index f162876a4f..fe15fbd905 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/junit/xml/UseAssertTrueInsteadOfAssertEquals.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/junit/xml/UseAssertTrueInsteadOfAssertEquals.xml @@ -51,4 +51,46 @@ public class TestWithAssertEquals { } ]]> + + + + + 8 + + + + + + + 0 + + \ No newline at end of file