From ac2fb3f9f6c108d7d30ba56d4e67da9a6527cbee Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Fri, 21 Jun 2024 22:18:32 +0200 Subject: [PATCH] Use JUnit5 in version-commons, versions-enforcer --- pom.xml | 13 ++- versions-common/pom.xml | 35 +------- .../versions/api/AbstractVersionDetails.java | 2 +- .../versions/api/DefaultVersionsHelper.java | 5 ++ .../api/AbstractVersionDetailsTest.java | 37 ++++---- .../versions/api/ArtifactVersionsTest.java | 40 ++++----- .../api/DefaultVersionsHelperTest.java | 88 +++++++++++-------- .../mojo/versions/api/PomHelperTest.java | 75 ++++++++-------- .../ordering/BoundArtifactVersionTest.java | 20 ++--- .../ordering/MavenVersionComparatorTest.java | 16 ++-- .../MercuryVersionComparatorTest.java | 10 +-- .../NumericVersionComparatorTest.java | 20 ++--- .../ordering/VersionComparatorTestBase.java | 22 ++--- .../recording/ChangeRecorderXMLTest.java | 26 +++--- .../ModifiedPomXMLEventReaderTest.java | 33 +++---- .../utils/CoreExtensionUtilsTest.java | 8 +- .../PropertiesVersionsFileReaderTest.java | 14 +-- .../mojo/versions/utils/SegmentUtilsTest.java | 12 +-- .../mojo/versions/utils/VersionStub.java | 66 -------------- versions-enforcer/pom.xml | 32 ++----- .../enforcer/MaxDependencyUpdatesTest.java | 60 ++++++------- .../it/it-set-issue-505/invoker.properties | 2 - .../it-set-issue-505/moduleA/moduleB/pom.xml | 13 --- .../src/it/it-set-issue-505/moduleA/pom.xml | 18 ---- .../src/it/it-set-issue-505/pom.xml | 13 --- .../src/it/it-set-issue-505/verify.groovy | 3 - versions-test/pom.xml | 4 + .../mojo/versions/utils/MockUtils.java | 12 ++- .../mojo/versions/utils/VersionStub.java | 66 -------------- 29 files changed, 282 insertions(+), 483 deletions(-) delete mode 100644 versions-common/src/test/java/org/codehaus/mojo/versions/utils/VersionStub.java delete mode 100644 versions-maven-plugin/src/it/it-set-issue-505/invoker.properties delete mode 100644 versions-maven-plugin/src/it/it-set-issue-505/moduleA/moduleB/pom.xml delete mode 100644 versions-maven-plugin/src/it/it-set-issue-505/moduleA/pom.xml delete mode 100644 versions-maven-plugin/src/it/it-set-issue-505/pom.xml delete mode 100644 versions-maven-plugin/src/it/it-set-issue-505/verify.groovy delete mode 100644 versions-test/src/main/java/org/codehaus/mojo/versions/utils/VersionStub.java diff --git a/pom.xml b/pom.xml index d2f9c04b4..c88272744 100644 --- a/pom.xml +++ b/pom.xml @@ -130,6 +130,9 @@ 2.1.0 2.0.0 1.14.17 + + 1.4.1 + ${project.build.directory}/staging/versions 0.75C @@ -185,14 +188,13 @@ org.apache.maven.resolver maven-resolver-api - - 1.4.1 + ${mavenResolverVersion} provided org.apache.maven.resolver maven-resolver-util - 1.4.1 + ${mavenResolverVersion} @@ -295,6 +297,11 @@ mockito-inline ${mockitoVersion} + + org.mockito + mockito-junit-jupiter + ${mockitoVersion} + org.hamcrest hamcrest diff --git a/versions-common/pom.xml b/versions-common/pom.xml index 7a14c174e..44c22ea7c 100644 --- a/versions-common/pom.xml +++ b/versions-common/pom.xml @@ -82,28 +82,11 @@ javax.inject javax.inject - org.apache.maven.resolver maven-resolver-util test - - org.apache.maven.plugin-testing - maven-plugin-testing-harness - test - - - junit - junit - test - - - org.hamcrest - hamcrest-core - - - org.junit.jupiter junit-jupiter-api @@ -115,19 +98,13 @@ test - org.junit.vintage - junit-vintage-engine + org.mockito + mockito-core test - - - org.hamcrest - hamcrest-core - - org.mockito - mockito-core + mockito-junit-jupiter test @@ -145,12 +122,6 @@ commons-io test - - - org.apache.maven - maven-compat - test - diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java index 0b49b2ef6..596db4518 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java @@ -92,7 +92,7 @@ protected ArtifactVersion getHighestLowerBound(ArtifactVersion lowerBoundVersion * or {@link Optional#empty()} if there are no ranges */ protected Optional getSelectedRestriction(ArtifactVersion selectedVersion) { - assert selectedVersion != null; + Objects.requireNonNull(selectedVersion); return Optional.ofNullable(getCurrentVersionRange()) .map(VersionRange::getRestrictions) .flatMap(r -> r.stream() diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java index 382348ebb..7d5c50941 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java @@ -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. * diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/api/AbstractVersionDetailsTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/api/AbstractVersionDetailsTest.java index d2308eda8..618f575fa 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/api/AbstractVersionDetailsTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/api/AbstractVersionDetailsTest.java @@ -21,8 +21,8 @@ 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; @@ -30,17 +30,17 @@ 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() { @@ -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")), @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -159,7 +159,7 @@ public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges4() } @Test - public void testRestrictionForUnchangedSegmentWithoutVersionInformation() + void testRestrictionForUnchangedSegmentWithoutVersionInformation() throws InvalidSegmentException, InvalidVersionSpecificationException { instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("[,0]")); assertThat( @@ -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)); } } diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/api/ArtifactVersionsTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/api/ArtifactVersionsTest.java index 94040a167..8dd5eaeb5 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/api/ArtifactVersionsTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/api/ArtifactVersionsTest.java @@ -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; @@ -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( @@ -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", @@ -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", @@ -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( @@ -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")), @@ -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); @@ -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); @@ -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); @@ -234,7 +234,7 @@ 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); @@ -242,7 +242,7 @@ public void testAllVersionsForIgnoreScopeMajor() { } @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")); @@ -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")); @@ -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")); @@ -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")); @@ -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")); diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/api/DefaultVersionsHelperTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/api/DefaultVersionsHelperTest.java index 8f30de006..fe230eda2 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/api/DefaultVersionsHelperTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/api/DefaultVersionsHelperTest.java @@ -31,14 +31,13 @@ import java.util.stream.Collectors; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.logging.SystemStreamLog; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub; import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.wagon.ConnectionException; @@ -53,15 +52,16 @@ import org.codehaus.mojo.versions.model.Rule; import org.codehaus.mojo.versions.model.RuleSet; import org.codehaus.mojo.versions.ordering.VersionComparators; -import org.codehaus.mojo.versions.utils.VersionStub; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.repository.RepositoryPolicy; import org.eclipse.aether.resolution.VersionRangeRequest; import org.eclipse.aether.resolution.VersionRangeResult; +import org.eclipse.aether.util.version.GenericVersionScheme; +import org.eclipse.aether.version.InvalidVersionSpecificationException; import org.eclipse.aether.version.Version; import org.hamcrest.CoreMatchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; import static java.util.Collections.emptyList; @@ -74,6 +74,9 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.core.IsIterableContaining.hasItems; +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.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.any; import static org.mockito.Mockito.doAnswer; @@ -84,7 +87,7 @@ /** * Test {@link DefaultVersionsHelper} */ -public class DefaultVersionsHelperTest extends AbstractMojoTestCase { +class DefaultVersionsHelperTest { @Test public void testPerRuleVersionsIgnored() throws Exception { final org.eclipse.aether.RepositorySystem repositorySystem = mock(org.eclipse.aether.RepositorySystem.class); @@ -92,15 +95,15 @@ public void testPerRuleVersionsIgnored() throws Exception { when(artifact.getGroupId()).thenReturn("com.mycompany.maven"); when(artifact.getArtifactId()).thenReturn("artifact-one"); when(artifact.getType()).thenReturn("jar"); - when(artifact.getArtifactHandler()).thenReturn(new DefaultArtifactHandlerStub("default")); + when(artifact.getArtifactHandler()).thenReturn(new DefaultArtifactHandler("default")); when(repositorySystem.resolveVersionRange(any(), any(VersionRangeRequest.class))) .then(i -> new VersionRangeResult(i.getArgument(1)) .setVersions(Arrays.asList( - new VersionStub("one"), - new VersionStub("two"), - new VersionStub("three"), - new VersionStub("1.200"), - new VersionStub("illegalVersion")))); + parseVersion("one"), + parseVersion("two"), + parseVersion("three"), + parseVersion("1.200"), + parseVersion("illegalVersion")))); VersionsHelper helper = createHelper(repositorySystem); @@ -121,19 +124,19 @@ public void testGlobalRuleVersionsIgnored() throws Exception { when(artifact.getGroupId()).thenReturn("other.company"); when(artifact.getArtifactId()).thenReturn("artifact-two"); when(artifact.getType()).thenReturn("jar"); - when(artifact.getArtifactHandler()).thenReturn(new DefaultArtifactHandlerStub("default")); + when(artifact.getArtifactHandler()).thenReturn(new DefaultArtifactHandler("default")); final List artifactVersions = new ArrayList<>(); - final Version one = new VersionStub("one"); - final Version two = new VersionStub("two"); - final Version three = new VersionStub("three"); + final Version one = parseVersion("one"); + final Version two = parseVersion("two"); + final Version three = parseVersion("three"); artifactVersions.add(one); artifactVersions.add(two); - artifactVersions.add(new VersionStub("three-alpha")); - artifactVersions.add(new VersionStub("three-beta")); + artifactVersions.add(parseVersion("three-alpha")); + artifactVersions.add(parseVersion("three-beta")); artifactVersions.add(three); - final Version illegal = new VersionStub("illegalVersion"); + final Version illegal = parseVersion("illegalVersion"); artifactVersions.add(illegal); when(repositorySystem.resolveVersionRange(any(), any(VersionRangeRequest.class))) @@ -145,7 +148,7 @@ public void testGlobalRuleVersionsIgnored() throws Exception { final List actual = Arrays.stream(versions.getVersions(true)) .map(ArtifactVersion::toString) - .map(VersionStub::new) + .map(DefaultVersionsHelperTest::parseVersion) .collect(Collectors.toList()); assertEquals(4, actual.size()); @@ -166,21 +169,21 @@ public void testRuleSets() throws Exception { VersionsHelper helper = createHelper(); assertEquals( - "no match gives default", VersionComparators.getVersionComparator("maven"), - helper.getVersionComparator("net.foo", "bar")); + helper.getVersionComparator("net.foo", "bar"), + "no match gives default"); assertEquals( - "matches wildcard", VersionComparators.getVersionComparator("mercury"), - helper.getVersionComparator("org.apache.maven", "plugins")); + helper.getVersionComparator("org.apache.maven", "plugins"), + "matches wildcard"); assertEquals( - "exact match wins over initial match", VersionComparators.getVersionComparator("mercury"), - helper.getVersionComparator("com.mycompany.custom.maven", "plugins")); + helper.getVersionComparator("com.mycompany.custom.maven", "plugins"), + "exact match wins over initial match"); assertEquals( - "non-wildcard prefix wins over wildcard prefix match", VersionComparators.getVersionComparator("maven"), - helper.getVersionComparator("com.mycompany.maven.plugins", "plugins")); + helper.getVersionComparator("com.mycompany.maven.plugins", "plugins"), + "non-wildcard prefix wins over wildcard prefix match"); assertEquals( VersionComparators.getVersionComparator("maven"), helper.getVersionComparator("com.mycompany.maven", "new-maven-plugin")); @@ -190,7 +193,7 @@ public void testRuleSets() throws Exception { } @Test - public void testMVERSIONS159ExcludedAndNotIncluded() throws Exception { + void testMVERSIONS159ExcludedAndNotIncluded() throws Exception { VersionsHelper helper = createHelper(); MavenProject project = null; @@ -209,14 +212,14 @@ public void testMVERSIONS159ExcludedAndNotIncluded() throws Exception { } @Test - public void testIsClasspathUriDetectsClassPathProtocol() throws Exception { + void testIsClasspathUriDetectsClassPathProtocol() throws Exception { String uri = "classpath:/p/a/c/k/a/g/e/resource.res"; assertThat(DefaultVersionsHelper.isClasspathUri(uri), CoreMatchers.is(true)); } @Test - public void testIsClasspathUriDetectsThatItIsDifferentProtocol() throws Exception { + void testIsClasspathUriDetectsThatItIsDifferentProtocol() throws Exception { String uri = "http://10.10.10.10/p/a/c/k/a/g/e/resource.res"; assertThat(DefaultVersionsHelper.isClasspathUri(uri), CoreMatchers.is(false)); @@ -258,7 +261,7 @@ private DefaultVersionsHelper createHelper(org.eclipse.aether.RepositorySystem a when(mavenSession.getRepositorySession()).thenReturn(new DefaultRepositorySystemSession()); return new DefaultVersionsHelper.Builder() - .withRepositorySystem(lookup(RepositorySystem.class)) + .withRepositorySystem(mock(RepositorySystem.class)) .withAetherRepositorySystem(aetherRepositorySystem) .withWagonMap(singletonMap("file", mockFileWagon(new URI(rulesUri)))) .withServerId("") @@ -270,13 +273,12 @@ private DefaultVersionsHelper createHelper(org.eclipse.aether.RepositorySystem a } @Test - public void testIgnoredVersionsShouldBeTheOnlyPresentInAnEmptyRuleSet() - throws MojoExecutionException, IllegalAccessException { + void testIgnoredVersionsShouldBeTheOnlyPresentInAnEmptyRuleSet() throws MojoExecutionException { DefaultVersionsHelper versionsHelper = new DefaultVersionsHelper.Builder() .withLog(new SystemStreamLog()) .withIgnoredVersions(Arrays.asList(".*-M.", ".*-SNAPSHOT")) .build(); - RuleSet ruleSet = (RuleSet) getVariableValueFromObject(versionsHelper, "ruleSet"); + RuleSet ruleSet = versionsHelper.getRuleSet(); assertThat(ruleSet.getIgnoreVersions(), hasSize(2)); assertThat( ruleSet.getIgnoreVersions().stream() @@ -286,17 +288,17 @@ public void testIgnoredVersionsShouldBeTheOnlyPresentInAnEmptyRuleSet() } @Test - public void testDefaultsShouldBePresentInAnEmptyRuleSet() throws MojoExecutionException, IllegalAccessException { + void testDefaultsShouldBePresentInAnEmptyRuleSet() throws MojoExecutionException, IllegalAccessException { DefaultVersionsHelper versionsHelper = new DefaultVersionsHelper.Builder() .withLog(new SystemStreamLog()) .withIgnoredVersions(singletonList(".*-M.")) .build(); - RuleSet ruleSet = (RuleSet) getVariableValueFromObject(versionsHelper, "ruleSet"); + RuleSet ruleSet = versionsHelper.getRuleSet(); assertThat(ruleSet.getComparisonMethod(), is("maven")); } @Test - public void testIgnoredVersionsShouldExtendTheRuleSet() throws MojoExecutionException, IllegalAccessException { + void testIgnoredVersionsShouldExtendTheRuleSet() throws MojoExecutionException, IllegalAccessException { DefaultVersionsHelper versionsHelper = new DefaultVersionsHelper.Builder() .withLog(new SystemStreamLog()) .withRuleSet(new RuleSet() { @@ -322,7 +324,7 @@ public void testIgnoredVersionsShouldExtendTheRuleSet() throws MojoExecutionExce }) .withIgnoredVersions(Arrays.asList(".*-M.", ".*-SNAPSHOT")) .build(); - RuleSet ruleSet = (RuleSet) getVariableValueFromObject(versionsHelper, "ruleSet"); + RuleSet ruleSet = versionsHelper.getRuleSet(); assertThat(ruleSet.getIgnoreVersions(), hasSize(3)); assertThat( ruleSet.getIgnoreVersions().stream() @@ -332,7 +334,7 @@ public void testIgnoredVersionsShouldExtendTheRuleSet() throws MojoExecutionExce } @Test - public void testRemoteRepositoryWithNeverUpdatePolicyShouldBeChangToDaily() { + void testRemoteRepositoryWithNeverUpdatePolicyShouldBeChangToDaily() { RemoteRepository repo1 = new RemoteRepository.Builder("id1", "", "") .setSnapshotPolicy(new RepositoryPolicy( @@ -377,4 +379,12 @@ public void testRemoteRepositoryWithNeverUpdatePolicyShouldBeChangToDaily() { remoteRepositories.get(1).getPolicy(false).getUpdatePolicy(), equalTo(RepositoryPolicy.UPDATE_POLICY_DAILY)); } + + private static Version parseVersion(String version) { + try { + return new GenericVersionScheme().parseVersion(version); + } catch (InvalidVersionSpecificationException e) { + throw new RuntimeException(e); + } + } } diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/api/PomHelperTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/api/PomHelperTest.java index 0ed517cbb..0c885c8f0 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/api/PomHelperTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/api/PomHelperTest.java @@ -41,37 +41,35 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.logging.SystemStreamLog; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.apache.maven.plugin.testing.MojoRule; import org.apache.maven.project.MavenProject; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.ModelNode; import org.codehaus.stax2.XMLInputFactory2; import org.hamcrest.MatcherAssert; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import static org.codehaus.mojo.versions.utils.ModifiedPomXMLEventReaderUtils.matches; import static org.codehaus.stax2.XMLInputFactory2.P_PRESERVE_LOCATION; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.Is.is; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; /** * Tests the methods of {@link PomHelper}. */ -public class PomHelperTest extends AbstractMojoTestCase { +class PomHelperTest { private static final int NUMBER_OF_CHILD_PROJECTS = 30; - @Rule - public MojoRule mojoRule = new MojoRule(this); - private static final XMLInputFactory INPUT_FACTORY = XMLInputFactory2.newInstance(); - @BeforeClass - public static void setUpClass() { + @BeforeAll + static void setUpClass() { INPUT_FACTORY.setProperty(P_PRESERVE_LOCATION, Boolean.TRUE); } @@ -82,7 +80,7 @@ public static void setUpClass() { * @throws Exception if the test fails. */ @Test - public void testLongProperties() throws Exception { + void testLongProperties() throws Exception { URL url = getClass().getResource("PomHelperTest.testLongProperties.pom.xml"); assert url != null; File file = new File(url.getPath()); @@ -97,7 +95,7 @@ public void testLongProperties() throws Exception { String newVersion = "1"; - assertTrue("The pom has been modified", PomHelper.setProjectVersion(pom, newVersion)); + assertTrue(PomHelper.setProjectVersion(pom, newVersion), "The pom has been modified"); assertEquals(newVersion, PomHelper.getProjectVersion(pom)); @@ -105,7 +103,7 @@ public void testLongProperties() throws Exception { } @Test - public void testGroupIdNotOnChildPom() throws Exception { + void testGroupIdNotOnChildPom() throws Exception { URL url = getClass().getResource("PomHelperTest.noGroupIdOnChild.pom.xml"); assert url != null; StringBuilder input = PomHelper.readXmlFile(new File(url.getPath())); @@ -116,67 +114,67 @@ public void testGroupIdNotOnChildPom() throws Exception { } @Test - public void testVersionVersionEqual() throws Exception { + void testVersionVersionEqual() throws Exception { assertTrue(PomHelper.isVersionOverlap("1.0.8", "1.0.8")); } @Test - public void testVersionVersionDiffer() throws Exception { + void testVersionVersionDiffer() throws Exception { assertFalse(PomHelper.isVersionOverlap("1.0.8", "1.0.0")); } @Test - public void testVersionRangeIntersect() throws Exception { + void testVersionRangeIntersect() throws Exception { assertTrue(PomHelper.isVersionOverlap("1.0.8", "[1.0.3,1.1.0]")); } @Test - public void testVersionRangeDisjoint() throws Exception { + void testVersionRangeDisjoint() throws Exception { assertFalse(PomHelper.isVersionOverlap("1.0.8", "[0.0.1,1.0.0]")); } @Test - public void testVersionLeftOpenRangeDisjoint() throws Exception { + void testVersionLeftOpenRangeDisjoint() throws Exception { assertFalse(PomHelper.isVersionOverlap("1.0.8", "[,1.0.0]")); } @Test - public void testVersionRightOpenRangeDisjoint() throws Exception { + void testVersionRightOpenRangeDisjoint() throws Exception { assertFalse(PomHelper.isVersionOverlap("1.0.8", "[1.1.0,)")); } @Test - public void testEmptyRange() throws Exception { + void testEmptyRange() throws Exception { assertTrue(PomHelper.isVersionOverlap("1.0.8", "")); } @Test - public void testRangeEmpty() throws Exception { + void testRangeEmpty() throws Exception { assertTrue(PomHelper.isVersionOverlap("[1.0.5,1.0.8]", "")); } @Test - public void testRangeRangeIntersect() throws Exception { + void testRangeRangeIntersect() throws Exception { assertTrue(PomHelper.isVersionOverlap("[1.0.5,1.0.8]", "[1.0.7,1.1.0]")); } @Test - public void testRangeRangeDisjoint() throws Exception { + void testRangeRangeDisjoint() throws Exception { assertFalse(PomHelper.isVersionOverlap("[1.0.5,1.0.6]", "[1.0.7,1.1.0]")); } @Test - public void testRangeVersionDisjoint() throws Exception { + void testRangeVersionDisjoint() throws Exception { assertFalse(PomHelper.isVersionOverlap("[1.0.5,1.0.6]", "1.0.8")); } @Test - public void testRangeVersionIntersect() throws Exception { + void testRangeVersionIntersect() throws Exception { assertTrue(PomHelper.isVersionOverlap("[1.0.0,2.0.0]", "1.0.8")); } @Test - public void testSetElementValueExistingValue() throws XMLStreamException { + void testSetElementValueExistingValue() throws XMLStreamException { ModifiedPomXMLEventReader xmlEventReader = new ModifiedPomXMLEventReader( new StringBuilder("test"), INPUT_FACTORY, @@ -188,7 +186,7 @@ public void testSetElementValueExistingValue() throws XMLStreamException { } @Test - public void testSetElementValueEmptyChild() throws XMLStreamException { + void testSetElementValueEmptyChild() throws XMLStreamException { ModifiedPomXMLEventReader xmlEventReader = new ModifiedPomXMLEventReader( new StringBuilder(""), INPUT_FACTORY, null); @@ -198,7 +196,7 @@ public void testSetElementValueEmptyChild() throws XMLStreamException { } @Test - public void testSetElementValueNewValueEmptyParent() throws XMLStreamException { + void testSetElementValueNewValueEmptyParent() throws XMLStreamException { ModifiedPomXMLEventReader xmlEventReader = new ModifiedPomXMLEventReader( new StringBuilder(""), INPUT_FACTORY, null); @@ -208,7 +206,7 @@ public void testSetElementValueNewValueEmptyParent() throws XMLStreamException { } @Test - public void testSetElementValueNewValueNoChild() throws XMLStreamException { + void testSetElementValueNewValueNoChild() throws XMLStreamException { ModifiedPomXMLEventReader xmlEventReader = new ModifiedPomXMLEventReader( new StringBuilder(""), INPUT_FACTORY, null); @@ -218,7 +216,7 @@ public void testSetElementValueNewValueNoChild() throws XMLStreamException { } @Test - public void testSetProjectValueNewValueNonEmptyParent() throws XMLStreamException { + void testSetProjectValueNewValueNonEmptyParent() throws XMLStreamException { ModifiedPomXMLEventReader xmlEventReader = new ModifiedPomXMLEventReader( new StringBuilder("test"), INPUT_FACTORY, @@ -230,14 +228,14 @@ public void testSetProjectValueNewValueNonEmptyParent() throws XMLStreamExceptio } @Test - public void testIssue505ChildModules() throws Exception { - MavenProject project = - mojoRule.readMavenProject(new File("src/test/resources/org/codehaus/mojo/versions/api/issue-505")); + void testIssue505ChildModules() throws Exception { + MavenProject project = new MavenProject(); + project.setFile(new File("src/test/resources/org/codehaus/mojo/versions/api/issue-505/pom.xml")); assertThat(PomHelper.getChildModels(project, new SystemStreamLog()).entrySet(), hasSize(3)); } @Test - public void testChildModelsForMultiLevelProject() throws Exception { + void testChildModelsForMultiLevelProject() throws Exception { Path tempDirectory = Files.createTempDirectory("testChildModelsForLargeNumberOfModules"); ModelWriter modelWriter = new DefaultModelWriter(); Map createdModels = new LinkedHashMap<>(); @@ -263,7 +261,8 @@ public void testChildModelsForMultiLevelProject() throws Exception { modelWriter.write(entry.getKey().resolve("pom.xml").toFile(), Collections.emptyMap(), entry.getValue()); } - MavenProject project = mojoRule.readMavenProject(tempDirectory.toFile()); + MavenProject project = new MavenProject(); + project.setFile(tempDirectory.resolve("pom.xml").toFile()); assertThat( PomHelper.getChildModels(project, new SystemStreamLog()).entrySet(), hasSize(createdModels.size())); @@ -283,7 +282,7 @@ private Model createSimpleModel(String artifactId) { } @Test - public void testGetRawModelTree() throws Exception { + void testGetRawModelTree() throws Exception { Log log = mock(Log.class); XMLInputFactory inputFactory = XMLInputFactory2.newInstance(); inputFactory.setProperty(XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE); @@ -301,7 +300,7 @@ public void testGetRawModelTree() throws Exception { } @Test - public void testFindProperty() throws Exception { + void testFindProperty() throws Exception { Log log = mock(Log.class); XMLInputFactory inputFactory = XMLInputFactory2.newInstance(); inputFactory.setProperty(XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE); diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/BoundArtifactVersionTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/BoundArtifactVersionTest.java index 18bad5911..0b4637337 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/BoundArtifactVersionTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/BoundArtifactVersionTest.java @@ -20,7 +20,7 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.codehaus.mojo.versions.utils.DefaultArtifactVersionCache; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL; import static org.codehaus.mojo.versions.api.Segment.MAJOR; @@ -33,58 +33,58 @@ /** * Unit tests for {@link BoundArtifactVersion} */ -public class BoundArtifactVersionTest { +class BoundArtifactVersionTest { @Test - public void testMajorUpperBoundGreaterThanNextMajor() { + void testMajorUpperBoundGreaterThanNextMajor() { BoundArtifactVersion bound = new BoundArtifactVersion("1.2.3", MAJOR); ArtifactVersion artifactVersion = DefaultArtifactVersionCache.of("2.0.0"); assertThat(bound.compareTo(artifactVersion), greaterThan(0)); } @Test - public void testSubIncrementalUpperBoundGreaterThanNextSubIncremental() { + void testSubIncrementalUpperBoundGreaterThanNextSubIncremental() { BoundArtifactVersion bound = new BoundArtifactVersion("1.2.3-2", SUBINCREMENTAL); ArtifactVersion artifactVersion = DefaultArtifactVersionCache.of("1.2.3-3"); assertThat(bound.compareTo(artifactVersion), greaterThan(0)); } @Test - public void testVersionShorterThanSegment() { + void testVersionShorterThanSegment() { BoundArtifactVersion bound = new BoundArtifactVersion("1.1", INCREMENTAL); ArtifactVersion artifactVersion = DefaultArtifactVersionCache.of("1.1.3"); assertThat(bound.compareTo(artifactVersion), greaterThan(0)); } @Test - public void testVersionBoundArtifactVersionShorterThanConcreteVersionAndSegment() { + void testVersionBoundArtifactVersionShorterThanConcreteVersionAndSegment() { BoundArtifactVersion bound = new BoundArtifactVersion("1.1", SUBINCREMENTAL); ArtifactVersion artifactVersion = DefaultArtifactVersionCache.of("1.1.3"); assertThat(bound.compareTo(artifactVersion), lessThan(0)); } @Test - public void testVersionSubIncrementalBoundGreaterThanSubIncremental() { + void testVersionSubIncrementalBoundGreaterThanSubIncremental() { BoundArtifactVersion bound = new BoundArtifactVersion("1.1", SUBINCREMENTAL); ArtifactVersion artifactVersion = DefaultArtifactVersionCache.of("1.1.0-2"); assertThat(bound.compareTo(artifactVersion), greaterThan(0)); } @Test - public void testVersionSubIncrementalBoundGreaterThanIncremental() { + void testVersionSubIncrementalBoundGreaterThanIncremental() { BoundArtifactVersion bound = new BoundArtifactVersion("1.1", INCREMENTAL); ArtifactVersion artifactVersion = DefaultArtifactVersionCache.of("1.1.3"); assertThat(bound.compareTo(artifactVersion), greaterThan(0)); } @Test - public void testVersionSubIncrementalBoundGreaterThanMinor() { + void testVersionSubIncrementalBoundGreaterThanMinor() { BoundArtifactVersion bound = new BoundArtifactVersion("1.1", MINOR); ArtifactVersion artifactVersion = DefaultArtifactVersionCache.of("1.3"); assertThat(bound.compareTo(artifactVersion), greaterThan(0)); } @Test - public void testSnapshotWithSubIncremental() { + void testSnapshotWithSubIncremental() { BoundArtifactVersion bound = new BoundArtifactVersion("1.0.0-SNAPSHOT", MINOR); ArtifactVersion artifactVersion = DefaultArtifactVersionCache.of("1.0.0"); assertThat(bound.compareTo(artifactVersion), greaterThan(0)); diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java index 1a072c2dc..53e8046da 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java @@ -20,7 +20,7 @@ */ import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL; import static org.codehaus.mojo.versions.api.Segment.SUBINCREMENTAL; @@ -29,13 +29,13 @@ import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.core.Is.is; -public class MavenVersionComparatorTest extends VersionComparatorTestBase { - public MavenVersionComparatorTest() { +class MavenVersionComparatorTest extends VersionComparatorTestBase { + MavenVersionComparatorTest() { super(new MavenVersionComparator()); } @Test - public void testSegmentCounting() { + void testSegmentCounting() { assertThat(3, is(instance.getSegmentCount(version("5")))); assertThat(3, is(instance.getSegmentCount(version("5.0")))); assertThat(4, is(instance.getSegmentCount(version("5-0")))); @@ -45,28 +45,28 @@ public void testSegmentCounting() { } @Test - public void testUpperBoundaryCustom() { + void testUpperBoundaryCustom() { assertThat( instance.compare(new BoundArtifactVersion(version("1.2.3"), INCREMENTAL), version("1.2.3-ANDRZEJ")), greaterThan(0)); } @Test - public void testUpperBoundaryRelease() { + void testUpperBoundaryRelease() { assertThat( instance.compare(new BoundArtifactVersion(version("1.1.0"), INCREMENTAL), version("1.1.0")), greaterThan(0)); } @Test - public void testUpperBoundarySnapshot() { + void testUpperBoundarySnapshot() { assertThat( instance.compare(new BoundArtifactVersion(version("1.1.0"), INCREMENTAL), version("1.1.0-SNAPSHOT")), greaterThan(0)); } @Test - public void testScopeLessThanNumSegmentsUpper() { + void testScopeLessThanNumSegmentsUpper() { ArtifactVersion artifactVersion = new BoundArtifactVersion(version("1.1"), SUBINCREMENTAL); assertThat(artifactVersion.compareTo(version("1.0.1")), greaterThan(0)); assertThat(artifactVersion.compareTo(version("1.1-SNAPSHOT")), greaterThan(0)); diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java index 3ed017eb0..db1ab45fa 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java @@ -20,17 +20,17 @@ */ import org.codehaus.mojo.versions.utils.DefaultArtifactVersionCache; -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 MercuryVersionComparatorTest extends VersionComparatorTestBase { - public MercuryVersionComparatorTest() { +class MercuryVersionComparatorTest extends VersionComparatorTestBase { + MercuryVersionComparatorTest() { super(new MercuryVersionComparator()); } @Test - public void testSegmentCounting() { + void testSegmentCounting() { assertEquals(1, instance.getSegmentCount(DefaultArtifactVersionCache.of("5"))); assertEquals(2, instance.getSegmentCount(DefaultArtifactVersionCache.of("5.0"))); assertEquals(2, instance.getSegmentCount(DefaultArtifactVersionCache.of("5-0"))); diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java index 1200442d7..c064f8f4a 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java @@ -20,13 +20,13 @@ */ import org.apache.maven.artifact.versioning.DefaultArtifactVersion; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class NumericVersionComparatorTest extends VersionComparatorTestBase { - public NumericVersionComparatorTest() { +class NumericVersionComparatorTest extends VersionComparatorTestBase { + NumericVersionComparatorTest() { super(new NumericVersionComparator()); } @@ -35,7 +35,7 @@ private int instanceCompare(String v1, String v2) { } @Test - public void testSmokes() { + void testSmokes() { assertTrue(instanceCompare("1.0.0.0.0", "1.0.0.0.1") < 0); assertTrue(instanceCompare("1.0.0.0.0", "2.0.0.0.1") < 0); assertTrue(instanceCompare("1.0.0.0.0", "1.0.0.0") < 0); @@ -44,14 +44,14 @@ public void testSmokes() { } @Test - public void testBigValues() { + void testBigValues() { assertTrue(instanceCompare("1.92.0", "1.100000000000000000000000.0") < 0); assertTrue(instanceCompare("1.100000000000000000000000.0", "1.92.0") > 0); assertTrue(instanceCompare("1.100000000000000000000000.0", "1.100000000000000000000000.0") == 0); } @Test - public void testStringValues() { + void testStringValues() { assertTrue(instanceCompare("1.a20.0", "1.a3.0") < 0); assertTrue(instanceCompare("1.a20.0", "1.b10.0") < 0); assertTrue(instanceCompare("1.a.0.b.0", "1.a.0.b.1") < 0); @@ -71,7 +71,7 @@ public void testStringValues() { } @Test - public void testQualifiers() { + void testQualifiers() { assertTrue(instanceCompare("1.0-alpha.10", "1.0-alpha.20") < 0); assertTrue(instanceCompare("1.0-alpha.10", "1.0-beta.1") < 0); assertTrue(instanceCompare("1.0", "1.0-alpha.2") > 0); @@ -80,7 +80,7 @@ public void testQualifiers() { } @Test - public void testSegmentCounting() { + void testSegmentCounting() { assertEquals(1, instance.getSegmentCount(new DefaultArtifactVersion("5"))); assertEquals(2, instance.getSegmentCount(new DefaultArtifactVersion("5.0"))); assertEquals(1, instance.getSegmentCount(new DefaultArtifactVersion("5-0"))); diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorTestBase.java b/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorTestBase.java index 81721fb07..431651e79 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorTestBase.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorTestBase.java @@ -21,7 +21,7 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.utils.DefaultArtifactVersionCache; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; @@ -31,10 +31,10 @@ * Abstract base class for {@link MavenVersionComparatorTest}, {@link MercuryVersionComparatorTest}, * and {@link NumericVersionComparatorTest} */ -public abstract class VersionComparatorTestBase { +abstract class VersionComparatorTestBase { protected final VersionComparator instance; - public VersionComparatorTestBase(VersionComparator instance) { + VersionComparatorTestBase(VersionComparator instance) { this.instance = instance; } @@ -43,7 +43,7 @@ protected static ArtifactVersion version(String version) { } @Test - public void testVersionComparatorRow1() { + void testVersionComparatorRow1() { assertThat(instance.compare(version("1"), version("2")), lessThan(0)); assertThat(instance.compare(version("1.0"), version("2.0")), lessThan(0)); assertThat(instance.compare(version("1.0"), version("1.1")), lessThan(0)); @@ -51,20 +51,20 @@ public void testVersionComparatorRow1() { } @Test - public void testVersionComparatorRow2() { + void testVersionComparatorRow2() { assertThat(instance.compare(version("1.0"), version("2.0")), lessThan(0)); assertThat(instance.compare(version("1.0"), version("1.1")), lessThan(0)); } @Test - public void testVersionComparatorRow3() { + void testVersionComparatorRow3() { assertThat(instance.compare(version("1.0.0"), version("2.0.0")), lessThan(0)); assertThat(instance.compare(version("1.0.0"), version("1.1.0")), lessThan(0)); assertThat(instance.compare(version("1.0.0"), version("1.0.1")), lessThan(0)); } @Test - public void testVersionComparatorRow4() { + void testVersionComparatorRow4() { assertThat(instance.compare(version("1.0.0-1"), version("2.0.0-1")), lessThan(0)); assertThat(instance.compare(version("1.0.0-1"), version("1.1.0-1")), lessThan(0)); assertThat(instance.compare(version("1.0.0-1"), version("1.0.1-1")), lessThan(0)); @@ -72,7 +72,7 @@ public void testVersionComparatorRow4() { } @Test - public void testVersionComparatorRow5() { + void testVersionComparatorRow5() { assertThat(instance.compare(version("1.0.0-sp1"), version("2.0.0-sp1")), lessThan(0)); assertThat(instance.compare(version("1.0.0-sp1"), version("1.1.0-sp1")), lessThan(0)); assertThat(instance.compare(version("1.0.0-sp1"), version("1.0.1-sp1")), lessThan(0)); @@ -80,18 +80,18 @@ public void testVersionComparatorRow5() { } @Test - public void testVersionComparatorRow6() { + void testVersionComparatorRow6() { assertThat(instance.compare(version("foobar"), version("foobar-1")), lessThan(0)); } @Test - public void testVersionComparatorRow7() { + void testVersionComparatorRow7() { assertThat(instance.compare(version("1-alpha-1"), version("2-alpha-1")), lessThan(0)); assertThat(instance.compare(version("1-alpha-1"), version("1-alpha-2")), lessThan(0)); } @Test - public void testBoundArtifactVersion() { + void testBoundArtifactVersion() { assertThat( instance.compare(new BoundArtifactVersion("1.0.0", Segment.MAJOR), version("1.9.9")), greaterThan(0)); } diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/recording/ChangeRecorderXMLTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/recording/ChangeRecorderXMLTest.java index 63df10c2a..8b76b80ef 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/recording/ChangeRecorderXMLTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/recording/ChangeRecorderXMLTest.java @@ -27,14 +27,16 @@ import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -public final class ChangeRecorderXMLTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + +class ChangeRecorderXMLTest { private static void copyResource(final String name, final Path output) throws IOException { try (InputStream inputStream = ChangeRecorderXMLTest.class.getResourceAsStream(name)) { Files.copy(inputStream, output, StandardCopyOption.REPLACE_EXISTING); @@ -48,7 +50,7 @@ private static Document parseXML(final Path path) throws ParserConfigurationExce } @Test - public void testChanges() throws Exception { + void testChanges() throws Exception { final Path path0 = Files.createTempFile("ChangeRecorderTest", ".xml"); final Path path1 = Files.createTempDirectory("ChangeRecorderTest") .resolve("subDirectory") @@ -81,39 +83,39 @@ public void testChanges() throws Exception { final NodeList elements0 = document0.getElementsByTagNameNS(ChangeRecorderXML.CHANGES_NAMESPACE, "updated"); final NodeList elements1 = document1.getElementsByTagNameNS(ChangeRecorderXML.CHANGES_NAMESPACE, "updated"); - Assert.assertEquals("Correct number of updates", elements0.getLength(), elements1.getLength()); + assertEquals(elements0.getLength(), elements1.getLength(), "Correct number of updates"); for (int index = 0; index < elements0.getLength(); ++index) { final Element element0 = (Element) elements0.item(index); final Element element1 = (Element) elements1.item(index); - Assert.assertEquals( + assertEquals( element0.getAttributeNS(ChangeRecorderXML.CHANGES_NAMESPACE, "artifactId"), element1.getAttributeNS(ChangeRecorderXML.CHANGES_NAMESPACE, "artifactId")); - Assert.assertEquals( + assertEquals( element0.getAttributeNS(ChangeRecorderXML.CHANGES_NAMESPACE, "groupId"), element1.getAttributeNS(ChangeRecorderXML.CHANGES_NAMESPACE, "groupId")); - Assert.assertEquals( + assertEquals( element0.getAttributeNS(ChangeRecorderXML.CHANGES_NAMESPACE, "oldVersion"), element1.getAttributeNS(ChangeRecorderXML.CHANGES_NAMESPACE, "oldVersion")); - Assert.assertEquals( + assertEquals( element0.getAttributeNS(ChangeRecorderXML.CHANGES_NAMESPACE, "newVersion"), element1.getAttributeNS(ChangeRecorderXML.CHANGES_NAMESPACE, "newVersion")); // FIXME - looks like assertions not working - Assert.assertEquals( + assertEquals( element0.getAttributeNS(ChangeRecorderXML.CHANGES_NAMESPACE, "kind"), element1.getAttributeNS(ChangeRecorderXML.CHANGES_NAMESPACE, "kind")); } } @Test - public void emptyResultShouldNotGenerateReports() throws Exception { + void emptyResultShouldNotGenerateReports() throws Exception { Path path = Files.createTempDirectory("ChangeRecorderTest").resolve("ChangeRecorderTest.xml"); ChangeRecorder recorder = new ChangeRecorderXML(); recorder.writeReport(path); - Assert.assertFalse("File should not be created", Files.isRegularFile(path)); + assertFalse(Files.isRegularFile(path), "File should not be created"); } } diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/rewriting/ModifiedPomXMLEventReaderTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/rewriting/ModifiedPomXMLEventReaderTest.java index efe678769..3d259c018 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/rewriting/ModifiedPomXMLEventReaderTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/rewriting/ModifiedPomXMLEventReaderTest.java @@ -22,17 +22,16 @@ import javax.xml.stream.Location; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; import java.io.StringReader; +import java.lang.reflect.Field; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; @@ -44,8 +43,8 @@ * * @author Andrzej Jarmoniuk */ -@RunWith(MockitoJUnitRunner.class) -public class ModifiedPomXMLEventReaderTest extends AbstractMojoTestCase { +@ExtendWith(MockitoExtension.class) +class ModifiedPomXMLEventReaderTest { private static final String[] STR = {"xyz", "0123456789abcdef"}; private static final String REPLACEMENT = "abcdef"; @@ -63,9 +62,8 @@ public class ModifiedPomXMLEventReaderTest extends AbstractMojoTestCase { private ModifiedPomXMLEventReader pomXMLEventReader; - @Before - public void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { when(location.getCharacterOffset()).thenReturn(STR[0].length()).thenReturn(STR[0].length() + STR[1].length()); @@ -88,7 +86,7 @@ public void setUp() throws Exception { } @Test - public void testReplace() throws XMLStreamException, IllegalAccessException { + void testReplace() throws Exception { assertThat(pomXMLEventReader.hasNext(), is(true)); assertThat(pomXMLEventReader.nextEvent(), is(xmlEvent)); @@ -102,11 +100,13 @@ public void testReplace() throws XMLStreamException, IllegalAccessException { assertThat(pomXMLEventReader.getMarkVerbatim(0), is(REPLACEMENT)); // more dangerous test since this touches the implementation - assertThat(getVariableValueFromObject(pomXMLEventReader, "lastEnd"), is((STR[0] + REPLACEMENT).length())); + Field field = pomXMLEventReader.getClass().getDeclaredField("lastEnd"); + field.setAccessible(true); + assertThat(field.getInt(pomXMLEventReader), is((STR[0] + REPLACEMENT).length())); } @Test - public void testReplaceMark() throws XMLStreamException, IllegalAccessException { + void testReplaceMark() throws Exception { assertThat(pomXMLEventReader.hasNext(), is(true)); assertThat(pomXMLEventReader.nextEvent(), is(xmlEvent)); @@ -122,6 +122,9 @@ public void testReplaceMark() throws XMLStreamException, IllegalAccessException assertThat(pomXMLEventReader.getMarkVerbatim(0), is(REPLACEMENT)); // more dangerous test since this touches the implementation - assertThat(getVariableValueFromObject(pomXMLEventReader, "lastEnd"), is((STR[0] + REPLACEMENT).length())); + Field field = pomXMLEventReader.getClass().getDeclaredField("lastEnd"); + field.setAccessible(true); + + assertThat(field.getInt(pomXMLEventReader), is((STR[0] + REPLACEMENT).length())); } } diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/utils/CoreExtensionUtilsTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/utils/CoreExtensionUtilsTest.java index 90aaeec52..7af0c343c 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/utils/CoreExtensionUtilsTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/utils/CoreExtensionUtilsTest.java @@ -25,7 +25,7 @@ import org.apache.maven.model.Extension; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItems; @@ -38,10 +38,10 @@ * * @author Andrzej Jarmoniuk */ -public class CoreExtensionUtilsTest { +class CoreExtensionUtilsTest { @Test - public void testNoExtensions() throws XmlPullParserException, IOException { + void testNoExtensions() throws XmlPullParserException, IOException { MavenProject project = mock(MavenProject.class); when(project.getBasedir()) .thenReturn( @@ -52,7 +52,7 @@ public void testNoExtensions() throws XmlPullParserException, IOException { } @Test - public void testExtensionsFound() throws XmlPullParserException, IOException { + void testExtensionsFound() throws XmlPullParserException, IOException { MavenProject project = mock(MavenProject.class); when(project.getBasedir()) .thenReturn(new File("src/test/resources/org/codehaus/mojo/versions/utils/core-extensions")); diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/utils/PropertiesVersionsFileReaderTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/utils/PropertiesVersionsFileReaderTest.java index 5fd8c9841..fc1e00d81 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/utils/PropertiesVersionsFileReaderTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/utils/PropertiesVersionsFileReaderTest.java @@ -25,23 +25,25 @@ import java.util.Set; import org.apache.commons.lang3.StringUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class PropertiesVersionsFileReaderTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class PropertiesVersionsFileReaderTest { private static final String TEST_PROPERTIES_FILE = "src/test/resources/org/codehaus/mojo/versions/utils/testPropertiesVersionsFile.properties"; @Test - public void testRead() throws IOException { + void testRead() throws IOException { PropertiesVersionsFileReader reader = new PropertiesVersionsFileReader(TEST_PROPERTIES_FILE); reader.read(); int numberOfPropertiesConfig = 3; - Assert.assertTrue(equalsCvsUnordered( + assertTrue(equalsCvsUnordered( "booking-api.version,booking-lib.version,be-air-impl.version", reader.getProperties())); - Assert.assertEquals(numberOfPropertiesConfig, reader.getPropertiesConfig().length); + assertEquals(numberOfPropertiesConfig, reader.getPropertiesConfig().length); } private boolean equalsCvsUnordered(String csvExpected, String csvActual) { diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/utils/SegmentUtilsTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/utils/SegmentUtilsTest.java index 36a8c17de..5ea5bf4e8 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/utils/SegmentUtilsTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/utils/SegmentUtilsTest.java @@ -22,7 +22,7 @@ import org.apache.maven.plugin.logging.Log; import org.codehaus.mojo.versions.api.Segment; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.util.Optional.empty; import static java.util.Optional.of; @@ -36,27 +36,27 @@ /** * Unit tests for {@link SegmentUtils} */ -public class SegmentUtilsTest { +class SegmentUtilsTest { @Test - public void testIncremental() { + void testIncremental() { assertThat(determineUnchangedSegment(false, false, false, null), is(of(INCREMENTAL))); assertThat(determineUnchangedSegment(true, false, false, null), is(of(INCREMENTAL))); assertThat(determineUnchangedSegment(true, true, false, null), is(of(INCREMENTAL))); } @Test - public void testMinor() { + void testMinor() { assertThat(determineUnchangedSegment(false, false, true, null), is(of(MINOR))); assertThat(determineUnchangedSegment(true, false, true, null), is(of(MINOR))); } @Test - public void testMajor() { + void testMajor() { assertThat(determineUnchangedSegment(false, true, true, null), is(of(MAJOR))); } @Test - public void testEmpty() { + void testEmpty() { Optional result; boolean allowMinorUpdates = true; boolean allowIncrementalUpdates = true; diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/utils/VersionStub.java b/versions-common/src/test/java/org/codehaus/mojo/versions/utils/VersionStub.java deleted file mode 100644 index c23e05758..000000000 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/utils/VersionStub.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.codehaus.mojo.versions.utils; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.eclipse.aether.version.Version; - -/** - * Stubs the {@link org.eclipse.aether.version.Version} - */ -public class VersionStub implements Version { - private final String version; - - /** - * Creates a new instance with the given version string - * @param version version to be set - */ - public VersionStub(String version) { - assert version != null; - this.version = version; - } - - @Override - public String toString() { - return version; - } - - @Override - public int compareTo(Version o) { - return o != null ? version.compareTo(o.toString()) : 1; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (!(o instanceof Version)) { - return false; - } - - return version.equals(o.toString()); - } - - @Override - public int hashCode() { - return version.hashCode(); - } -} diff --git a/versions-enforcer/pom.xml b/versions-enforcer/pom.xml index 84f619402..8f8d24b31 100644 --- a/versions-enforcer/pom.xml +++ b/versions-enforcer/pom.xml @@ -71,39 +71,20 @@ ${project.version} test - - org.eclipse.sisu - org.eclipse.sisu.plexus - test - - junit - junit + org.junit.jupiter + junit-jupiter-api test - - - org.hamcrest - hamcrest-core - - - - org.junit.vintage - junit-vintage-engine + org.mockito + mockito-core test - - - org.hamcrest - hamcrest-core - - - org.mockito - mockito-core + mockito-junit-jupiter test @@ -141,9 +122,6 @@ */pom.xml verify - - ${repository.proxy.url} - -Xmx256m diff --git a/versions-enforcer/src/test/java/org/codehaus/mojo/versions/enforcer/MaxDependencyUpdatesTest.java b/versions-enforcer/src/test/java/org/codehaus/mojo/versions/enforcer/MaxDependencyUpdatesTest.java index d7219d2cd..b20acbca6 100644 --- a/versions-enforcer/src/test/java/org/codehaus/mojo/versions/enforcer/MaxDependencyUpdatesTest.java +++ b/versions-enforcer/src/test/java/org/codehaus/mojo/versions/enforcer/MaxDependencyUpdatesTest.java @@ -27,25 +27,24 @@ import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.MockUtils; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) -public class MaxDependencyUpdatesTest { +@ExtendWith(MockitoExtension.class) +class MaxDependencyUpdatesTest { @Mock private EnforcerLogger enforcerLogger; @@ -65,14 +64,14 @@ public class MaxDependencyUpdatesTest { @InjectMocks private MaxDependencyUpdates maxDependencyUpdates; - @Before + @BeforeEach public void setup() { maxDependencyUpdates.setLog(enforcerLogger); MockUtils.prepareRepositorySystemMock(repositorySystem); } @Test - public void testRuleFailsByMaxUpdatesExceeded() throws ExpressionEvaluationException, ComponentLookupException { + void testRuleFailsByMaxUpdatesExceeded() { when(project.getDependencies()) .thenReturn(asList( DependencyBuilder.newBuilder() @@ -94,18 +93,13 @@ public void testRuleFailsByMaxUpdatesExceeded() throws ExpressionEvaluationExcep } }); - try { - maxDependencyUpdates.maxUpdates = 1; - maxDependencyUpdates.execute(); - - fail("EnforcerRuleException should have been thrown"); - } catch (EnforcerRuleException e) { - assertThat(e.getMessage(), containsString("More than 1 upgradable artifacts detected")); - } + maxDependencyUpdates.maxUpdates = 1; + Exception e = assertThrows(EnforcerRuleException.class, () -> maxDependencyUpdates.execute()); + assertThat(e.getMessage(), containsString("More than 1 upgradable artifacts detected")); } @Test - public void testRulePassesByMaxUpdatesNotExceeded() throws Exception { + void testRulePassesByMaxUpdatesNotExceeded() { when(project.getDependencies()) .thenReturn(singletonList(DependencyBuilder.newBuilder() @@ -118,11 +112,11 @@ public void testRulePassesByMaxUpdatesNotExceeded() throws Exception { aetherRepositorySystem, singletonMap("artifactA", new String[] {"1.0.0", "2.0.0"})); maxDependencyUpdates.maxUpdates = 1; - maxDependencyUpdates.execute(); + assertDoesNotThrow(() -> maxDependencyUpdates.execute()); } @Test - public void testRulePassesByMaxUpdatesNotExceededDependencyIncludes() throws Exception { + void testRulePassesByMaxUpdatesNotExceededDependencyIncludes() { when(project.getDependencies()) .thenReturn(asList( @@ -146,11 +140,11 @@ public void testRulePassesByMaxUpdatesNotExceededDependencyIncludes() throws Exc }); maxDependencyUpdates.dependencyIncludes = singletonList("group:artifactB"); - maxDependencyUpdates.execute(); + assertDoesNotThrow(() -> maxDependencyUpdates.execute()); } @Test - public void testRulePassesByMaxUpdatesNotExceededDependencyExcludes() throws Exception { + void testRulePassesByMaxUpdatesNotExceededDependencyExcludes() { when(project.getDependencies()) .thenReturn(asList( @@ -174,11 +168,11 @@ public void testRulePassesByMaxUpdatesNotExceededDependencyExcludes() throws Exc }); maxDependencyUpdates.dependencyExcludes = singletonList("group:artifactA"); - maxDependencyUpdates.execute(); + assertDoesNotThrow(() -> maxDependencyUpdates.execute()); } @Test - public void testRulePassesByMaxUpdatesNotExceededDependencyIncludesExcludes() throws Exception { + void testRulePassesByMaxUpdatesNotExceededDependencyIncludesExcludes() { when(project.getDependencies()) .thenReturn(asList( @@ -203,11 +197,11 @@ public void testRulePassesByMaxUpdatesNotExceededDependencyIncludesExcludes() th maxDependencyUpdates.dependencyIncludes = singletonList("group:*"); maxDependencyUpdates.dependencyExcludes = singletonList("group:artifactA"); - maxDependencyUpdates.execute(); + assertDoesNotThrow(() -> maxDependencyUpdates.execute()); } @Test - public void testIgnoreSubIncrementalUpdates() throws Exception { + void testIgnoreSubIncrementalUpdates() { when(project.getDependencies()) .thenReturn(singletonList(DependencyBuilder.newBuilder() @@ -220,11 +214,11 @@ public void testIgnoreSubIncrementalUpdates() throws Exception { aetherRepositorySystem, singletonMap("artifactA", new String[] {"1.0.0", "1.0.0-1"})); maxDependencyUpdates.ignoreSubIncrementalUpdates = true; - maxDependencyUpdates.execute(); + assertDoesNotThrow(() -> maxDependencyUpdates.execute()); } @Test - public void testIgnoreIncrementalUpdates() throws Exception { + void testIgnoreIncrementalUpdates() { when(project.getDependencies()) .thenReturn(singletonList(DependencyBuilder.newBuilder() .withGroupId("group") @@ -236,11 +230,11 @@ public void testIgnoreIncrementalUpdates() throws Exception { aetherRepositorySystem, singletonMap("artifactA", new String[] {"1.0.0", "1.0.0-1", "1.0.1"})); maxDependencyUpdates.ignoreIncrementalUpdates = true; - maxDependencyUpdates.execute(); + assertDoesNotThrow(() -> maxDependencyUpdates.execute()); } @Test - public void testIgnoreMinorUpdates() throws Exception { + void testIgnoreMinorUpdates() { when(project.getDependencies()) .thenReturn(singletonList(DependencyBuilder.newBuilder() @@ -253,6 +247,6 @@ public void testIgnoreMinorUpdates() throws Exception { aetherRepositorySystem, singletonMap("artifactA", new String[] {"1.0.0", "1.0.0-1", "1.0.1", "1.1.0"})); maxDependencyUpdates.ignoreMinorUpdates = true; - maxDependencyUpdates.execute(); + assertDoesNotThrow(() -> maxDependencyUpdates.execute()); } } diff --git a/versions-maven-plugin/src/it/it-set-issue-505/invoker.properties b/versions-maven-plugin/src/it/it-set-issue-505/invoker.properties deleted file mode 100644 index f21410e6a..000000000 --- a/versions-maven-plugin/src/it/it-set-issue-505/invoker.properties +++ /dev/null @@ -1,2 +0,0 @@ -invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:set -invoker.mavenOpts = -DnewVersion=TEST diff --git a/versions-maven-plugin/src/it/it-set-issue-505/moduleA/moduleB/pom.xml b/versions-maven-plugin/src/it/it-set-issue-505/moduleA/moduleB/pom.xml deleted file mode 100644 index 92023f8d5..000000000 --- a/versions-maven-plugin/src/it/it-set-issue-505/moduleA/moduleB/pom.xml +++ /dev/null @@ -1,13 +0,0 @@ - - 4.0.0 - - - default-group - moduleA - 1.0-SNAPSHOT - - - moduleB - - diff --git a/versions-maven-plugin/src/it/it-set-issue-505/moduleA/pom.xml b/versions-maven-plugin/src/it/it-set-issue-505/moduleA/pom.xml deleted file mode 100644 index 123b5c733..000000000 --- a/versions-maven-plugin/src/it/it-set-issue-505/moduleA/pom.xml +++ /dev/null @@ -1,18 +0,0 @@ - - 4.0.0 - - - default-group - default-artifact - 1.0-SNAPSHOT - - - moduleA - pom - - - moduleB/pom.xml - - - diff --git a/versions-maven-plugin/src/it/it-set-issue-505/pom.xml b/versions-maven-plugin/src/it/it-set-issue-505/pom.xml deleted file mode 100644 index c2a998332..000000000 --- a/versions-maven-plugin/src/it/it-set-issue-505/pom.xml +++ /dev/null @@ -1,13 +0,0 @@ - - 4.0.0 - default-group - default-artifact - 1.0-SNAPSHOT - pom - - - moduleA/pom.xml - - - diff --git a/versions-maven-plugin/src/it/it-set-issue-505/verify.groovy b/versions-maven-plugin/src/it/it-set-issue-505/verify.groovy deleted file mode 100644 index 4ebd95210..000000000 --- a/versions-maven-plugin/src/it/it-set-issue-505/verify.groovy +++ /dev/null @@ -1,3 +0,0 @@ -assert new File( basedir, "pom.xml" ).text.contains( 'TEST' ) -assert new File( basedir, "moduleA/pom.xml" ).text.contains( 'TEST' ) -assert new File( basedir, "moduleA/moduleB/pom.xml" ).text.contains( 'TEST' ) diff --git a/versions-test/pom.xml b/versions-test/pom.xml index ab4a0619a..22e6de24d 100644 --- a/versions-test/pom.xml +++ b/versions-test/pom.xml @@ -52,6 +52,10 @@ org.apache.maven.resolver maven-resolver-api + + org.apache.maven.resolver + maven-resolver-util + org.apache.maven.doxia doxia-integration-tools diff --git a/versions-test/src/main/java/org/codehaus/mojo/versions/utils/MockUtils.java b/versions-test/src/main/java/org/codehaus/mojo/versions/utils/MockUtils.java index aea5a1d43..b8d248da2 100644 --- a/versions-test/src/main/java/org/codehaus/mojo/versions/utils/MockUtils.java +++ b/versions-test/src/main/java/org/codehaus/mojo/versions/utils/MockUtils.java @@ -38,6 +38,8 @@ import org.eclipse.aether.resolution.VersionRangeRequest; import org.eclipse.aether.resolution.VersionRangeResolutionException; import org.eclipse.aether.resolution.VersionRangeResult; +import org.eclipse.aether.util.version.GenericVersionScheme; +import org.eclipse.aether.version.InvalidVersionSpecificationException; import org.eclipse.aether.version.Version; import static java.util.Collections.emptyList; @@ -108,7 +110,7 @@ public static void prepareAetherRepositorySystemMockForVersionRange( e.getKey().equals(request.getArtifact().getArtifactId())) .findAny() .map(e -> Arrays.stream(e.getValue()) - .map(VersionStub::new) + .map(MockUtils::parseVersion) .collect(() -> new ArrayList(), ArrayList::add, ArrayList::addAll)) .map(versions -> new VersionRangeResult(request).setVersions(versions)) .orElse(null); // should tell us if we haven't populated all cases in the test @@ -118,6 +120,14 @@ public static void prepareAetherRepositorySystemMockForVersionRange( } } + private static Version parseVersion(String version) { + try { + return new GenericVersionScheme().parseVersion(version); + } catch (InvalidVersionSpecificationException e) { + throw new RuntimeException(e); + } + } + public static I18N mockI18N() { I18N i18n = mock(I18N.class); when(i18n.getString(anyString(), any(), anyString())).thenAnswer(invocation -> invocation.getArgument(2)); diff --git a/versions-test/src/main/java/org/codehaus/mojo/versions/utils/VersionStub.java b/versions-test/src/main/java/org/codehaus/mojo/versions/utils/VersionStub.java deleted file mode 100644 index 925d38fe0..000000000 --- a/versions-test/src/main/java/org/codehaus/mojo/versions/utils/VersionStub.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.codehaus.mojo.versions.utils; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.eclipse.aether.version.Version; - -/** - * Stubs the {@link Version} - */ -public class VersionStub implements Version { - private final String version; - - /** - * Creates a new instance with the given version string - * @param version version to be set - */ - public VersionStub(String version) { - assert version != null; - this.version = version; - } - - @Override - public String toString() { - return version; - } - - @Override - public int compareTo(Version o) { - return o != null ? version.compareTo(o.toString()) : 1; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (!(o instanceof Version)) { - return false; - } - - return version.equals(o.toString()); - } - - @Override - public int hashCode() { - return version.hashCode(); - } -}