From 21b2741a86dc39e3889c139b55191bb7d70f019d Mon Sep 17 00:00:00 2001 From: Vitalij Berdinskih Date: Sun, 17 Nov 2024 12:09:06 +0200 Subject: [PATCH] Move to jUnit5 (#608) * Move to jUnit5 * Drop public classifier from tests --------- Co-authored-by: Slawomir Jaranowski --- pom.xml | 4 +- .../mojo/license/LicenseMojoUtilsTest.java | 38 ++-- .../mojo/license/api/ArtifactFiltersTest.java | 174 +++++++++--------- .../license/api/FreeMarkerHelperTest.java | 15 +- .../download/LicenseDownloaderTest.java | 11 +- .../license/download/LicenseMatchersTest.java | 77 ++++---- .../license/download/LicenseSummaryTest.java | 73 ++++---- .../AbstractFileHeaderTransformerTest.java | 160 ++++++++-------- .../JavaFileHeaderTransformerTest.java | 13 +- .../XmlFileHeaderTransformerTest.java | 27 +-- .../mojo/license/model/LicenseMapTest.java | 8 +- .../license/model/LicenseRepositoryTest.java | 43 +++-- .../mojo/license/model/LicenseStoreTest.java | 63 ++++--- .../license/spdx/SpdxLicenseListDataTest.java | 12 +- .../license/spdx/SpdxLicenseListTest.java | 38 ++-- .../mojo/license/utils/UrlRequesterTest.java | 34 ++-- 16 files changed, 412 insertions(+), 378 deletions(-) diff --git a/pom.xml b/pom.xml index f7e9a10c1..37cbc3b94 100644 --- a/pom.xml +++ b/pom.xml @@ -283,8 +283,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api test diff --git a/src/test/java/org/codehaus/mojo/license/LicenseMojoUtilsTest.java b/src/test/java/org/codehaus/mojo/license/LicenseMojoUtilsTest.java index 59b275c5e..e7efcea29 100644 --- a/src/test/java/org/codehaus/mojo/license/LicenseMojoUtilsTest.java +++ b/src/test/java/org/codehaus/mojo/license/LicenseMojoUtilsTest.java @@ -2,14 +2,14 @@ import java.io.File; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -public class LicenseMojoUtilsTest { +class LicenseMojoUtilsTest { private String resolvedUrl; private File deprecatedFile; private String url; @@ -17,45 +17,45 @@ public class LicenseMojoUtilsTest { private MockLogger log = new MockLogger(); @Test - public void testIsValidNull() { + void testIsValidNull() { assertFalse(LicenseMojoUtils.isValid(null)); } @Test - public void testIsValidEmpty() { + void testIsValidEmpty() { // This might be wrong; feel free to change the test when it starts to fail assertTrue(LicenseMojoUtils.isValid("")); } @Test - public void testIsValidBlank() { + void testIsValidBlank() { // This might be wrong; feel free to change the test when it starts to fail assertTrue(LicenseMojoUtils.isValid(" ")); } @Test - public void testIsValidNonexistingClasspathResource() { + void testIsValidNonexistingClasspathResource() { assertTrue(LicenseMojoUtils.isValid("classpath:noSuchResource")); } @Test - public void testIsValidClasspathResource() { + void testIsValidClasspathResource() { assertTrue(LicenseMojoUtils.isValid("classpath:log4j.properties")); } @Test - public void testIsValidHttpResource() { + void testIsValidHttpResource() { assertTrue(LicenseMojoUtils.isValid("http://foo/bar/baz")); } @Test - public void testPrepareThirdPartyOverrideUrlNull() { + void testPrepareThirdPartyOverrideUrlNull() { String actual = LicenseMojoUtils.prepareThirdPartyOverrideUrl(resolvedUrl, deprecatedFile, url, basedir, log); assertEquals(LicenseMojoUtils.NO_URL, actual); } @Test - public void testPrepareThirdPartyOverrideUrlBothOverrides() { + void testPrepareThirdPartyOverrideUrlBothOverrides() { deprecatedFile = new File("src/test/resources/overrides.properties"); url = "classpath:overrides.properties"; try { @@ -68,7 +68,7 @@ public void testPrepareThirdPartyOverrideUrlBothOverrides() { } @Test - public void testPrepareThirdPartyOverrideUrlNonExistingDeprecatedFile() { + void testPrepareThirdPartyOverrideUrlNonExistingDeprecatedFile() { deprecatedFile = new File("foo"); String actual = runTestAndJoinResults(); assertEquals( @@ -81,7 +81,7 @@ public void testPrepareThirdPartyOverrideUrlNonExistingDeprecatedFile() { } @Test - public void testPrepareThirdPartyOverrideUrlDeprecatedFile() { + void testPrepareThirdPartyOverrideUrlDeprecatedFile() { deprecatedFile = new File("src/test/resources/overrides.properties"); String actual = runTestAndJoinResults(); assertEquals( @@ -93,7 +93,7 @@ public void testPrepareThirdPartyOverrideUrlDeprecatedFile() { } @Test - public void testPrepareThirdPartyOverrideClasspathResource() { + void testPrepareThirdPartyOverrideClasspathResource() { url = "classpath:overrides.properties"; String actual = LicenseMojoUtils.prepareThirdPartyOverrideUrl(resolvedUrl, deprecatedFile, url, basedir, log); assertEquals(url, actual); @@ -102,7 +102,7 @@ public void testPrepareThirdPartyOverrideClasspathResource() { } @Test - public void testPrepareThirdPartyOverrideInvalidUrl() { + void testPrepareThirdPartyOverrideInvalidUrl() { url = "foo://localhost/bar"; String actual = runTestAndJoinResults(); assertEquals( @@ -114,7 +114,7 @@ public void testPrepareThirdPartyOverrideInvalidUrl() { } @Test - public void testPrepareThirdPartyOverridePreventReinit() { + void testPrepareThirdPartyOverridePreventReinit() { resolvedUrl = "classpath:overrides.properties"; deprecatedFile = new File("foo"); url = "classpath:bar"; diff --git a/src/test/java/org/codehaus/mojo/license/api/ArtifactFiltersTest.java b/src/test/java/org/codehaus/mojo/license/api/ArtifactFiltersTest.java index 60fec21c6..d1454865a 100644 --- a/src/test/java/org/codehaus/mojo/license/api/ArtifactFiltersTest.java +++ b/src/test/java/org/codehaus/mojo/license/api/ArtifactFiltersTest.java @@ -11,12 +11,14 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; import org.codehaus.mojo.license.api.ArtifactFilters.Builder; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class ArtifactFiltersTest { +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ArtifactFiltersTest { @Test - public void isIncluded() throws InvalidVersionSpecificationException { + void isIncluded() throws InvalidVersionSpecificationException { final Artifact jar1Compile = new DefaultArtifact( "org.group1", "artifact1", VersionRange.createFromVersionSpec("1.0"), "compile", "jar", "", null); final Artifact jar2Compile = new DefaultArtifact( @@ -33,102 +35,102 @@ public void isIncluded() throws InvalidVersionSpecificationException { jar4CompileOptional.setOptional(true); final ArtifactFilters defaultFilters = ArtifactFilters.buidler().build(); - Assert.assertTrue(defaultFilters.isIncluded(jar1Compile)); - Assert.assertTrue(defaultFilters.isIncluded(jar2Compile)); - Assert.assertTrue(defaultFilters.isIncluded(war1Compile)); - Assert.assertTrue(defaultFilters.isIncluded(jar1Test)); - Assert.assertTrue(defaultFilters.isIncluded(jar4CompileOptional)); + assertTrue(defaultFilters.isIncluded(jar1Compile)); + assertTrue(defaultFilters.isIncluded(jar2Compile)); + assertTrue(defaultFilters.isIncluded(war1Compile)); + assertTrue(defaultFilters.isIncluded(jar1Test)); + assertTrue(defaultFilters.isIncluded(jar4CompileOptional)); final ArtifactFilters includeScope = ArtifactFilters.buidler().includeScope("compile").build(); - Assert.assertTrue(includeScope.isIncluded(jar1Compile)); - Assert.assertTrue(includeScope.isIncluded(jar2Compile)); - Assert.assertTrue(includeScope.isIncluded(war1Compile)); - Assert.assertFalse(includeScope.isIncluded(jar1Test)); - Assert.assertTrue(includeScope.isIncluded(jar4CompileOptional)); + assertTrue(includeScope.isIncluded(jar1Compile)); + assertTrue(includeScope.isIncluded(jar2Compile)); + assertTrue(includeScope.isIncluded(war1Compile)); + assertFalse(includeScope.isIncluded(jar1Test)); + assertTrue(includeScope.isIncluded(jar4CompileOptional)); final ArtifactFilters excludeScope = ArtifactFilters.buidler().excludeScope("test").build(); - Assert.assertTrue(excludeScope.isIncluded(jar1Compile)); - Assert.assertTrue(excludeScope.isIncluded(jar2Compile)); - Assert.assertTrue(excludeScope.isIncluded(war1Compile)); - Assert.assertFalse(excludeScope.isIncluded(jar1Test)); - Assert.assertTrue(excludeScope.isIncluded(jar4CompileOptional)); + assertTrue(excludeScope.isIncluded(jar1Compile)); + assertTrue(excludeScope.isIncluded(jar2Compile)); + assertTrue(excludeScope.isIncluded(war1Compile)); + assertFalse(excludeScope.isIncluded(jar1Test)); + assertTrue(excludeScope.isIncluded(jar4CompileOptional)); final ArtifactFilters includeType = ArtifactFilters.buidler().includeType("jar").build(); - Assert.assertTrue(includeType.isIncluded(jar1Compile)); - Assert.assertTrue(includeType.isIncluded(jar2Compile)); - Assert.assertFalse(includeType.isIncluded(war1Compile)); - Assert.assertTrue(includeType.isIncluded(jar1Test)); - Assert.assertTrue(includeType.isIncluded(jar4CompileOptional)); + assertTrue(includeType.isIncluded(jar1Compile)); + assertTrue(includeType.isIncluded(jar2Compile)); + assertFalse(includeType.isIncluded(war1Compile)); + assertTrue(includeType.isIncluded(jar1Test)); + assertTrue(includeType.isIncluded(jar4CompileOptional)); final ArtifactFilters excludeType = ArtifactFilters.buidler().excludeType("war").build(); - Assert.assertTrue(excludeType.isIncluded(jar1Compile)); - Assert.assertTrue(excludeType.isIncluded(jar2Compile)); - Assert.assertFalse(excludeType.isIncluded(war1Compile)); - Assert.assertTrue(excludeType.isIncluded(jar1Test)); - Assert.assertTrue(excludeType.isIncluded(jar4CompileOptional)); + assertTrue(excludeType.isIncluded(jar1Compile)); + assertTrue(excludeType.isIncluded(jar2Compile)); + assertFalse(excludeType.isIncluded(war1Compile)); + assertTrue(excludeType.isIncluded(jar1Test)); + assertTrue(excludeType.isIncluded(jar4CompileOptional)); final ArtifactFilters includeGa = ArtifactFilters.buidler().includeGa("org\\.group1:artifact[^2]").build(); - Assert.assertTrue(includeGa.isIncluded(jar1Compile)); - Assert.assertFalse(includeGa.isIncluded(jar2Compile)); - Assert.assertTrue(includeGa.isIncluded(war1Compile)); - Assert.assertTrue(includeGa.isIncluded(jar1Test)); - Assert.assertTrue(includeGa.isIncluded(jar4CompileOptional)); + assertTrue(includeGa.isIncluded(jar1Compile)); + assertFalse(includeGa.isIncluded(jar2Compile)); + assertTrue(includeGa.isIncluded(war1Compile)); + assertTrue(includeGa.isIncluded(jar1Test)); + assertTrue(includeGa.isIncluded(jar4CompileOptional)); final ArtifactFilters includeGas = ArtifactFilters.buidler() .includeGas("org\\.group1:artifact1", "org\\.group1:artifact3") .build(); - Assert.assertTrue(includeGas.isIncluded(jar1Compile)); - Assert.assertFalse(includeGas.isIncluded(jar2Compile)); - Assert.assertTrue(includeGas.isIncluded(jar3Compile)); - Assert.assertTrue(includeGas.isIncluded(war1Compile)); - Assert.assertTrue(includeGas.isIncluded(jar1Test)); - Assert.assertFalse(includeGas.isIncluded(jar4CompileOptional)); + assertTrue(includeGas.isIncluded(jar1Compile)); + assertFalse(includeGas.isIncluded(jar2Compile)); + assertTrue(includeGas.isIncluded(jar3Compile)); + assertTrue(includeGas.isIncluded(war1Compile)); + assertTrue(includeGas.isIncluded(jar1Test)); + assertFalse(includeGas.isIncluded(jar4CompileOptional)); final ArtifactFilters excludeGas = ArtifactFilters.buidler() .excludeGas("org\\.group1:artifact2", "org\\.group1:artifact3") .build(); - Assert.assertTrue(excludeGas.isIncluded(jar1Compile)); - Assert.assertFalse(excludeGas.isIncluded(jar2Compile)); - Assert.assertFalse(excludeGas.isIncluded(jar3Compile)); - Assert.assertTrue(excludeGas.isIncluded(war1Compile)); - Assert.assertTrue(excludeGas.isIncluded(jar1Test)); - Assert.assertTrue(excludeGas.isIncluded(jar4CompileOptional)); + assertTrue(excludeGas.isIncluded(jar1Compile)); + assertFalse(excludeGas.isIncluded(jar2Compile)); + assertFalse(excludeGas.isIncluded(jar3Compile)); + assertTrue(excludeGas.isIncluded(war1Compile)); + assertTrue(excludeGas.isIncluded(jar1Test)); + assertTrue(excludeGas.isIncluded(jar4CompileOptional)); final ArtifactFilters excludeGa = ArtifactFilters.buidler().excludeGa("org\\.group1:artifact2").build(); - Assert.assertTrue(excludeGa.isIncluded(jar1Compile)); - Assert.assertFalse(excludeGa.isIncluded(jar2Compile)); - Assert.assertTrue(excludeGa.isIncluded(war1Compile)); - Assert.assertTrue(excludeGa.isIncluded(jar1Test)); - Assert.assertTrue(excludeGa.isIncluded(jar4CompileOptional)); + assertTrue(excludeGa.isIncluded(jar1Compile)); + assertFalse(excludeGa.isIncluded(jar2Compile)); + assertTrue(excludeGa.isIncluded(war1Compile)); + assertTrue(excludeGa.isIncluded(jar1Test)); + assertTrue(excludeGa.isIncluded(jar4CompileOptional)); final ArtifactFilters includeExcludeGas = ArtifactFilters.buidler() .includeGa("org\\.group1:.*") .excludeGa("org\\.group1:artifact3") .build(); - Assert.assertTrue(includeExcludeGas.isIncluded(jar1Compile)); - Assert.assertTrue(includeExcludeGas.isIncluded(jar2Compile)); - Assert.assertFalse(includeExcludeGas.isIncluded(jar3Compile)); - Assert.assertTrue(includeExcludeGas.isIncluded(war1Compile)); - Assert.assertTrue(includeExcludeGas.isIncluded(jar1Test)); - Assert.assertTrue(includeExcludeGas.isIncluded(jar4CompileOptional)); + assertTrue(includeExcludeGas.isIncluded(jar1Compile)); + assertTrue(includeExcludeGas.isIncluded(jar2Compile)); + assertFalse(includeExcludeGas.isIncluded(jar3Compile)); + assertTrue(includeExcludeGas.isIncluded(war1Compile)); + assertTrue(includeExcludeGas.isIncluded(jar1Test)); + assertTrue(includeExcludeGas.isIncluded(jar4CompileOptional)); final ArtifactFilters includeExcludeGasType = ArtifactFilters.buidler() .includeGa("org\\.group1:.*") .excludeGa("org\\.group1:artifact3") .excludeType("war") .build(); - Assert.assertTrue(includeExcludeGasType.isIncluded(jar1Compile)); - Assert.assertTrue(includeExcludeGasType.isIncluded(jar2Compile)); - Assert.assertFalse(includeExcludeGasType.isIncluded(jar3Compile)); - Assert.assertFalse(includeExcludeGasType.isIncluded(war1Compile)); - Assert.assertTrue(includeExcludeGasType.isIncluded(jar1Test)); - Assert.assertTrue(includeExcludeGasType.isIncluded(jar4CompileOptional)); + assertTrue(includeExcludeGasType.isIncluded(jar1Compile)); + assertTrue(includeExcludeGasType.isIncluded(jar2Compile)); + assertFalse(includeExcludeGasType.isIncluded(jar3Compile)); + assertFalse(includeExcludeGasType.isIncluded(war1Compile)); + assertTrue(includeExcludeGasType.isIncluded(jar1Test)); + assertTrue(includeExcludeGasType.isIncluded(jar4CompileOptional)); final ArtifactFilters includeExcludeGasTypeScope = ArtifactFilters.buidler() .includeGa("org\\.group1:.*") @@ -136,32 +138,32 @@ public void isIncluded() throws InvalidVersionSpecificationException { .excludeType("war") .excludeScope("test") .build(); - Assert.assertTrue(includeExcludeGasTypeScope.isIncluded(jar1Compile)); - Assert.assertTrue(includeExcludeGasTypeScope.isIncluded(jar2Compile)); - Assert.assertFalse(includeExcludeGasTypeScope.isIncluded(jar3Compile)); - Assert.assertFalse(includeExcludeGasTypeScope.isIncluded(war1Compile)); - Assert.assertFalse(includeExcludeGasTypeScope.isIncluded(jar1Test)); - Assert.assertTrue(includeExcludeGasTypeScope.isIncluded(jar4CompileOptional)); + assertTrue(includeExcludeGasTypeScope.isIncluded(jar1Compile)); + assertTrue(includeExcludeGasTypeScope.isIncluded(jar2Compile)); + assertFalse(includeExcludeGasTypeScope.isIncluded(jar3Compile)); + assertFalse(includeExcludeGasTypeScope.isIncluded(war1Compile)); + assertFalse(includeExcludeGasTypeScope.isIncluded(jar1Test)); + assertTrue(includeExcludeGasTypeScope.isIncluded(jar4CompileOptional)); final ArtifactFilters includeOptional = ArtifactFilters.buidler().includeOptional(true).build(); - Assert.assertTrue(includeOptional.isIncluded(jar1Compile)); - Assert.assertTrue(includeOptional.isIncluded(jar2Compile)); - Assert.assertTrue(includeOptional.isIncluded(war1Compile)); - Assert.assertTrue(includeOptional.isIncluded(jar1Test)); - Assert.assertTrue(includeOptional.isIncluded(jar4CompileOptional)); + assertTrue(includeOptional.isIncluded(jar1Compile)); + assertTrue(includeOptional.isIncluded(jar2Compile)); + assertTrue(includeOptional.isIncluded(war1Compile)); + assertTrue(includeOptional.isIncluded(jar1Test)); + assertTrue(includeOptional.isIncluded(jar4CompileOptional)); final ArtifactFilters excludeOptional = ArtifactFilters.buidler().includeOptional(false).build(); - Assert.assertTrue(excludeOptional.isIncluded(jar1Compile)); - Assert.assertTrue(excludeOptional.isIncluded(jar2Compile)); - Assert.assertTrue(excludeOptional.isIncluded(war1Compile)); - Assert.assertTrue(excludeOptional.isIncluded(jar1Test)); - Assert.assertFalse(excludeOptional.isIncluded(jar4CompileOptional)); + assertTrue(excludeOptional.isIncluded(jar1Compile)); + assertTrue(excludeOptional.isIncluded(jar2Compile)); + assertTrue(excludeOptional.isIncluded(war1Compile)); + assertTrue(excludeOptional.isIncluded(jar1Test)); + assertFalse(excludeOptional.isIncluded(jar4CompileOptional)); } @Test - public void urlContent() throws IOException, InvalidVersionSpecificationException { + void urlContent() throws IOException, InvalidVersionSpecificationException { final Builder builder = ArtifactFilters.buidler(); final URL url = getClass().getClassLoader().getResource("org/codehaus/mojo/license/api/atifact-filters.txt"); try (InputStream in = url.openStream()) { @@ -185,11 +187,11 @@ public void urlContent() throws IOException, InvalidVersionSpecificationExceptio "org.group1", "artifact4", VersionRange.createFromVersionSpec("1.0"), "compile", "jar", "", null); jar4CompileOptional.setOptional(false); - Assert.assertTrue(filters.isIncluded(jar1Compile)); - Assert.assertFalse(filters.isIncluded(jar2Compile)); - Assert.assertFalse(filters.isIncluded(jar3Compile)); - Assert.assertFalse(filters.isIncluded(war1Compile)); - Assert.assertFalse(filters.isIncluded(jar1Test)); - Assert.assertFalse(filters.isIncluded(jar4CompileOptional)); + assertTrue(filters.isIncluded(jar1Compile)); + assertFalse(filters.isIncluded(jar2Compile)); + assertFalse(filters.isIncluded(jar3Compile)); + assertFalse(filters.isIncluded(war1Compile)); + assertFalse(filters.isIncluded(jar1Test)); + assertFalse(filters.isIncluded(jar4CompileOptional)); } } diff --git a/src/test/java/org/codehaus/mojo/license/api/FreeMarkerHelperTest.java b/src/test/java/org/codehaus/mojo/license/api/FreeMarkerHelperTest.java index 505c4299c..d61e9d961 100644 --- a/src/test/java/org/codehaus/mojo/license/api/FreeMarkerHelperTest.java +++ b/src/test/java/org/codehaus/mojo/license/api/FreeMarkerHelperTest.java @@ -29,22 +29,23 @@ import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.project.MavenProject; import org.codehaus.mojo.license.model.LicenseMap; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * Tests the {@link FreeMarkerHelper} and given templates. * * @author tchemit dev@tchemit.fr * @since 1.1 */ -public class FreeMarkerHelperTest { +class FreeMarkerHelperTest { private static final Logger LOG = LoggerFactory.getLogger(FreeMarkerHelperTest.class); @Test - public void testRenderTemplateForThirdPartyFile() throws Exception { + void testRenderTemplateForThirdPartyFile() throws Exception { FreeMarkerHelper helper = FreeMarkerHelper.newDefaultHelper(); @@ -87,7 +88,7 @@ public void testRenderTemplateForThirdPartyFile() throws Exception { } @Test - public void testRenderTemplateForThirdPartyFileGroupByLicense() throws Exception { + void testRenderTemplateForThirdPartyFileGroupByLicense() throws Exception { FreeMarkerHelper helper = FreeMarkerHelper.newDefaultHelper(); @@ -130,7 +131,7 @@ public void testRenderTemplateForThirdPartyFileGroupByLicense() throws Exception } @Test - public void testRenderTemplateForUpdateFileHeader() throws Exception { + void testRenderTemplateForUpdateFileHeader() throws Exception { FreeMarkerHelper helper = FreeMarkerHelper.newDefaultHelper(); @@ -155,7 +156,7 @@ public void testRenderTemplateForUpdateFileHeader() throws Exception { properties.put("addSvnKeyWords", true); String s = helper.renderTemplate("/org/codehaus/mojo/license/default-file-header-description.ftl", properties); - Assert.assertEquals("projectName\n$Id:$\n$HeadURL:$", s); + assertEquals("projectName\n$Id:$\n$HeadURL:$", s); LOG.info("{}", s); } } diff --git a/src/test/java/org/codehaus/mojo/license/download/LicenseDownloaderTest.java b/src/test/java/org/codehaus/mojo/license/download/LicenseDownloaderTest.java index 9b566a149..cef7f9298 100644 --- a/src/test/java/org/codehaus/mojo/license/download/LicenseDownloaderTest.java +++ b/src/test/java/org/codehaus/mojo/license/download/LicenseDownloaderTest.java @@ -24,13 +24,14 @@ import java.io.File; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class LicenseDownloaderTest { +import static org.junit.jupiter.api.Assertions.assertEquals; + +class LicenseDownloaderTest { @Test - public void updateFileExtension() { + void updateFileExtension() { assertExtension("path/to/file.html", "path/to/file.php", "text/html"); assertExtension("path/to/file.txt", "path/to/file", null); } @@ -38,6 +39,6 @@ public void updateFileExtension() { private static void assertExtension(String expected, String input, String mimeType) { final File in = new File(input); final File result = LicenseDownloader.updateFileExtension(in, mimeType); - Assert.assertEquals(expected, result.getPath().replace('\\', '/')); + assertEquals(expected, result.getPath().replace('\\', '/')); } } diff --git a/src/test/java/org/codehaus/mojo/license/download/LicenseMatchersTest.java b/src/test/java/org/codehaus/mojo/license/download/LicenseMatchersTest.java index 28c758840..2cb4166cb 100644 --- a/src/test/java/org/codehaus/mojo/license/download/LicenseMatchersTest.java +++ b/src/test/java/org/codehaus/mojo/license/download/LicenseMatchersTest.java @@ -26,31 +26,36 @@ import org.codehaus.mojo.license.download.LicenseMatchers.DependencyMatcher; import org.codehaus.mojo.license.download.LicenseMatchers.LicenseMatcher; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class LicenseMatchersTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class LicenseMatchersTest { @Test - public void licenseMatches() { + void licenseMatches() { final LicenseMatcher lm1 = new LicenseMatcher("my license", "http://some.com", null, "important comment"); final ProjectLicense lic = new ProjectLicense("my license", "http://some.com", null, "important comment", null); - Assert.assertTrue(lm1.matches(lic)); + assertTrue(lm1.matches(lic)); lic.setName("other license"); - Assert.assertFalse(lm1.matches(lic)); + assertFalse(lm1.matches(lic)); final LicenseMatcher lm2 = new LicenseMatcher("other.*", "http://some.com", null, "important comment"); - Assert.assertTrue(lm2.matches(lic)); + assertTrue(lm2.matches(lic)); lic.setUrl("http://other.org"); - Assert.assertFalse(lm2.matches(lic)); + assertFalse(lm2.matches(lic)); final LicenseMatcher lm3 = new LicenseMatcher("other.*", "http://other\\..*", null, "important comment"); - Assert.assertTrue(lm3.matches(lic)); + assertTrue(lm3.matches(lic)); lic.setComments("other comment"); - Assert.assertFalse(lm3.matches(lic)); + assertFalse(lm3.matches(lic)); final LicenseMatcher lm4 = new LicenseMatcher("other.*", "http://other\\..*", null, ".*comment"); - Assert.assertTrue(lm4.matches(lic)); + assertTrue(lm4.matches(lic)); lic.setComments(null); lic.setDistribution(null); @@ -58,73 +63,73 @@ public void licenseMatches() { lic.setName(null); lic.setUrl(null); final LicenseMatcher lm5 = new LicenseMatcher((String) null, (String) null, (String) null, (String) null); - Assert.assertTrue(lm5.matches(lic)); + assertTrue(lm5.matches(lic)); lic.setComments(""); lic.setDistribution(""); lic.setFile(""); lic.setName(""); lic.setUrl(""); - Assert.assertTrue(lm5.matches(lic)); + assertTrue(lm5.matches(lic)); } @Test - public void replaceMatchesLegacy() { + void replaceMatchesLegacy() { final ProjectLicenseInfo dep = new ProjectLicenseInfo("myGroup", "myArtifact", "1a2.3", null); final ProjectLicenseInfo pli1 = new ProjectLicenseInfo("myGroup", "myArtifact", "1.2.3", false); final ProjectLicense lic2 = new ProjectLicense("lic2", "http://other.org", null, "other comment", null); pli1.addLicense(lic2); final DependencyMatcher m1 = DependencyMatcher.of(pli1); - Assert.assertTrue(m1.matches(dep)); // legacy mode disregards the version + assertTrue(m1.matches(dep)); // legacy mode disregards the version dep.setVersion("1.2.3"); - Assert.assertTrue(m1.matches(dep)); + assertTrue(m1.matches(dep)); dep.addLicense(new ProjectLicense("lic1", "http://some.org", null, "comment", null)); - Assert.assertTrue(m1.matches(dep)); + assertTrue(m1.matches(dep)); final LicenseMatchers matchers1 = LicenseMatchers.builder().matcher(m1).build(); matchers1.replaceMatches(dep); - Assert.assertEquals(1, dep.getLicenses().size()); - Assert.assertEquals(lic2, dep.getLicenses().get(0)); - Assert.assertNotSame(lic2, dep.getLicenses().get(0)); + assertEquals(1, dep.getLicenses().size()); + assertEquals(lic2, dep.getLicenses().get(0)); + assertNotSame(lic2, dep.getLicenses().get(0)); } @Test - public void replaceMatches() { + void replaceMatches() { final ProjectLicenseInfo dep = new ProjectLicenseInfo("myGroup", "myArtifact", "1.2.3", null); final DependencyMatcher m0 = DependencyMatcher.of(new ProjectLicenseInfo("myGroup", "myArtifact", null, true)); - Assert.assertTrue(m0.matches(dep)); + assertTrue(m0.matches(dep)); final DependencyMatcher m1 = DependencyMatcher.of(new ProjectLicenseInfo("myGroup", "myArtifact", "1\\.2\\.3", true)); - Assert.assertTrue(m1.matches(dep)); + assertTrue(m1.matches(dep)); dep.setGroupId("otherGroup"); - Assert.assertFalse(m1.matches(dep)); + assertFalse(m1.matches(dep)); final DependencyMatcher m2 = DependencyMatcher.of(new ProjectLicenseInfo("other.*", "myArtifact", "1\\.2\\.3", true)); - Assert.assertTrue(m2.matches(dep)); + assertTrue(m2.matches(dep)); dep.setArtifactId("otherArtifact"); - Assert.assertFalse(m2.matches(dep)); + assertFalse(m2.matches(dep)); final DependencyMatcher m3 = DependencyMatcher.of(new ProjectLicenseInfo("other.*", ".*Artifact", "1\\.2\\.3", true)); - Assert.assertTrue(m3.matches(dep)); + assertTrue(m3.matches(dep)); dep.setVersion("2.2.2"); - Assert.assertFalse(m3.matches(dep)); + assertFalse(m3.matches(dep)); final DependencyMatcher m4 = DependencyMatcher.of(new ProjectLicenseInfo("other.*", ".*Artifact", "2\\.2\\..*", true)); - Assert.assertTrue(m4.matches(dep)); + assertTrue(m4.matches(dep)); final LicenseMatchers matchers1 = LicenseMatchers.builder().matcher(m1).build(); final List oldLics = dep.cloneLicenses(); matchers1.replaceMatches(dep); - Assert.assertEquals(oldLics, dep.getLicenses()); + assertEquals(oldLics, dep.getLicenses()); dep.addLicense(new ProjectLicense("lic1", "http://some.org", null, "comment", null)); - Assert.assertFalse(m1.matches(dep)); + assertFalse(m1.matches(dep)); final ProjectLicenseInfo dep11 = new ProjectLicenseInfo("myGroup", "myArtifact", "1.2.3", null); dep11.addLicense(new ProjectLicense("lic1", "http://some.org", null, "comment", null)); @@ -133,18 +138,18 @@ public void replaceMatches() { pli11.addMatchLicense(new ProjectLicense("lic1", "http://some\\.org", null, "comment", null)); pli11.addLicense(new ProjectLicense("lic2", "http://other.org", null, "other comment", null)); final DependencyMatcher m11 = DependencyMatcher.of(pli11); - Assert.assertTrue(m11.matches(dep11)); + assertTrue(m11.matches(dep11)); - Assert.assertEquals(oldLics11, dep11.getLicenses()); + assertEquals(oldLics11, dep11.getLicenses()); final LicenseMatchers matchers11 = LicenseMatchers.builder().matcher(m11).build(); matchers11.replaceMatches(dep11); - Assert.assertNotEquals(oldLics11, dep11.getLicenses()); + assertNotEquals(oldLics11, dep11.getLicenses()); final List newLics = dep11.getLicenses(); - Assert.assertEquals(1, newLics.size()); - Assert.assertEquals(1, newLics.size()); + assertEquals(1, newLics.size()); + assertEquals(1, newLics.size()); } } diff --git a/src/test/java/org/codehaus/mojo/license/download/LicenseSummaryTest.java b/src/test/java/org/codehaus/mojo/license/download/LicenseSummaryTest.java index 3384491b6..e42168b7e 100644 --- a/src/test/java/org/codehaus/mojo/license/download/LicenseSummaryTest.java +++ b/src/test/java/org/codehaus/mojo/license/download/LicenseSummaryTest.java @@ -33,19 +33,20 @@ import org.codehaus.mojo.license.extended.InfoFile; import org.codehaus.mojo.license.extended.spreadsheet.CalcFileWriter; import org.codehaus.mojo.license.extended.spreadsheet.ExcelFileWriter; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; import static org.codehaus.mojo.license.download.LicenseSummaryWriter.LICENSE_PATH; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @since 1.0 */ -public class LicenseSummaryTest { +class LicenseSummaryTest { private static final Logger LOG = LoggerFactory.getLogger(LicenseSummaryTest.class); /** @@ -56,7 +57,7 @@ public class LicenseSummaryTest { * @throws SAXException if any */ @Test - public void testReadLicenseSummary() throws IOException, SAXException, ParserConfigurationException { + void testReadLicenseSummary() throws IOException, SAXException, ParserConfigurationException { File licenseSummaryFile = new File("src/test/resources/license-summary-test.xml"); assertTrue(licenseSummaryFile.exists()); List list; @@ -64,17 +65,17 @@ public void testReadLicenseSummary() throws IOException, SAXException, ParserCon list = LicenseSummaryReader.parseLicenseSummary(fis); } ProjectLicenseInfo dep = list.get(0); - Assert.assertEquals("org.codehaus.mojo", dep.getGroupId()); - Assert.assertEquals("junk", dep.getArtifactId()); - Assert.assertEquals("1.1", dep.getVersion()); + assertEquals("org.codehaus.mojo", dep.getGroupId()); + assertEquals("junk", dep.getArtifactId()); + assertEquals("1.1", dep.getVersion()); List licenses = dep.getLicenses(); - Assert.assertEquals(1, licenses.size()); + assertEquals(1, licenses.size()); ProjectLicense lic0 = dep.getLicenses().get(0); - Assert.assertEquals("lgpl", lic0.getName()); - Assert.assertEquals("http://www.gnu.org/licenses/lgpl-3.0.txt", lic0.getUrl()); - Assert.assertEquals("lgpl-3.0.txt", lic0.getFile()); - Assert.assertEquals("lgpl version 3.0", lic0.getComments()); + assertEquals("lgpl", lic0.getName()); + assertEquals("http://www.gnu.org/licenses/lgpl-3.0.txt", lic0.getUrl()); + assertEquals("lgpl-3.0.txt", lic0.getFile()); + assertEquals("lgpl version 3.0", lic0.getComments()); } /** @@ -88,7 +89,7 @@ public void testReadLicenseSummary() throws IOException, SAXException, ParserCon * @throws SAXException if any */ @Test - public void testWriteReadLicenseSummary() + void testWriteReadLicenseSummary() throws IOException, SAXException, ParserConfigurationException, TransformerFactoryConfigurationError, TransformerException { List licSummary = new ArrayList<>(); @@ -123,17 +124,17 @@ public void testWriteReadLicenseSummary() List list = LicenseSummaryReader.parseLicenseSummary(fis); fis.close(); ProjectLicenseInfo dep = list.get(0); - Assert.assertEquals("org.test", dep.getGroupId()); - Assert.assertEquals("test1", dep.getArtifactId()); - Assert.assertEquals("1.0", dep.getVersion()); + assertEquals("org.test", dep.getGroupId()); + assertEquals("test1", dep.getArtifactId()); + assertEquals("1.0", dep.getVersion()); List licenses = dep.getLicenses(); - Assert.assertEquals(1, licenses.size()); + assertEquals(1, licenses.size()); ProjectLicense lic0 = dep.getLicenses().get(0); - Assert.assertEquals("lgpl", lic0.getName()); - Assert.assertEquals("http://www.gnu.org/licenses/lgpl-3.0.txt", lic0.getUrl()); - Assert.assertEquals("lgpl-3.0.txt", lic0.getFile()); - Assert.assertEquals("lgpl version 3.0", lic0.getComments()); + assertEquals("lgpl", lic0.getName()); + assertEquals("http://www.gnu.org/licenses/lgpl-3.0.txt", lic0.getUrl()); + assertEquals("lgpl-3.0.txt", lic0.getFile()); + assertEquals("lgpl version 3.0", lic0.getComments()); validateXml(licenseSummaryFile); @@ -145,17 +146,17 @@ public void testWriteReadLicenseSummary() list = LicenseSummaryReader.parseLicenseSummary(fis); fis.close(); dep = list.get(0); - Assert.assertEquals("org.test", dep.getGroupId()); - Assert.assertEquals("test1", dep.getArtifactId()); - Assert.assertNull(dep.getVersion()); + assertEquals("org.test", dep.getGroupId()); + assertEquals("test1", dep.getArtifactId()); + assertNull(dep.getVersion()); licenses = dep.getLicenses(); - Assert.assertEquals(1, licenses.size()); + assertEquals(1, licenses.size()); lic0 = dep.getLicenses().get(0); - Assert.assertEquals("lgpl", lic0.getName()); - Assert.assertEquals("http://www.gnu.org/licenses/lgpl-3.0.txt", lic0.getUrl()); - Assert.assertEquals("lgpl-3.0.txt", lic0.getFile()); - Assert.assertEquals("lgpl version 3.0", lic0.getComments()); + assertEquals("lgpl", lic0.getName()); + assertEquals("http://www.gnu.org/licenses/lgpl-3.0.txt", lic0.getUrl()); + assertEquals("lgpl-3.0.txt", lic0.getFile()); + assertEquals("lgpl version 3.0", lic0.getComments()); validateXml(licenseSummaryFile); @@ -244,11 +245,11 @@ private static Developer createDeveloper(int suffix) { } @Test - public void patternOrText() { - Assert.assertEquals("\\Qsimple\\E", LicenseSummaryWriter.patternOrText("simple", true)); - Assert.assertEquals("\\Qone two\\E", LicenseSummaryWriter.patternOrText("one two", true)); - Assert.assertEquals("\\Qone\\E\\s+\\Qtwo\\E", LicenseSummaryWriter.patternOrText("one two", true)); - Assert.assertEquals("\\Qone\ntwo\\E", LicenseSummaryWriter.patternOrText("one\ntwo", true)); - Assert.assertEquals("\\Qone\\E\\s+\\Qtwo\\E", LicenseSummaryWriter.patternOrText("one\n\t\ttwo", true)); + void patternOrText() { + assertEquals("\\Qsimple\\E", LicenseSummaryWriter.patternOrText("simple", true)); + assertEquals("\\Qone two\\E", LicenseSummaryWriter.patternOrText("one two", true)); + assertEquals("\\Qone\\E\\s+\\Qtwo\\E", LicenseSummaryWriter.patternOrText("one two", true)); + assertEquals("\\Qone\ntwo\\E", LicenseSummaryWriter.patternOrText("one\ntwo", true)); + assertEquals("\\Qone\\E\\s+\\Qtwo\\E", LicenseSummaryWriter.patternOrText("one\n\t\ttwo", true)); } } diff --git a/src/test/java/org/codehaus/mojo/license/header/transformer/AbstractFileHeaderTransformerTest.java b/src/test/java/org/codehaus/mojo/license/header/transformer/AbstractFileHeaderTransformerTest.java index bb7cc1b0b..cdf18424b 100644 --- a/src/test/java/org/codehaus/mojo/license/header/transformer/AbstractFileHeaderTransformerTest.java +++ b/src/test/java/org/codehaus/mojo/license/header/transformer/AbstractFileHeaderTransformerTest.java @@ -26,16 +26,20 @@ import org.codehaus.mojo.license.header.FileHeader; import org.codehaus.mojo.license.model.Copyright; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.codehaus.mojo.license.header.transformer.AbstractFileHeaderTransformer.COPYRIGHT_PATTERN; import static org.codehaus.mojo.license.header.transformer.FileHeaderTransformer.DEFAULT_PROCESS_END_TAG; import static org.codehaus.mojo.license.header.transformer.FileHeaderTransformer.DEFAULT_PROCESS_START_TAG; import static org.codehaus.mojo.license.header.transformer.FileHeaderTransformer.DEFAULT_SECTION_DELIMITER; import static org.codehaus.mojo.license.header.transformer.FileHeaderTransformer.LINE_SEPARATOR; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests the {@link AbstractFileHeaderTransformer}. @@ -43,14 +47,14 @@ * @author tchemit dev@tchemit.fr * @since 1.0 */ -public class AbstractFileHeaderTransformerTest { +class AbstractFileHeaderTransformerTest { FileHeaderTransformer transformer; FileHeader model1, model2; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { transformer = new JavaFileHeaderTransformer(); model1 = new FileHeader(); @@ -64,37 +68,43 @@ public void setUp() throws Exception { model2.setLicense("License2"); } - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { transformer = null; model1 = null; model2 = null; } - @Test(expected = IllegalStateException.class) - public void testIllegalTransformer() throws Exception { - - new AbstractFileHeaderTransformer("name", "description", "commentPrefix", "commentEndtag", "commentPrefix") { - - public String[] getDefaultAcceptedExtensions() { - return new String[] {getName()}; - } - }; + @Test + void testIllegalTransformer() throws Exception { + assertThrows( + IllegalStateException.class, + () -> + new AbstractFileHeaderTransformer( + "name", "description", "commentPrefix", "commentEndtag", "commentPrefix") { + + public String[] getDefaultAcceptedExtensions() { + return new String[] {getName()}; + } + }); } - @Test(expected = IllegalStateException.class) - public void testIllegalTransformer2() throws Exception { - - new AbstractFileHeaderTransformer("name", "description", "commentstartTag", "commentPrefix", "commentPrefix") { - - public String[] getDefaultAcceptedExtensions() { - return new String[] {getName()}; - } - }; + @Test + void testIllegalTransformer2() throws Exception { + assertThrows( + IllegalStateException.class, + () -> + new AbstractFileHeaderTransformer( + "name", "description", "commentstartTag", "commentPrefix", "commentPrefix") { + + public String[] getDefaultAcceptedExtensions() { + return new String[] {getName()}; + } + }); } @Test - public void testCopyrightPattern() throws Exception { + void testCopyrightPattern() throws Exception { String actual; Matcher matcher; String prefix; @@ -104,76 +114,76 @@ public void testCopyrightPattern() throws Exception { actual = "Copyright (C) 2010 Tony"; matcher = COPYRIGHT_PATTERN.matcher(actual); - Assert.assertTrue(matcher.matches()); - Assert.assertEquals(5, matcher.groupCount()); + assertTrue(matcher.matches()); + assertEquals(5, matcher.groupCount()); prefix = matcher.group(1); - Assert.assertEquals("Copyright (C)", prefix); + assertEquals("Copyright (C)", prefix); firstYear = matcher.group(2); - Assert.assertEquals("2010", firstYear); + assertEquals("2010", firstYear); lastYear = matcher.group(4); - Assert.assertEquals(null, lastYear); + assertEquals(null, lastYear); holder = matcher.group(5); - Assert.assertEquals("Tony", holder); + assertEquals("Tony", holder); actual = "Copyright (C) 2010 - 2012 Tony"; matcher = COPYRIGHT_PATTERN.matcher(actual); - Assert.assertTrue(matcher.matches()); - Assert.assertEquals(5, matcher.groupCount()); + assertTrue(matcher.matches()); + assertEquals(5, matcher.groupCount()); prefix = matcher.group(1); - Assert.assertEquals("Copyright (C)", prefix); + assertEquals("Copyright (C)", prefix); firstYear = matcher.group(2); - Assert.assertEquals("2010", firstYear); + assertEquals("2010", firstYear); lastYear = matcher.group(4); - Assert.assertEquals("2012", lastYear); + assertEquals("2012", lastYear); holder = matcher.group(5); - Assert.assertEquals("Tony", holder); + assertEquals("Tony", holder); // Test MLICENSE-34 (multi-line copyright holders) actual = "Copyright (C) 2010 - 2012 Tony\nAnd Yet\n Another\nLine"; matcher = COPYRIGHT_PATTERN.matcher(actual); - Assert.assertTrue(matcher.matches()); - Assert.assertEquals(5, matcher.groupCount()); + assertTrue(matcher.matches()); + assertEquals(5, matcher.groupCount()); prefix = matcher.group(1); - Assert.assertEquals("Copyright (C)", prefix); + assertEquals("Copyright (C)", prefix); firstYear = matcher.group(2); - Assert.assertEquals("2010", firstYear); + assertEquals("2010", firstYear); lastYear = matcher.group(4); - Assert.assertEquals("2012", lastYear); + assertEquals("2012", lastYear); holder = matcher.group(5); - Assert.assertEquals("Tony\nAnd Yet\n Another\nLine", holder); + assertEquals("Tony\nAnd Yet\n Another\nLine", holder); } @Test - public void testToFileHeader() throws Exception { + void testToFileHeader() throws Exception { String header; FileHeader model; header = "Description" + LINE_SEPARATOR + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR + "Copyright (C) 2010 Tony" + LINE_SEPARATOR + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR + "License"; model = transformer.toFileHeader(header); - Assert.assertNotNull(model); - assertEquals(model1, model); + assertNotNull(model); + assertFileHeaderEquals(model1, model); header = "Description2" + LINE_SEPARATOR + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR + "Copyright (C) 2010 - 2012 Tony2" + LINE_SEPARATOR + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR + "License2"; model = transformer.toFileHeader(header); - Assert.assertNotNull(model); - assertEquals(model2, model); + assertNotNull(model); + assertFileHeaderEquals(model2, model); } @Test - public void testToString() throws Exception { + void testToString() throws Exception { String header; header = transformer.toString(model1); - Assert.assertEquals( + assertEquals( "Description" + LINE_SEPARATOR + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR + "Copyright (C) 2010 Tony" + LINE_SEPARATOR + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR + "License" + LINE_SEPARATOR, header); header = transformer.toString(model2); - Assert.assertEquals( + assertEquals( "Description2" + LINE_SEPARATOR + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR + "Copyright (C) 2010 - 2012 Tony2" + LINE_SEPARATOR + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR @@ -182,13 +192,13 @@ public void testToString() throws Exception { } @Test - public void testBoxProcessTag() throws Exception { + void testBoxProcessTag() throws Exception { String header; String boxedHeader; header = transformer.toString(model1); boxedHeader = transformer.boxProcessTag(header); - Assert.assertEquals( + assertEquals( DEFAULT_PROCESS_START_TAG + LINE_SEPARATOR + "Description" + LINE_SEPARATOR + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR + "Copyright (C) 2010 Tony" + LINE_SEPARATOR + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR @@ -197,7 +207,7 @@ public void testBoxProcessTag() throws Exception { header = transformer.toString(model2); boxedHeader = transformer.boxProcessTag(header); - Assert.assertEquals( + assertEquals( DEFAULT_PROCESS_START_TAG + LINE_SEPARATOR + "Description2" + LINE_SEPARATOR + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR + "Copyright (C) 2010 - 2012 Tony2" + LINE_SEPARATOR + DEFAULT_SECTION_DELIMITER @@ -207,7 +217,7 @@ public void testBoxProcessTag() throws Exception { } @Test - public void testUnboxProcessTag() throws Exception { + void testUnboxProcessTag() throws Exception { String header; String boxedHeader; String unboxedHeader; @@ -216,17 +226,17 @@ public void testUnboxProcessTag() throws Exception { boxedHeader = transformer.boxProcessTag(header); unboxedHeader = transformer.unboxProcessTag(boxedHeader); - Assert.assertEquals(header, unboxedHeader); + assertEquals(header, unboxedHeader); header = transformer.toString(model2); boxedHeader = transformer.boxProcessTag(header); unboxedHeader = transformer.unboxProcessTag(boxedHeader); - Assert.assertEquals(header, unboxedHeader); + assertEquals(header, unboxedHeader); } @Test - public void testBoxComment() throws Exception { + void testBoxComment() throws Exception { String header; String boxedHeader; @@ -236,7 +246,7 @@ public void testBoxComment() throws Exception { String commentLinePrefix = " * "; String commentStartTag = "/*"; String commentEndTag = " */"; - Assert.assertEquals( + assertEquals( commentStartTag + LINE_SEPARATOR + commentLinePrefix + "Description" + LINE_SEPARATOR + commentLinePrefix + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR + commentLinePrefix @@ -247,7 +257,7 @@ public void testBoxComment() throws Exception { boxedHeader = transformer.boxComment(header, false); - Assert.assertEquals( + assertEquals( commentLinePrefix + "Description" + LINE_SEPARATOR + commentLinePrefix + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR + commentLinePrefix + "Copyright (C) 2010 Tony" + LINE_SEPARATOR + commentLinePrefix @@ -257,7 +267,7 @@ public void testBoxComment() throws Exception { header = transformer.toString(model2); boxedHeader = transformer.boxComment(header, true); - Assert.assertEquals( + assertEquals( commentStartTag + LINE_SEPARATOR + commentLinePrefix + "Description2" + LINE_SEPARATOR + commentLinePrefix + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR + commentLinePrefix @@ -268,7 +278,7 @@ public void testBoxComment() throws Exception { boxedHeader); boxedHeader = transformer.boxComment(header, false); - Assert.assertEquals( + assertEquals( commentLinePrefix + "Description2" + LINE_SEPARATOR + commentLinePrefix + DEFAULT_SECTION_DELIMITER + LINE_SEPARATOR + commentLinePrefix + "Copyright (C) 2010 - 2012 Tony2" + LINE_SEPARATOR + commentLinePrefix @@ -277,7 +287,7 @@ public void testBoxComment() throws Exception { } @Test - public void testUnboxComment() throws Exception { + void testUnboxComment() throws Exception { String header; String boxedHeader; String unboxedHeader; @@ -286,26 +296,26 @@ public void testUnboxComment() throws Exception { boxedHeader = transformer.boxComment(header, true); unboxedHeader = transformer.unboxComent(boxedHeader); - Assert.assertEquals(header, unboxedHeader); + assertEquals(header, unboxedHeader); header = transformer.toString(model2); boxedHeader = transformer.boxComment(header, true); unboxedHeader = transformer.unboxComent(boxedHeader); - Assert.assertEquals(header, unboxedHeader); + assertEquals(header, unboxedHeader); } @Test - public void testSetTrimHeaderLine() { - Assert.assertFalse(transformer.isTrimHeaderLine()); + void testSetTrimHeaderLine() { + assertFalse(transformer.isTrimHeaderLine()); transformer.setTrimHeaderLine(true); - Assert.assertTrue(transformer.isTrimHeaderLine()); + assertTrue(transformer.isTrimHeaderLine()); } - public static void assertEquals(FileHeader model, FileHeader model2) { - Assert.assertEquals(model.getDescription(), model2.getDescription()); - Assert.assertEquals(model.getCopyright(), model2.getCopyright()); - Assert.assertEquals(model.getLicense(), model2.getLicense()); + static void assertFileHeaderEquals(FileHeader model, FileHeader model2) { + assertEquals(model.getDescription(), model2.getDescription()); + assertEquals(model.getCopyright(), model2.getCopyright()); + assertEquals(model.getLicense(), model2.getLicense()); } } diff --git a/src/test/java/org/codehaus/mojo/license/header/transformer/JavaFileHeaderTransformerTest.java b/src/test/java/org/codehaus/mojo/license/header/transformer/JavaFileHeaderTransformerTest.java index 9e39e3500..c655acb20 100644 --- a/src/test/java/org/codehaus/mojo/license/header/transformer/JavaFileHeaderTransformerTest.java +++ b/src/test/java/org/codehaus/mojo/license/header/transformer/JavaFileHeaderTransformerTest.java @@ -22,8 +22,9 @@ * #L% */ -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests the {@link JavaFileHeaderTransformer}. @@ -31,7 +32,7 @@ * @author tchemit dev@tchemit.fr * @since 1.2 */ -public class JavaFileHeaderTransformerTest { +class JavaFileHeaderTransformerTest { private static final String PACKAGE = "package org.codehaus.mojo.license.header.transformer;"; @@ -42,7 +43,7 @@ public class JavaFileHeaderTransformerTest { private static final String LINE_SEPARATOR = ""; @Test - public void testAddHeader() { + void testAddHeader() { JavaFileHeaderTransformer transformer = new JavaFileHeaderTransformer(); transformer.setLineSeparator(LINE_SEPARATOR); transformer.setEmptyLineAfterHeader(false); @@ -52,12 +53,12 @@ public void testAddHeader() { transformer.setAddJavaLicenseAfterPackage(false); String result = transformer.addHeader(HEADER, content); - Assert.assertEquals(HEADER + content, result); + assertEquals(HEADER + content, result); transformer.setAddJavaLicenseAfterPackage(true); result = transformer.addHeader(HEADER, content); - Assert.assertEquals( + assertEquals( PACKAGE + FileHeaderTransformer.LINE_SEPARATOR + transformer.getLineSeparator() + HEADER + CONTENT, result); } diff --git a/src/test/java/org/codehaus/mojo/license/header/transformer/XmlFileHeaderTransformerTest.java b/src/test/java/org/codehaus/mojo/license/header/transformer/XmlFileHeaderTransformerTest.java index 951313aae..ad5b7e398 100644 --- a/src/test/java/org/codehaus/mojo/license/header/transformer/XmlFileHeaderTransformerTest.java +++ b/src/test/java/org/codehaus/mojo/license/header/transformer/XmlFileHeaderTransformerTest.java @@ -22,10 +22,11 @@ * #L% */ -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests the {@link XmlFileHeaderTransformer}. @@ -41,35 +42,35 @@ public class XmlFileHeaderTransformerTest { private static final String HEADER = "header"; - @Before - public void setUp() { + @BeforeEach + void setUp() { transformer = new XmlFileHeaderTransformer(); } - @After - public void tearDown() { + @AfterEach + void tearDown() { transformer = null; } @Test - public void testAddHeaderWithNoProlog() { + void testAddHeaderWithNoProlog() { String header = HEADER; String content = CONTENT; String result = transformer.addHeader(header, content); - Assert.assertEquals(header + content, result); + assertEquals(header + content, result); } @Test - public void testAddHeaderWithProlog() { + void testAddHeaderWithProlog() { String header = HEADER; String prolog = ""; String content = prolog + CONTENT; String result = transformer.addHeader(header, content); - Assert.assertEquals(prolog + FileHeaderTransformer.LINE_SEPARATOR + header + CONTENT, result); + assertEquals(prolog + FileHeaderTransformer.LINE_SEPARATOR + header + CONTENT, result); header = HEADER; content = " " + prolog + CONTENT; result = transformer.addHeader(header, content); - Assert.assertEquals(" " + prolog + FileHeaderTransformer.LINE_SEPARATOR + header + CONTENT, result); + assertEquals(" " + prolog + FileHeaderTransformer.LINE_SEPARATOR + header + CONTENT, result); } } diff --git a/src/test/java/org/codehaus/mojo/license/model/LicenseMapTest.java b/src/test/java/org/codehaus/mojo/license/model/LicenseMapTest.java index 1dc559c25..d24634d61 100644 --- a/src/test/java/org/codehaus/mojo/license/model/LicenseMapTest.java +++ b/src/test/java/org/codehaus/mojo/license/model/LicenseMapTest.java @@ -25,9 +25,9 @@ import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.project.MavenProject; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class LicenseMapTest { // licenses must be equal @@ -40,7 +40,7 @@ public class LicenseMapTest { // unit test for #361 @Test - public void licenseMapOrderByName() { + void licenseMapOrderByName() { LicenseMap licenseMap = new LicenseMap(); licenseMap.put(LICENSE_KEY, projectForArtifact(PROJECT_NAME, ARTIFACT_ID_FIRST)); licenseMap.put(LICENSE_KEY, projectForArtifact(PROJECT_NAME, ARTIFACT_ID_SECOND)); @@ -50,7 +50,7 @@ public void licenseMapOrderByName() { // it's a re-assurance test for default unsorted behavior @Test - public void licenseMapDefaultState() { + void licenseMapDefaultState() { LicenseMap licenseMap = new LicenseMap(); licenseMap.put(LICENSE_KEY, projectForArtifact(PROJECT_NAME, ARTIFACT_ID_FIRST)); licenseMap.put(LICENSE_KEY, projectForArtifact(PROJECT_NAME, ARTIFACT_ID_SECOND)); diff --git a/src/test/java/org/codehaus/mojo/license/model/LicenseRepositoryTest.java b/src/test/java/org/codehaus/mojo/license/model/LicenseRepositoryTest.java index 03c90a74a..7c5493d6a 100644 --- a/src/test/java/org/codehaus/mojo/license/model/LicenseRepositoryTest.java +++ b/src/test/java/org/codehaus/mojo/license/model/LicenseRepositoryTest.java @@ -25,9 +25,12 @@ import java.io.IOException; import java.net.URL; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@link LicenseRepository}. @@ -35,17 +38,17 @@ * @author tchemit dev@tchemit.fr * @since 1.0 */ -public class LicenseRepositoryTest { +class LicenseRepositoryTest { protected LicenseRepository repository; - @Before - public void setUp() { + @BeforeEach + void setUp() { repository = null; } @Test - public void testJarRepository() throws IOException { + void testJarRepository() throws IOException { repository = new LicenseRepository(); URL baseURL = getClass().getResource(LicenseStore.JAR_LICENSE_REPOSITORY); @@ -53,23 +56,23 @@ public void testJarRepository() throws IOException { repository.load(); License[] licenses = repository.getLicenses(); - Assert.assertNotNull(licenses); - Assert.assertEquals(LicenseStoreTest.DEFAULT_LICENSES.size(), licenses.length); + assertNotNull(licenses); + assertEquals(LicenseStoreTest.DEFAULT_LICENSES.size(), licenses.length); for (String licenseName : LicenseStoreTest.DEFAULT_LICENSES) { License license = repository.getLicense(licenseName); - Assert.assertNotNull(license); - Assert.assertNotNull(license.getHeaderURL()); - Assert.assertNotNull(license.getLicenseURL()); + assertNotNull(license); + assertNotNull(license.getHeaderURL()); + assertNotNull(license.getLicenseURL()); } for (String licenseName : repository.getLicenseNames()) { - Assert.assertTrue(LicenseStoreTest.DEFAULT_LICENSES.contains(licenseName)); + assertTrue(LicenseStoreTest.DEFAULT_LICENSES.contains(licenseName)); } } @Test - public void testUserRepository() throws IOException { + void testUserRepository() throws IOException { repository = new LicenseRepository(); URL baseURL = getClass().getResource("/newRepository"); @@ -77,18 +80,18 @@ public void testUserRepository() throws IOException { repository.load(); License[] licenses = repository.getLicenses(); - Assert.assertNotNull(licenses); - Assert.assertEquals(LicenseStoreTest.NEW_LICENSES.size(), licenses.length); + assertNotNull(licenses); + assertEquals(LicenseStoreTest.NEW_LICENSES.size(), licenses.length); for (String licenseName : LicenseStoreTest.NEW_LICENSES) { License license = repository.getLicense(licenseName); - Assert.assertNotNull(license); - Assert.assertNotNull(license.getHeaderURL()); - Assert.assertNotNull(license.getLicenseURL()); + assertNotNull(license); + assertNotNull(license.getHeaderURL()); + assertNotNull(license.getLicenseURL()); } for (String licenseName : repository.getLicenseNames()) { - Assert.assertTrue(LicenseStoreTest.NEW_LICENSES.contains(licenseName)); + assertTrue(LicenseStoreTest.NEW_LICENSES.contains(licenseName)); } } } diff --git a/src/test/java/org/codehaus/mojo/license/model/LicenseStoreTest.java b/src/test/java/org/codehaus/mojo/license/model/LicenseStoreTest.java index 2dad0c40c..232258c1d 100644 --- a/src/test/java/org/codehaus/mojo/license/model/LicenseStoreTest.java +++ b/src/test/java/org/codehaus/mojo/license/model/LicenseStoreTest.java @@ -27,9 +27,12 @@ import java.util.Arrays; import java.util.List; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@link LicenseStore}. @@ -37,9 +40,9 @@ * @author tchemit dev@tchemit.fr * @since 1.0 */ -public class LicenseStoreTest { +class LicenseStoreTest { - public static final List DEFAULT_LICENSES = Arrays.asList( + static final List DEFAULT_LICENSES = Arrays.asList( "agpl_v3", "apache_v2", "bsd_2", @@ -58,48 +61,48 @@ public class LicenseStoreTest { "lgpl_v3", "mit"); - public static final List NEW_LICENSES = Arrays.asList("license1", "license2", "license3", "license4"); + static final List NEW_LICENSES = Arrays.asList("license1", "license2", "license3", "license4"); protected LicenseStore store; - @Before - public void setUp() { + @BeforeEach + void setUp() { store = null; } @Test - public void testJarRepository() throws IOException { + void testJarRepository() throws IOException { store = new LicenseStore(); store.init(); List repositories = store.getRepositories(); - Assert.assertNotNull(repositories); - Assert.assertEquals(1, repositories.size()); + assertNotNull(repositories); + assertEquals(1, repositories.size()); LicenseRepository repository = repositories.get(0); License[] licenses1 = repository.getLicenses(); License[] licenses = store.getLicenses(); - Assert.assertNotNull(licenses); - Assert.assertNotNull(licenses1); - Assert.assertEquals(DEFAULT_LICENSES.size(), licenses.length); - Assert.assertEquals(DEFAULT_LICENSES.size(), licenses1.length); + assertNotNull(licenses); + assertNotNull(licenses1); + assertEquals(DEFAULT_LICENSES.size(), licenses.length); + assertEquals(DEFAULT_LICENSES.size(), licenses1.length); for (String licenseName : DEFAULT_LICENSES) { License license = repository.getLicense(licenseName); License license1 = store.getLicense(licenseName); - Assert.assertNotNull(license); - Assert.assertNotNull(license1); - Assert.assertEquals(license, license1); + assertNotNull(license); + assertNotNull(license1); + assertEquals(license, license1); } for (String licenseName : store.getLicenseNames()) { - Assert.assertTrue(DEFAULT_LICENSES.contains(licenseName)); + assertTrue(DEFAULT_LICENSES.contains(licenseName)); } } @Test - public void testUserRepository() throws IOException { + void testUserRepository() throws IOException { URL baseURL = getClass().getResource("/newRepository"); LicenseRepository jarRepository = new LicenseRepository(); @@ -109,27 +112,27 @@ public void testUserRepository() throws IOException { store.addRepository(jarRepository); store.init(); List repositories = store.getRepositories(); - Assert.assertNotNull(repositories); - Assert.assertEquals(1, repositories.size()); + assertNotNull(repositories); + assertEquals(1, repositories.size()); LicenseRepository repository = repositories.get(0); License[] licenses1 = repository.getLicenses(); License[] licenses = store.getLicenses(); - Assert.assertNotNull(licenses); - Assert.assertNotNull(licenses1); - Assert.assertEquals(licenses1.length, 4); - Assert.assertEquals(licenses1.length, licenses.length); + assertNotNull(licenses); + assertNotNull(licenses1); + assertEquals(licenses1.length, 4); + assertEquals(licenses1.length, licenses.length); for (String licenseName : NEW_LICENSES) { License license = repository.getLicense(licenseName); License license1 = store.getLicense(licenseName); - Assert.assertNotNull(license); - Assert.assertNotNull(license1); - Assert.assertEquals(license, license1); + assertNotNull(license); + assertNotNull(license1); + assertEquals(license, license1); } for (String licenseName : store.getLicenseNames()) { - Assert.assertTrue(NEW_LICENSES.contains(licenseName)); + assertTrue(NEW_LICENSES.contains(licenseName)); } } } diff --git a/src/test/java/org/codehaus/mojo/license/spdx/SpdxLicenseListDataTest.java b/src/test/java/org/codehaus/mojo/license/spdx/SpdxLicenseListDataTest.java index 39d942c75..9d8158bc7 100644 --- a/src/test/java/org/codehaus/mojo/license/spdx/SpdxLicenseListDataTest.java +++ b/src/test/java/org/codehaus/mojo/license/spdx/SpdxLicenseListDataTest.java @@ -22,15 +22,19 @@ * #L% */ +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * A class generated by GenerateSpdxLicenseList.groovy from * * https://raw.githubusercontent.com/spdx/license-list-data/v3.5/json/licenses.json */ -public class SpdxLicenseListDataTest { - @org.junit.Test - public void getInstance() { +class SpdxLicenseListDataTest { + @Test + void getInstance() { SpdxLicenseList list = SpdxLicenseList.getLatest(); - org.junit.Assert.assertEquals(388, list.getLicenses().size()); + assertEquals(388, list.getLicenses().size()); } } diff --git a/src/test/java/org/codehaus/mojo/license/spdx/SpdxLicenseListTest.java b/src/test/java/org/codehaus/mojo/license/spdx/SpdxLicenseListTest.java index 5b285bb89..831b3eb65 100644 --- a/src/test/java/org/codehaus/mojo/license/spdx/SpdxLicenseListTest.java +++ b/src/test/java/org/codehaus/mojo/license/spdx/SpdxLicenseListTest.java @@ -4,42 +4,44 @@ import org.codehaus.mojo.license.spdx.SpdxLicenseInfo.Attachments.UrlInfo; import org.codehaus.mojo.license.utils.FileUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class SpdxLicenseListTest { +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class SpdxLicenseListTest { @Test - public void mimeTypes() { + void mimeTypes() { for (SpdxLicenseInfo lic : SpdxLicenseList.getLatest().getLicenses().values()) { for (UrlInfo urlInfo : lic.getAttachments().getUrlInfos().values()) { if (urlInfo.getMimeType() != null) { - Assert.assertNotNull(FileUtil.toExtension(urlInfo.getMimeType(), true)); + assertNotNull(FileUtil.toExtension(urlInfo.getMimeType(), true)); } } } } @Test - public void extraAliases() { + void extraAliases() { Map lics = SpdxLicenseList.getLatest().getLicenses(); Map urlInfos = lics.get("Apache-2.0").getAttachments().getUrlInfos(); - Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/apache2.0")); - Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/apache2.0.php")); - Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/apache2.0.html")); + assertTrue(urlInfos.containsKey("https://opensource.org/licenses/apache2.0")); + assertTrue(urlInfos.containsKey("https://opensource.org/licenses/apache2.0.php")); + assertTrue(urlInfos.containsKey("https://opensource.org/licenses/apache2.0.html")); urlInfos = lics.get("BSD-2-Clause").getAttachments().getUrlInfos(); - Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/bsd-license")); - Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/bsd-license.php")); - Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/bsd-license.html")); + assertTrue(urlInfos.containsKey("https://opensource.org/licenses/bsd-license")); + assertTrue(urlInfos.containsKey("https://opensource.org/licenses/bsd-license.php")); + assertTrue(urlInfos.containsKey("https://opensource.org/licenses/bsd-license.html")); urlInfos = lics.get("CDDL-1.0").getAttachments().getUrlInfos(); - Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/cddl1")); - Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/cddl1.php")); - Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/cddl1.html")); + assertTrue(urlInfos.containsKey("https://opensource.org/licenses/cddl1")); + assertTrue(urlInfos.containsKey("https://opensource.org/licenses/cddl1.php")); + assertTrue(urlInfos.containsKey("https://opensource.org/licenses/cddl1.html")); urlInfos = lics.get("MIT").getAttachments().getUrlInfos(); - Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/mit-license")); - Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/mit-license.php")); - Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/mit-license.html")); + assertTrue(urlInfos.containsKey("https://opensource.org/licenses/mit-license")); + assertTrue(urlInfos.containsKey("https://opensource.org/licenses/mit-license.php")); + assertTrue(urlInfos.containsKey("https://opensource.org/licenses/mit-license.html")); } } diff --git a/src/test/java/org/codehaus/mojo/license/utils/UrlRequesterTest.java b/src/test/java/org/codehaus/mojo/license/utils/UrlRequesterTest.java index e3b516bb1..f39b7073c 100644 --- a/src/test/java/org/codehaus/mojo/license/utils/UrlRequesterTest.java +++ b/src/test/java/org/codehaus/mojo/license/utils/UrlRequesterTest.java @@ -2,43 +2,43 @@ import java.io.File; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; import org.codehaus.plexus.util.FileUtils; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; -public class UrlRequesterTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; - private static final String RESOURCE_NAME = "org/codehaus/mojo/license/utils/licenses.properties"; +class UrlRequesterTest { - @Rule - public TemporaryFolder fileRule = new TemporaryFolder(); + private static final String RESOURCE_NAME = "org/codehaus/mojo/license/utils/licenses.properties"; @Test - public void testClasspathRequester() throws Exception { + void testClasspathRequester() throws Exception { String licenseContent = UrlRequester.getFromUrl("classpath:" + RESOURCE_NAME); - Assert.assertEquals("license1=This is mine!", licenseContent.trim()); + assertEquals("license1=This is mine!", licenseContent.trim()); } @Test - public void testGenericRequester() throws Exception { + void testGenericRequester(@TempDir Path tempDir) throws Exception { URL res = getClass().getClassLoader().getResource(RESOURCE_NAME); - File testFile = fileRule.newFile(); + File testFile = Files.createTempFile(tempDir, "requester", "test").toFile(); FileUtils.copyURLToFile(res, testFile); String licenseContent = UrlRequester.getFromUrl(testFile.toURI().toURL().toString()); - Assert.assertEquals("license1=This is mine!", licenseContent.trim()); + assertEquals("license1=This is mine!", licenseContent.trim()); } @Test - public void testClasspathIsAValidUrl() { - Assert.assertTrue("classpath protocol not registered", UrlRequester.isStringUrl("classpath:" + RESOURCE_NAME)); + void testClasspathIsAValidUrl() { + assertTrue(UrlRequester.isStringUrl("classpath:" + RESOURCE_NAME), "classpath protocol not registered"); } @Test - public void testClasspathIsAExternalUrl() { - Assert.assertTrue("classpath protocol as external", UrlRequester.isExternalUrl("classpath:" + RESOURCE_NAME)); + void testClasspathIsAExternalUrl() { + assertTrue(UrlRequester.isExternalUrl("classpath:" + RESOURCE_NAME), "classpath protocol as external"); } }