This is an automated email from the ASF dual-hosted git repository.

adangel pushed a commit to branch pmd7
in repository https://gitbox.apache.org/repos/asf/maven-pmd-plugin.git

commit 50576f9e765ade626c00f6f160cfc71d0ddad77e
Author: Andreas Dangel <adan...@apache.org>
AuthorDate: Fri May 19 16:47:21 2023 +0200

    Clarify unit tests
---
 .../apache/maven/plugins/pmd/CpdReportTest.java    |  8 ++--
 .../apache/maven/plugins/pmd/PmdReportTest.java    | 18 +++----
 .../def/configuration/App.java                     | 56 ++++++++--------------
 .../def/configuration/App2.java                    | 11 ++---
 .../def/configuration/AppSample.java               | 42 ++++++----------
 5 files changed, 53 insertions(+), 82 deletions(-)

diff --git a/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java 
b/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java
index 55748a5..9b5f8e1 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java
@@ -64,8 +64,8 @@ public class CpdReportTest extends AbstractPmdReportTestCase {
         String str = readFile(generatedReport);
         assertTrue(lowerCaseContains(str, "AppSample.java"));
         assertTrue(lowerCaseContains(str, "App.java"));
-        assertTrue(lowerCaseContains(str, "public String dup( String str )"));
-        assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring( i, i + 
1);"));
+        assertTrue(lowerCaseContains(str, "public String dup(String str)"));
+        assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring(i, i + 
1);"));
 
         // the version should be logged
         String output = CapturingPrintStream.getOutput();
@@ -171,8 +171,8 @@ public class CpdReportTest extends 
AbstractPmdReportTestCase {
         String str = readFile(generatedFile);
         assertTrue(lowerCaseContains(str, "AppSample.java"));
         assertTrue(lowerCaseContains(str, "App.java"));
-        assertTrue(lowerCaseContains(str, "public String dup( String str )"));
-        assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring( i, i + 
1);"));
+        assertTrue(lowerCaseContains(str, "public String dup(String str)"));
+        assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring(i, i + 
1);"));
     }
 
     /**
diff --git a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java 
b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
index aa897f6..0d344ab 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
@@ -73,9 +73,10 @@ public class PmdReportTest extends AbstractPmdReportTestCase 
{
         // check if there's a link to the JXR files
         String str = readFile(generatedReport);
 
-        assertTrue(str.contains("/xref/def/configuration/App.html#L31"));
-
-        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L45"));
+        // PMD: UnusedPrivateField (Prio 3)
+        assertTrue(str.contains("/xref/def/configuration/App.html#L29"));
+        // PMD: UnusedFormalParameter (Prio 3) and UnusedPrivateMethod (Prio 3)
+        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L42"));
 
         // check if there's a priority column
         assertTrue(str.contains("<th>Priority</th>"));
@@ -251,9 +252,10 @@ public class PmdReportTest extends 
AbstractPmdReportTestCase {
         // check if there's a link to the JXR files
         String str = readFile(generatedReport);
 
-        assertTrue(str.contains("/xref/def/configuration/App.html#L31"));
-
-        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L45"));
+        // PMD: UnusedPrivateField (Prio 3)
+        assertTrue(str.contains("/xref/def/configuration/App.html#L29"));
+        // PMD: UnusedFormalParameter (Prio 3) and UnusedPrivateMethod (Prio 3)
+        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L42"));
 
         mockServer.stop();
     }
@@ -452,7 +454,7 @@ public class PmdReportTest extends 
AbstractPmdReportTestCase {
         // check if there's a link to the JXR files
         str = readFile(generatedReport);
 
-        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L27"));
+        
assertTrue(str.contains("/xref/def/configuration/AppSample.html#L25")); // PMD: 
UnusedPrivateField (Prio 3)
         // suppressed violation
         assertTrue(str.contains("Avoid unused private fields such as 
'unusedVar2'."));
     }
@@ -477,7 +479,7 @@ public class PmdReportTest extends 
AbstractPmdReportTestCase {
         // check if there's a link to the JXR files
         str = readFile(generatedReport);
 
-        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L27"));
+        
assertTrue(str.contains("/xref/def/configuration/AppSample.html#L25")); // PMD: 
UnusedPrivateField (Prio 3)
         // suppressed violations are not rendered
         assertFalse(str.contains("Avoid unused private fields such as 
'unusedVar2'."));
     }
diff --git 
a/src/test/resources/unit/default-configuration/def/configuration/App.java 
b/src/test/resources/unit/default-configuration/def/configuration/App.java
index da53df0..3441a0c 100644
--- a/src/test/resources/unit/default-configuration/def/configuration/App.java
+++ b/src/test/resources/unit/default-configuration/def/configuration/App.java
@@ -1,5 +1,3 @@
-package def.configuration;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,17 +16,17 @@ package def.configuration;
  * specific language governing permissions and limitations
  * under the License.
  */
+package def.configuration;
 
 /**
  * This is a sample class used for testing
  *
  * @author Maria Odea Ching
  */
-public class App
-{
+public class App  {
     protected String unusedVar1;
 
-    private int unusedVar2; //SUPPRESSME test for the suppressMarker property
+    private int unusedVar2; //SUPPRESSME test for the suppressMarker property 
- PMD: UnusedPrivateField (Prio 3)
 
     String unusedvar3;
 
@@ -37,9 +35,8 @@ public class App
      *
      * @param args  an array of strings that contains the arguments
      */
-    public static void main( String[] args )
-    {
-        System.out.println( "Sample Application." );
+    public static void main(String[] args) {
+        System.out.println("Sample Application.");
     }
 
     /**
@@ -47,15 +44,10 @@ public class App
      *
      * @param str   the value to be displayed
      */
-    protected void sampleMethod( String str )
-    {
-        try
-        {
-            System.out.println( str );
-        }
-        catch ( Exception e )
-        {
-
+    protected void sampleMethod(String str) {
+        try {
+            System.out.println(str);
+        } catch ( Exception e ) { // PMD: EmptyCatchBlock (Prio 3)
         }
     }
 
@@ -65,35 +57,27 @@ public class App
      * @param unusedParam1
      * @param unusedParam2
      */
-    public void testMethod( String unusedParam1, String unusedParam2)
-    {
+    public void testMethod(String unusedParam1, String unusedParam2) {
         System.out.println( "Test method" );
     }
 
 
-    public String dup( String str )
-    {
+    public String dup(String str) {
         String tmp = "";
 
-        for( int i = 0; i < str.length(); i++ )
-        {
-            if ( i != ( str.length() -1 ) )
-            {
-                tmp = tmp + str.substring( i, i + 1);
-            }
-            else
-            {
-                tmp = tmp + str.substring( i );
+        for (int i = 0; i < str.length(); i++) {
+            if (i != ((str.length() - 1))) { // PMD: UselessParentheses (Prio 
4)
+                tmp = tmp + str.substring(i, i + 1);
+            } else {
+                tmp = tmp + str.substring(i);
             }
         }
 
-        if ("".equals( tmp ))
-        {
-                tmp = "EMPTY";
+        if ("".equals(tmp)) {
+            tmp = "EMPTY";
         }
 
-        System.out.println( "The value of tmp is " + tmp );
+        System.out.println("The value of tmp is " + tmp);
         return tmp;
     }
-
-}
\ No newline at end of file
+}
diff --git 
a/src/test/resources/unit/default-configuration/def/configuration/App2.java 
b/src/test/resources/unit/default-configuration/def/configuration/App2.java
index 6054a2e..49b38fc 100644
--- a/src/test/resources/unit/default-configuration/def/configuration/App2.java
+++ b/src/test/resources/unit/default-configuration/def/configuration/App2.java
@@ -1,4 +1,3 @@
-package def.configuration;
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -17,16 +16,14 @@ package def.configuration;
  * specific language governing permissions and limitations
  * under the License.
  */
+package def.configuration;
+
+import java.io.File; // PMD: UnnecessaryImport (Prio 4)
 
-//trigger unused import
-import java.io.File;
 /**
  * This is a sample class used for testing
  *
  * @author Maria Odea Ching
  */
-public class App2
-{
-
-  
+public class App2 {
 }
diff --git 
a/src/test/resources/unit/default-configuration/def/configuration/AppSample.java
 
b/src/test/resources/unit/default-configuration/def/configuration/AppSample.java
index 201bf19..c4b8316 100644
--- 
a/src/test/resources/unit/default-configuration/def/configuration/AppSample.java
+++ 
b/src/test/resources/unit/default-configuration/def/configuration/AppSample.java
@@ -1,5 +1,3 @@
-package def.configuration;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,21 +16,20 @@ package def.configuration;
  * specific language governing permissions and limitations
  * under the License.
  */
+package def.configuration;
 
 /**
  * @author Maria Odea Ching
  */
-public class AppSample
-{
-    private String unusedVar = "UNUSED";
+public class AppSample {
+    private String unusedVar = "UNUSED"; // PMD: UnusedPrivateField (Prio 3)
 
     /**
      * The main method
      *
      * @param args  an array of strings that contains the arguments
      */
-    public static void main( String[] args )
-    {
+    public static void main(String[] args) {
         System.out.println( "Another Sample Application" );
     }
 
@@ -42,36 +39,27 @@ public class AppSample
      * @param notUsedParam
      * @return a blank String
      */
-    private String unusedMethod( String notUsedParam )
-    {
-        System.out.println( "This is just a test." );
-
+    private String unusedMethod(String notUsedParam) { // PMD: 
UnusedFormalParameter (Prio 3) and UnusedPrivateMethod (Prio 3)
+        System.out.println("This is just a test.");
         return "";
     }
 
-    public String dup( String str )
-    {
+    public String dup(String str) {
         String tmp = "";
 
-        for( int i = 0; i < str.length(); i++ )
-        {
-            if ( i != ( str.length() -1 ) )
-            {
-                tmp = tmp + str.substring( i, i + 1);
-            }
-            else
-            {
-                tmp = tmp + str.substring( i );
+        for (int i = 0; i < str.length(); i++) {
+            if (i != ((str.length() - 1))) { // PMD: UselessParentheses (Prio 
4)
+                tmp = tmp + str.substring(i, i + 1);
+            } else {
+                tmp = tmp + str.substring(i);
             }
         }
 
-        if ("".equals( tmp ))
-        {
+        if ("".equals(tmp)) {
                 tmp = "EMPTY";
         }
 
-        System.out.println( "The value of tmp is " + tmp );
+        System.out.println("The value of tmp is " + tmp);
         return tmp;
     }
-
-}
\ No newline at end of file
+}

Reply via email to