diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/DefaultAnalyserFactoryTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/DefaultAnalyserFactoryTest.java index b576868f1..bcab20c93 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/DefaultAnalyserFactoryTest.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/DefaultAnalyserFactoryTest.java @@ -18,6 +18,7 @@ */ package org.apache.rat.analysis; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -81,7 +82,7 @@ public void standardTypeAnalyser() throws Exception { reporter.report(document); String result = out.toString(); for (String exp : expected) { - assertTrue(result.contains(exp), () -> exp); + assertThat(result).contains(exp); } } @@ -91,7 +92,7 @@ public void noteTypeAnalyser() throws Exception { Resources.getResourceFile("/elements/LICENSE")); analyser.analyse(document); reporter.report(document); - assertEquals("", out.toString()); + assertThat(out.toString()).isEqualTo(""); } @Test @@ -100,7 +101,7 @@ public void binaryTypeAnalyser() throws Exception { Resources.getResourceFile("/elements/Image.png")); analyser.analyse(document); reporter.report(document); - assertEquals("", out.toString()); + assertThat(out.toString()).isEqualTo(""); } @Test @@ -114,7 +115,7 @@ public void archiveTypeAnalyserTest() throws Exception { analyser = DefaultAnalyserFactory.createDefaultAnalyser(config); analyser.analyse(document); reporter.report(document); - assertEquals("", out.toString()); + assertThat(out.toString()).isEqualTo(""); } @Test @@ -130,9 +131,9 @@ public void archivesAbsenceTest() throws Exception { analyser.analyse(document); reporter.report(document); String result = out.toString(); - TextUtils.assertContains("", out.toString()); - TextUtils.assertContains("", out.toString()); - TextUtils.assertContains("", out.toString()); + TextUtils.assertContains("", result); + TextUtils.assertContains("", result); + TextUtils.assertContains("", result); } @Test @@ -148,9 +149,9 @@ public void archivesPresenceTest() throws Exception { analyser.analyse(document); reporter.report(document); String result = out.toString(); - TextUtils.assertContains("", out.toString()); - TextUtils.assertNotContains("", out.toString()); - TextUtils.assertContains("", out.toString()); + TextUtils.assertContains("", result); + TextUtils.assertNotContains("", result); + TextUtils.assertContains("", result); } @Test @@ -159,7 +160,7 @@ public void archiveTypeAnalyser() throws Exception { Resources.getResourceFile("/elements/dummy.jar")); analyser.analyse(document); reporter.report(document); - assertEquals("", out.toString()); + assertThat(out.toString()).isEqualTo(""); } @Test @@ -168,7 +169,7 @@ public void RAT211_bmp_Test() throws Exception { Resources.getResourceFile("/jira/RAT211/side_left.bmp")); analyser.analyse(document); reporter.report(document); - assertEquals("", out.toString()); + assertThat(out.toString()).isEqualTo(""); } @Test diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/license/AbstractLicenseTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/license/AbstractLicenseTest.java index 80f94d109..c88d3be56 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/license/AbstractLicenseTest.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/license/AbstractLicenseTest.java @@ -18,8 +18,7 @@ */ package org.apache.rat.analysis.license; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.fail; import java.io.BufferedReader; @@ -34,7 +33,6 @@ import org.apache.rat.license.ILicense; import org.apache.rat.license.LicenseSetFactory; import org.apache.rat.license.LicenseSetFactory.LicenseFilter; -import org.apache.rat.testhelpers.TestingLicense; import org.apache.rat.utils.DefaultLog; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; @@ -42,7 +40,6 @@ /** * Test to see if short form license information will be recognized correctly. - * */ abstract public class AbstractLicenseTest { private static int NAME = 0; @@ -77,8 +74,8 @@ public void testMatchProcessing(String id, String familyPattern, String name, St for (String[] target : targets) { if (processText(license, target[TEXT])) { data.reportOnLicense(license); - assertEquals(1, data.licenses().count()); - assertEquals(license, data.licenses().findFirst().get()); + assertThat(data.licenses()).hasSize(1); + assertThat(data.licenses().findFirst()).isPresent().hasValue(license); } else { fail(license + " was not matched by " + target[NAME]); } @@ -110,8 +107,7 @@ public void testEmbeddedStrings(String id, String family, String name, String no for (String fmt : formats) { boolean found = processText(license, String.format(fmt, target[TEXT])); license.reset(); - assertTrue(found, () -> String.format("%s %s did not match pattern '%s' for target string %s", id, - name, fmt, target[NAME])); + assertThat(found).isTrue(); } } } finally { diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/license/ApacheSoftwareLicenseTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/license/ApacheSoftwareLicenseTest.java index ef7692ad8..971ffb2a8 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/license/ApacheSoftwareLicenseTest.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/license/ApacheSoftwareLicenseTest.java @@ -24,7 +24,6 @@ /** * Apache Software License detection tests. - * */ public class ApacheSoftwareLicenseTest extends AbstractLicenseTest { diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/license/DirectoryScanner.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/license/DirectoryScanner.java index 887169b77..bb5e76f0c 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/license/DirectoryScanner.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/license/DirectoryScanner.java @@ -38,11 +38,11 @@ class DirectoryScanner { * * @param directory the directory containing the files * @param matcher the license matcher - * @param expected the expected result of the each scan + * @param expected the expected result of each scan * @throws Exception */ @Test - public static void testFilesInDir(String directory, ILicense license, boolean expected) throws Exception { + public static void runTestsOnFilesInDir(String directory, ILicense license, boolean expected) throws Exception { final File[] resourceFiles = Resources.getResourceFiles(directory); if (resourceFiles.length == 0) { fail("No files found under " + directory); diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/license/GeneratedLicenseTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/license/GeneratedLicenseTest.java index 431db58d1..df0a7547e 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/license/GeneratedLicenseTest.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/license/GeneratedLicenseTest.java @@ -25,7 +25,7 @@ public class GeneratedLicenseTest extends AbstractLicenseTest { private static String id = "GEN"; private static String name = "Generated Files"; - private static String notes = "Files that are autmoatically generated."; + private static String notes = "Files that are automatically generated."; private static String[][] targets = { { "Cayenne", "generated by Cayenne" }, { "JJTree", "Generated By:JJTree" }, { "JavaCC", "Generated By:JavaCC" }, { "AUTOMATIC", "THIS FILE IS AUTOMATICALLY GENERATED" }, { "XBeans", "NOTE: this file is autogenerated by XBeans" }, diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/license/OASISLicenseTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/license/OASISLicenseTest.java index a439827c2..4a7c96d18 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/license/OASISLicenseTest.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/license/OASISLicenseTest.java @@ -20,6 +20,8 @@ import java.util.stream.Stream; +import org.apache.rat.license.ILicense; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.provider.Arguments; public class OASISLicenseTest extends AbstractLicenseTest { @@ -36,15 +38,17 @@ public class OASISLicenseTest extends AbstractLicenseTest { public static Stream parameterProvider() { return Stream.of(Arguments.of(id, id, name, notes, targets)); } - /* - @Test(timeout = 2000) // may need to be adjusted if many more files are added + + /* TODO + private static ILicense license = ILicense.builder().setId(id).build(); + @Test // may need to be adjusted if many more files are added public void goodFiles() throws Exception { - DirectoryScanner.testFilesInDir("oasis/good", license, true); + DirectoryScanner.runTestsOnFilesInDir("oasis/good", license, true); } - @Test(timeout = 2000) // may need to be adjusted if many more files are added - public void baddFiles() throws Exception { - DirectoryScanner.testFilesInDir("oasis/bad", license, false); + @Test // may need to be adjusted if many more files are added + public void badFiles() throws Exception { + DirectoryScanner.runTestsOnFilesInDir("oasis/bad", license, false); } */ } diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/AbstractMatcherTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/AbstractMatcherTest.java index 3b38d0502..e2f352340 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/AbstractMatcherTest.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/AbstractMatcherTest.java @@ -18,6 +18,7 @@ */ package org.apache.rat.analysis.matchers; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Locale; diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/FullTextMatcherTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/FullTextMatcherTest.java index dbdccda58..f5b75af56 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/FullTextMatcherTest.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/FullTextMatcherTest.java @@ -18,8 +18,7 @@ */ package org.apache.rat.analysis.matchers; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,8 +34,8 @@ public void setup() { @Test public void testMatch() { - assertFalse(target.matches(AbstractMatcherTest.makeHeaders(null, "what in the world"))); - assertTrue(target.matches(AbstractMatcherTest.makeHeaders(null, "hello world"))); - assertTrue(target.matches(AbstractMatcherTest.makeHeaders(null, "HELLO world"))); + assertThat(target.matches(AbstractMatcherTest.makeHeaders(null, "what in the world"))).isFalse(); + assertThat(target.matches(AbstractMatcherTest.makeHeaders(null, "hello world"))).isTrue(); + assertThat(target.matches(AbstractMatcherTest.makeHeaders(null, "HELLO world"))).isTrue(); } } diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SPDXMatcherTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SPDXMatcherTest.java index 66facc904..81adb67c1 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SPDXMatcherTest.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SPDXMatcherTest.java @@ -18,8 +18,7 @@ */ package org.apache.rat.analysis.matchers; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.apache.rat.analysis.IHeaderMatcher; import org.apache.rat.analysis.IHeaders; @@ -45,9 +44,9 @@ public void testMatch() { IHeaders headers = AbstractMatcherTest.makeHeaders(sb.toString(),null); - assertTrue(target1.matches(headers)); - assertTrue(target2.matches(headers)); - assertFalse(target3.matches(headers)); + assertThat(target1.matches(headers)).isTrue(); + assertThat(target2.matches(headers)).isTrue(); + assertThat(target3.matches(headers)).isFalse(); target1.reset(); } } diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SimpleCopyrightTests.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SimpleCopyrightTests.java index 6a12f9a0a..c28f1b13a 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SimpleCopyrightTests.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SimpleCopyrightTests.java @@ -18,8 +18,7 @@ */ package org.apache.rat.analysis.matchers; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.Test; @@ -29,8 +28,8 @@ public class SimpleCopyrightTests { @Test public void testTrueIsAlwaysTrue() { - assertTrue(target.matches(AbstractMatcherTest.makeHeaders("hello Copyright 1999", null))); - assertFalse(target.matches(AbstractMatcherTest.makeHeaders("A non matching line", null))); + assertThat(target.matches(AbstractMatcherTest.makeHeaders("hello Copyright 1999", null))).isTrue(); + assertThat(target.matches(AbstractMatcherTest.makeHeaders("A non matching line", null))).isFalse(); target.reset(); } } diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SimpleRegexMatcherTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SimpleRegexMatcherTest.java index e4d2c5b68..87819d431 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SimpleRegexMatcherTest.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SimpleRegexMatcherTest.java @@ -18,7 +18,7 @@ */ package org.apache.rat.analysis.matchers; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.util.regex.Pattern; @@ -36,8 +36,8 @@ public void setup() { @Test public void test() { - assertEquals(false, target.matches(AbstractMatcherTest.makeHeaders("what in the world", null))); - assertEquals(true, target.matches(AbstractMatcherTest.makeHeaders("hello world", null))); + assertThat(target.matches(AbstractMatcherTest.makeHeaders("what in the world", null))).isFalse(); + assertThat(target.matches(AbstractMatcherTest.makeHeaders("hello world", null))).isTrue(); target.reset(); } } diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SimpleTextMatcherTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SimpleTextMatcherTest.java index 610a0746f..63b7138d6 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SimpleTextMatcherTest.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SimpleTextMatcherTest.java @@ -18,8 +18,7 @@ */ package org.apache.rat.analysis.matchers; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,8 +34,8 @@ public void setup() { @Test public void testMatch() { - assertFalse(target.matches(AbstractMatcherTest.makeHeaders("what in the world", null))); - assertTrue(target.matches(AbstractMatcherTest.makeHeaders("hello world", null))); + assertThat(target.matches(AbstractMatcherTest.makeHeaders("what in the world", null))).isFalse(); + assertThat(target.matches(AbstractMatcherTest.makeHeaders("hello world", null))).isTrue(); target.reset(); }