From 41e921531a4a19fc8ac0a79b15fbd13c509bbba1 Mon Sep 17 00:00:00 2001 From: Robert Whitebit Date: Wed, 18 Feb 2015 20:30:16 +0100 Subject: [PATCH] Add missing assertions in JUnitAssertionsShouldIncludeMessage test Missing assertions were assertArrayEquals, assertNotSame, assertThat and fail. --- ...nitAssertionsShouldIncludeMessageRule.java | 10 +- .../JUnitAssertionsShouldIncludeMessage.xml | 190 ++++++++++++++---- 2 files changed, 158 insertions(+), 42 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/junit/JUnitAssertionsShouldIncludeMessageRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/junit/JUnitAssertionsShouldIncludeMessageRule.java index b215c35bd2..7a4bd3b7ad 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/junit/JUnitAssertionsShouldIncludeMessageRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/junit/JUnitAssertionsShouldIncludeMessageRule.java @@ -26,12 +26,16 @@ public class JUnitAssertionsShouldIncludeMessageRule extends AbstractJUnitRule { private List checks = new ArrayList(); public JUnitAssertionsShouldIncludeMessageRule() { + checks.add(new AssertionCall(2, "assertArrayEquals")); checks.add(new AssertionCall(2, "assertEquals")); - checks.add(new AssertionCall(1, "assertTrue")); + checks.add(new AssertionCall(1, "assertFalse")); + checks.add(new AssertionCall(1, "assertNotNull")); + checks.add(new AssertionCall(2, "assertNotSame")); checks.add(new AssertionCall(1, "assertNull")); checks.add(new AssertionCall(2, "assertSame")); - checks.add(new AssertionCall(1, "assertNotNull")); - checks.add(new AssertionCall(1, "assertFalse")); + checks.add(new AssertionCall(2, "assertThat")); + checks.add(new AssertionCall(1, "assertTrue")); + checks.add(new AssertionCall(0, "fail")); } public Object visit(ASTArguments node, Object data) { diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/junit/xml/JUnitAssertionsShouldIncludeMessage.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/junit/xml/JUnitAssertionsShouldIncludeMessage.xml index 840166469a..4ecb5f9254 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/junit/xml/JUnitAssertionsShouldIncludeMessage.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/junit/xml/JUnitAssertionsShouldIncludeMessage.xml @@ -2,6 +2,34 @@ + 0 + + + + + 1 + + + + 0 @@ -9,7 +37,7 @@ assertEquals ok import junit.framework.TestCase; public class Foo extends TestCase { public void test1() { - assertEquals("1 == 1", 1, 1); + assertEquals("1 != 1", 1, 1); } } ]]> @@ -30,28 +58,84 @@ public class Foo extends TestCase { 0 + 1 + + + + + 0 + + + + 1 + + + + 0 + + + + + 1 + @@ -100,7 +184,7 @@ public class Foo extends TestCase { 1 0 1 + + + + 0 + + + + + 1 + + + + + 0 + + + + + 1 + @@ -156,34 +296,6 @@ public class Foo extends TestCase { - 0 - - - - - 1 - - - - 0