Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JUnit5 in versions-commons, versions-enforcer #1094

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
<modelloNamespaceRuleVersion>2.1.0</modelloNamespaceRuleVersion>
<modelloNamespaceReportVersion>2.0.0</modelloNamespaceReportVersion>
<byteBuddyVersion>1.14.17</byteBuddyVersion>
<!-- use the same version as in Maven core -->
<mavenResolverVersion>1.4.1</mavenResolverVersion>

<scmpublish.content>${project.build.directory}/staging/versions</scmpublish.content>
<!-- execute ITS in parallel by default -->
<invoker.parallelThreads>0.75C</invoker.parallelThreads>
Expand Down Expand Up @@ -185,14 +188,13 @@
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
<!-- use the same version as in Maven core -->
<version>1.4.1</version>
<version>${mavenResolverVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
<version>1.4.1</version>
<version>${mavenResolverVersion}</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -295,6 +297,11 @@
<artifactId>mockito-inline</artifactId>
<version>${mockitoVersion}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockitoVersion}</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
Expand Down
35 changes: 3 additions & 32 deletions versions-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,11 @@
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>

<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -115,19 +98,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -145,12 +122,6 @@
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<!-- Required by Maven Testing Harness -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected ArtifactVersion getHighestLowerBound(ArtifactVersion lowerBoundVersion
* or {@link Optional#empty()} if there are no ranges
*/
protected Optional<Restriction> getSelectedRestriction(ArtifactVersion selectedVersion) {
assert selectedVersion != null;
Objects.requireNonNull(selectedVersion);
return Optional.ofNullable(getCurrentVersionRange())
.map(VersionRange::getRestrictions)
.flatMap(r -> r.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public class DefaultVersionsHelper implements VersionsHelper {

private static final int LOOKUP_PARALLEL_THREADS = 5;

// for testing purpose
RuleSet getRuleSet() {
return ruleSet;
}

/**
* The artifact comparison rules to use.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.ordering.MavenVersionComparator;
import org.codehaus.mojo.versions.ordering.VersionComparator;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.codehaus.mojo.versions.api.Segment.MAJOR;
import static org.codehaus.mojo.versions.utils.ArtifactVersionUtils.version;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* Unit tests for {@link AbstractVersionDetails}
*/
public class AbstractVersionDetailsTest {
class AbstractVersionDetailsTest {

private AbstractVersionDetails instance;

@Before
public void setUp() {
@BeforeEach
void setUp() {
instance = new AbstractVersionDetails() {
@Override
public VersionComparator getVersionComparator() {
Expand All @@ -55,7 +55,7 @@ public ArtifactVersion[] getVersions(boolean includeSnapshots) {
}

@Test
public void testRestrictionForUnchangedSegmentWithSimpleVersion() throws InvalidSegmentException {
void testRestrictionForUnchangedSegmentWithSimpleVersion() throws InvalidSegmentException {
assertThat(
instance.restrictionForUnchangedSegment(version("1.0.0"), of(MAJOR), false)
.containsVersion(version("1.0.0")),
Expand All @@ -75,7 +75,7 @@ public void testRestrictionForUnchangedSegmentWithSimpleVersion() throws Invalid
}

@Test
public void testRestrictionForUnchangedSegmentWithRange()
void testRestrictionForUnchangedSegmentWithRange()
throws InvalidSegmentException, InvalidVersionSpecificationException {
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("(0.0.1, 1.0.0]"));
assertThat(
Expand All @@ -97,7 +97,7 @@ public void testRestrictionForUnchangedSegmentWithRange()
}

@Test
public void testRestrictionForUnchangedSegmentWithTwoRanges()
void testRestrictionForUnchangedSegmentWithTwoRanges()
throws InvalidSegmentException, InvalidVersionSpecificationException {
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("(0.0.1, 1.0.0],(1.0.0,2.0.0]"));
assertThat(
Expand All @@ -119,7 +119,7 @@ public void testRestrictionForUnchangedSegmentWithTwoRanges()
}

@Test
public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges1()
void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges1()
throws InvalidSegmentException, InvalidVersionSpecificationException {
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("(0.0.1, 1.0.0),(1.0.0,2.0.0]"));
assertThat(
Expand All @@ -129,7 +129,7 @@ public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges1()
}

@Test
public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges2()
void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges2()
throws InvalidSegmentException, InvalidVersionSpecificationException {
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("(0.0.1, 1.0.0),(1.0.0,2.0.0]"));
assertThat(
Expand All @@ -139,7 +139,7 @@ public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges2()
}

@Test
public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges3()
void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges3()
throws InvalidSegmentException, InvalidVersionSpecificationException {
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("(0.0.1, 1.0.0),(1.0.0,2.0.0]"));
assertThat(
Expand All @@ -149,7 +149,7 @@ public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges3()
}

@Test
public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges4()
void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges4()
throws InvalidSegmentException, InvalidVersionSpecificationException {
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("(0.0.1, 1.0.0),(1.0.0,2.0.0]"));
assertThat(
Expand All @@ -159,7 +159,7 @@ public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges4()
}

@Test
public void testRestrictionForUnchangedSegmentWithoutVersionInformation()
void testRestrictionForUnchangedSegmentWithoutVersionInformation()
throws InvalidSegmentException, InvalidVersionSpecificationException {
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("[,0]"));
assertThat(
Expand All @@ -168,13 +168,8 @@ public void testRestrictionForUnchangedSegmentWithoutVersionInformation()
}

@Test
public void testGetSelectedRestrictionForNoVersion()
throws InvalidVersionSpecificationException, InvalidSegmentException {
void testGetSelectedRestrictionForNoVersion() throws InvalidVersionSpecificationException {
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("[,0]"));
try {
instance.getSelectedRestriction(null);
fail("Expected a NullPointerException to be thrown or assertions are not enabled.");
} catch (AssertionError ignored) {
}
assertThrows(NullPointerException.class, () -> instance.getSelectedRestriction(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.codehaus.mojo.versions.ordering.MavenVersionComparator;
import org.codehaus.mojo.versions.ordering.MercuryVersionComparator;
import org.codehaus.mojo.versions.ordering.VersionComparator;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static java.util.Optional.of;
import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL;
Expand All @@ -47,11 +47,11 @@
import static org.hamcrest.Matchers.hasToString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

public class ArtifactVersionsTest {
class ArtifactVersionsTest {

private void test4DigitVersion(VersionComparator comparator) throws InvalidVersionSpecificationException {
ArtifactVersions instance = new ArtifactVersions(
Expand Down Expand Up @@ -101,17 +101,17 @@ private void test4DigitVersion(VersionComparator comparator) throws InvalidVersi
}

@Test
public void test4DigitVersionsMercury() throws Exception {
void test4DigitVersionsMercury() throws Exception {
test4DigitVersion(new MercuryVersionComparator());
}

@Test
public void test4DigitVersionsMaven() throws Exception {
void test4DigitVersionsMaven() throws Exception {
test4DigitVersion(new MavenVersionComparator());
}

@Test
public void testIsEmpty() throws Exception {
void testIsEmpty() throws Exception {
ArtifactVersions instance = new ArtifactVersions(
new DefaultArtifact(
"group",
Expand All @@ -128,7 +128,7 @@ public void testIsEmpty() throws Exception {
}

@Test
public void testSmokes() throws Exception {
void testSmokes() throws Exception {
ArtifactVersions instance = new ArtifactVersions(
new DefaultArtifact(
"group",
Expand All @@ -155,7 +155,7 @@ public void testSmokes() throws Exception {
}

@Test
public void testReportLabels() {
void testReportLabels() {
ArtifactVersions instance = new ArtifactVersions(
new DefaultArtifact("default-group", "dummy-api", "1.1", "foo", "bar", "jar", null),
Arrays.asList(versions(
Expand Down Expand Up @@ -188,7 +188,7 @@ public void testReportLabels() {
}

@Test
public void testGetNewerVersionsWithSnapshot() throws InvalidSegmentException {
void testGetNewerVersionsWithSnapshot() throws InvalidSegmentException {
ArtifactVersions instance = new ArtifactVersions(
new DefaultArtifact("default-group", "dummy-api", "1.0.0-SNAPSHOT", "foo", "bar", "jar", null),
Arrays.asList(versions("1.0.0-SNAPSHOT", "1.0.0")),
Expand All @@ -207,7 +207,7 @@ private static ArtifactVersions createInstance(ArtifactVersion[] versions) {
}

@Test
public void testAllVersionsForIgnoreScopeSubIncremental() {
void testAllVersionsForIgnoreScopeSubIncremental() {
ArtifactVersions instance = createInstance(versions("1.0.0", "1.0.0-1", "1.0.1"));
ArtifactVersion[] filteredVersions = instance.getVersions(
instance.restrictionForIgnoreScope(instance.getCurrentVersion(), of(SUBINCREMENTAL)), false);
Expand All @@ -216,7 +216,7 @@ public void testAllVersionsForIgnoreScopeSubIncremental() {
}

@Test
public void testAllVersionsForIgnoreScopeIncremental() {
void testAllVersionsForIgnoreScopeIncremental() {
ArtifactVersions instance = createInstance(versions("1.0.0", "1.0.0-1", "1.0.1", "1.1.0"));
ArtifactVersion[] filteredVersions = instance.getVersions(
instance.restrictionForIgnoreScope(instance.getCurrentVersion(), of(INCREMENTAL)), false);
Expand All @@ -225,7 +225,7 @@ public void testAllVersionsForIgnoreScopeIncremental() {
}

@Test
public void testAllVersionsForIgnoreScopeMinor() {
void testAllVersionsForIgnoreScopeMinor() {
ArtifactVersions instance = createInstance(versions("1.0.0", "1.0.0-1", "1.0.1", "1.1.0", "2.0.0"));
ArtifactVersion[] filteredVersions = instance.getVersions(
instance.restrictionForIgnoreScope(instance.getCurrentVersion(), of(MINOR)), false);
Expand All @@ -234,15 +234,15 @@ public void testAllVersionsForIgnoreScopeMinor() {
}

@Test
public void testAllVersionsForIgnoreScopeMajor() {
void testAllVersionsForIgnoreScopeMajor() {
ArtifactVersions instance = createInstance(versions("1.0.0", "1.0.0-1", "1.0.1", "1.1.0", "2.0.0"));
ArtifactVersion[] filteredVersions = instance.getVersions(
instance.restrictionForIgnoreScope(instance.getCurrentVersion(), of(MAJOR)), false);
assertThat(filteredVersions, arrayWithSize(0));
}

@Test
public void testGetReportNewestUpdateWithOnlyMajorUpdate() {
void testGetReportNewestUpdateWithOnlyMajorUpdate() {
ArtifactVersions instance = createInstance(versions("1.0.0", "2.0.0"));
assertThat(instance.getReportNewestUpdate(Optional.empty(), true).toString(), is("2.0.0"));
assertThat(instance.getReportNewestUpdate(of(MAJOR), true), hasToString("2.0.0"));
Expand All @@ -252,7 +252,7 @@ public void testGetReportNewestUpdateWithOnlyMajorUpdate() {
}

@Test
public void testGetReportNewestUpdateWithMinorAndMajor() {
void testGetReportNewestUpdateWithMinorAndMajor() {
ArtifactVersions instance = createInstance(versions("1.0.0", "1.1.0", "2.0.0"));
assertThat(instance.getReportNewestUpdate(Optional.empty(), true).toString(), is("2.0.0"));
assertThat(instance.getReportNewestUpdate(of(MAJOR), true), hasToString("2.0.0"));
Expand All @@ -262,7 +262,7 @@ public void testGetReportNewestUpdateWithMinorAndMajor() {
}

@Test
public void testGetReportNewestUpdateWithIncrementalAndMajor() {
void testGetReportNewestUpdateWithIncrementalAndMajor() {
ArtifactVersions instance = createInstance(versions("1.0.0", "1.0.1", "2.0.0"));
assertThat(instance.getReportNewestUpdate(Optional.empty(), true).toString(), is("2.0.0"));
assertThat(instance.getReportNewestUpdate(of(MAJOR), true), hasToString("2.0.0"));
Expand All @@ -272,7 +272,7 @@ public void testGetReportNewestUpdateWithIncrementalAndMajor() {
}

@Test
public void testGetNewestVersionWithLesserSegment() throws InvalidSegmentException {
void testGetNewestVersionWithLesserSegment() throws InvalidSegmentException {
ArtifactVersions instance = createInstance(versions("1.0.0-1"));
assertThat(instance.getNewestVersion("1.0.0", of(MAJOR), false, false).get(), hasToString("1.0.0-1"));
assertThat(instance.getNewestVersion("1.0.0", of(MINOR), false, false).get(), hasToString("1.0.0-1"));
Expand All @@ -283,7 +283,7 @@ public void testGetNewestVersionWithLesserSegment() throws InvalidSegmentExcepti
}

@Test
public void testGetNewestVersionWithLesserSegmentWithSnapshots() throws InvalidSegmentException {
void testGetNewestVersionWithLesserSegmentWithSnapshots() throws InvalidSegmentException {
ArtifactVersions instance = createInstance(versions("1.0.0-1-SNAPSHOT"));
assertThat(instance.getNewestVersion("1.0.0", of(MAJOR), true, false).get(), hasToString("1.0.0-1-SNAPSHOT"));
assertThat(instance.getNewestVersion("1.0.0", of(MINOR), true, false).get(), hasToString("1.0.0-1-SNAPSHOT"));
Expand Down
Loading