Skip to content

Commit

Permalink
Move to jUnit5 (#608)
Browse files Browse the repository at this point in the history
* Move to jUnit5

* Drop public classifier from tests

---------

Co-authored-by: Slawomir Jaranowski <s.jaranowski@gmail.com>
  • Loading branch information
vitalijr2 and slawekjaranowski authored Nov 17, 2024
1 parent 922e838 commit 21b2741
Show file tree
Hide file tree
Showing 16 changed files with 412 additions and 378 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

Expand Down
38 changes: 19 additions & 19 deletions src/test/java/org/codehaus/mojo/license/LicenseMojoUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,60 @@

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;
private File basedir = new File("");
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 {
Expand All @@ -68,7 +68,7 @@ public void testPrepareThirdPartyOverrideUrlBothOverrides() {
}

@Test
public void testPrepareThirdPartyOverrideUrlNonExistingDeprecatedFile() {
void testPrepareThirdPartyOverrideUrlNonExistingDeprecatedFile() {
deprecatedFile = new File("foo");
String actual = runTestAndJoinResults();
assertEquals(
Expand All @@ -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(
Expand All @@ -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);
Expand All @@ -102,7 +102,7 @@ public void testPrepareThirdPartyOverrideClasspathResource() {
}

@Test
public void testPrepareThirdPartyOverrideInvalidUrl() {
void testPrepareThirdPartyOverrideInvalidUrl() {
url = "foo://localhost/bar";
String actual = runTestAndJoinResults();
assertEquals(
Expand All @@ -114,7 +114,7 @@ public void testPrepareThirdPartyOverrideInvalidUrl() {
}

@Test
public void testPrepareThirdPartyOverridePreventReinit() {
void testPrepareThirdPartyOverridePreventReinit() {
resolvedUrl = "classpath:overrides.properties";
deprecatedFile = new File("foo");
url = "classpath:bar";
Expand Down
174 changes: 88 additions & 86 deletions src/test/java/org/codehaus/mojo/license/api/ArtifactFiltersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -33,135 +35,135 @@ 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:.*")
.excludeGa("org\\.group1:artifact3")
.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()) {
Expand All @@ -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));
}
}
Loading

0 comments on commit 21b2741

Please sign in to comment.