You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@creadur.apache.org by po...@apache.org on 2019/05/30 19:04:39 UTC

[creadur-rat] branch trunk updated: RAT-244: Replace old style JUnit tests with JUnit4

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

pottlinger pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/creadur-rat.git


The following commit(s) were added to refs/heads/trunk by this push:
     new cc335fd  RAT-244: Replace old style JUnit tests with JUnit4
cc335fd is described below

commit cc335fd9d5d90f1c4bb77d19f123d9e537b1f518
Author: Hugo Hirsch <gi...@hugo-hirsch.de>
AuthorDate: Thu May 30 21:04:33 2019 +0200

    RAT-244: Replace old style JUnit tests with JUnit4
---
 .../license/SimplePatternBasedLicense.java         |  2 +-
 .../rat/analysis/util/MatcherMultiplexerTest.java  | 28 ++++++++++------------
 .../impl/util/DocumentAnalyserMultiplexerTest.java | 18 +++++++-------
 .../main/java/org/apache/rat/mp/RatReportMojo.java |  2 +-
 .../java/org/apache/rat/anttasks/ReportTest.java   |  1 -
 5 files changed, 23 insertions(+), 28 deletions(-)

diff --git a/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java b/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java
index c3ec20a..6844d7a 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java
@@ -52,7 +52,7 @@ public class SimplePatternBasedLicense extends BaseLicense implements IHeaderMat
             final String[] pttrns = getPatterns();
             if (pttrns != null) {
                 for (String pttrn : pttrns) {
-                    if (pLine.indexOf(pttrn) >= 0) {
+                    if (pLine.contains(pttrn)) {
                         return true;
                     }
                 }
diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/util/MatcherMultiplexerTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/util/MatcherMultiplexerTest.java
index 1ed6e69..68d8910 100644
--- a/apache-rat-core/src/test/java/org/apache/rat/analysis/util/MatcherMultiplexerTest.java
+++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/util/MatcherMultiplexerTest.java
@@ -18,41 +18,38 @@
  */ 
 package org.apache.rat.analysis.util;
 
-import junit.framework.TestCase;
-
 import org.apache.rat.analysis.IHeaderMatcher;
 import org.apache.rat.analysis.MockLicenseMatcher;
 import org.apache.rat.api.Document;
 import org.apache.rat.document.MockLocation;
 import org.apache.rat.report.claim.impl.xml.MockClaimReporter;
+import org.junit.Before;
+import org.junit.Test;
 
 import java.util.Arrays;
 
-public class MatcherMultiplexerTest extends TestCase {
+import static org.junit.Assert.assertEquals;
+
+public class MatcherMultiplexerTest {
 
     private static final String LINE_ONE = "Line One";
     private static final String LINE_TWO = "Line Two";
 
-    MockClaimReporter reporter;
-    MockLicenseMatcher matcherOne;
-    MockLicenseMatcher matcherTwo;
+    private MockClaimReporter reporter;
+    private MockLicenseMatcher matcherOne;
+    private MockLicenseMatcher matcherTwo;
 
-    HeaderMatcherMultiplexer multiplexer;
+    private HeaderMatcherMultiplexer multiplexer;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setUp() {
         matcherOne = new MockLicenseMatcher();
         matcherTwo = new MockLicenseMatcher();
         multiplexer = new HeaderMatcherMultiplexer(Arrays.<IHeaderMatcher>asList(matcherOne, matcherTwo));
         reporter = new MockClaimReporter();
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-    }
-
+    @Test
     public void testMatcherLine() throws Exception {
         matcherOne.result = false;
         matcherTwo.result = false;
@@ -69,6 +66,7 @@ public class MatcherMultiplexerTest extends TestCase {
         assertEquals("Same as line passed", LINE_TWO, matcherTwo.lines.get(1));
     }
 
+    @Test
     public void testReset() {
         multiplexer.reset();
         assertEquals("Reset once", 1, matcherOne.resets);
diff --git a/apache-rat-core/src/test/java/org/apache/rat/document/impl/util/DocumentAnalyserMultiplexerTest.java b/apache-rat-core/src/test/java/org/apache/rat/document/impl/util/DocumentAnalyserMultiplexerTest.java
index c03df15..0f0ea1b 100644
--- a/apache-rat-core/src/test/java/org/apache/rat/document/impl/util/DocumentAnalyserMultiplexerTest.java
+++ b/apache-rat-core/src/test/java/org/apache/rat/document/impl/util/DocumentAnalyserMultiplexerTest.java
@@ -21,17 +21,19 @@ package org.apache.rat.document.impl.util;
 import org.apache.rat.document.IDocumentAnalyser;
 import org.apache.rat.document.MockDocument;
 import org.apache.rat.document.MockDocumentAnalyser;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
 
-public class DocumentAnalyserMultiplexerTest extends TestCase {
+import static org.junit.Assert.assertEquals;
+
+public class DocumentAnalyserMultiplexerTest {
 
     private DocumentAnalyserMultiplexer multiplexer;
     private IDocumentAnalyser[] analysers;
     private MockDocument document;
     
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setUp() {
         IDocumentAnalyser[] analysers = {
                 new MockDocumentAnalyser(), 
                 new MockDocumentAnalyser(),
@@ -42,11 +44,7 @@ public class DocumentAnalyserMultiplexerTest extends TestCase {
         multiplexer = new DocumentAnalyserMultiplexer(analysers);
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-    }
-
+    @Test
     public void testAnalyse() throws Exception {
         multiplexer.analyse(document);
         MockDocumentAnalyser analyser =  (MockDocumentAnalyser) (analysers[0]);
diff --git a/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatReportMojo.java b/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatReportMojo.java
index 7a082fb..fbbbfdb 100644
--- a/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatReportMojo.java
+++ b/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatReportMojo.java
@@ -51,7 +51,6 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
 import java.util.ResourceBundle;
@@ -176,6 +175,7 @@ public class RatReportMojo extends AbstractRatMojo implements MavenReport {
      * @return Version number, if found, or null.
      */
     private String getRatVersion() {
+        //noinspection unchecked
         for (Artifact a : (Iterable<Artifact>) getProject().getDependencyArtifacts()) {
             if ("rat-lib".equals(a.getArtifactId())) {
                 return a.getVersion();
diff --git a/apache-rat-tasks/src/test/java/org/apache/rat/anttasks/ReportTest.java b/apache-rat-tasks/src/test/java/org/apache/rat/anttasks/ReportTest.java
index 325d179..0690574 100644
--- a/apache-rat-tasks/src/test/java/org/apache/rat/anttasks/ReportTest.java
+++ b/apache-rat-tasks/src/test/java/org/apache/rat/anttasks/ReportTest.java
@@ -18,7 +18,6 @@ package org.apache.rat.anttasks;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.tools.ant.BuildException;
-import org.junit.Assert;
 
 import java.io.BufferedReader;
 import java.io.File;