Skip to content

Commit 08a64ff

Browse files
Use JUnit5 in versions-commons, versions-enforcer
1 parent 7b86752 commit 08a64ff

29 files changed

+282
-483
lines changed

Diff for: pom.xml

+10-3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@
130130
<modelloNamespaceRuleVersion>2.1.0</modelloNamespaceRuleVersion>
131131
<modelloNamespaceReportVersion>2.0.0</modelloNamespaceReportVersion>
132132
<byteBuddyVersion>1.14.17</byteBuddyVersion>
133+
<!-- use the same version as in Maven core -->
134+
<mavenResolverVersion>1.4.1</mavenResolverVersion>
135+
133136
<scmpublish.content>${project.build.directory}/staging/versions</scmpublish.content>
134137
<!-- execute ITS in parallel by default -->
135138
<invoker.parallelThreads>0.75C</invoker.parallelThreads>
@@ -185,14 +188,13 @@
185188
<dependency>
186189
<groupId>org.apache.maven.resolver</groupId>
187190
<artifactId>maven-resolver-api</artifactId>
188-
<!-- use the same version as in Maven core -->
189-
<version>1.4.1</version>
191+
<version>${mavenResolverVersion}</version>
190192
<scope>provided</scope>
191193
</dependency>
192194
<dependency>
193195
<groupId>org.apache.maven.resolver</groupId>
194196
<artifactId>maven-resolver-util</artifactId>
195-
<version>1.4.1</version>
197+
<version>${mavenResolverVersion}</version>
196198
</dependency>
197199

198200
<dependency>
@@ -295,6 +297,11 @@
295297
<artifactId>mockito-inline</artifactId>
296298
<version>${mockitoVersion}</version>
297299
</dependency>
300+
<dependency>
301+
<groupId>org.mockito</groupId>
302+
<artifactId>mockito-junit-jupiter</artifactId>
303+
<version>${mockitoVersion}</version>
304+
</dependency>
298305
<dependency>
299306
<groupId>org.hamcrest</groupId>
300307
<artifactId>hamcrest</artifactId>

Diff for: versions-common/pom.xml

+3-32
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,11 @@
8282
<groupId>javax.inject</groupId>
8383
<artifactId>javax.inject</artifactId>
8484
</dependency>
85-
8685
<dependency>
8786
<groupId>org.apache.maven.resolver</groupId>
8887
<artifactId>maven-resolver-util</artifactId>
8988
<scope>test</scope>
9089
</dependency>
91-
<dependency>
92-
<groupId>org.apache.maven.plugin-testing</groupId>
93-
<artifactId>maven-plugin-testing-harness</artifactId>
94-
<scope>test</scope>
95-
</dependency>
96-
<dependency>
97-
<groupId>junit</groupId>
98-
<artifactId>junit</artifactId>
99-
<scope>test</scope>
100-
<exclusions>
101-
<exclusion>
102-
<groupId>org.hamcrest</groupId>
103-
<artifactId>hamcrest-core</artifactId>
104-
</exclusion>
105-
</exclusions>
106-
</dependency>
10790
<dependency>
10891
<groupId>org.junit.jupiter</groupId>
10992
<artifactId>junit-jupiter-api</artifactId>
@@ -115,19 +98,13 @@
11598
<scope>test</scope>
11699
</dependency>
117100
<dependency>
118-
<groupId>org.junit.vintage</groupId>
119-
<artifactId>junit-vintage-engine</artifactId>
101+
<groupId>org.mockito</groupId>
102+
<artifactId>mockito-core</artifactId>
120103
<scope>test</scope>
121-
<exclusions>
122-
<exclusion>
123-
<groupId>org.hamcrest</groupId>
124-
<artifactId>hamcrest-core</artifactId>
125-
</exclusion>
126-
</exclusions>
127104
</dependency>
128105
<dependency>
129106
<groupId>org.mockito</groupId>
130-
<artifactId>mockito-core</artifactId>
107+
<artifactId>mockito-junit-jupiter</artifactId>
131108
<scope>test</scope>
132109
</dependency>
133110
<dependency>
@@ -145,12 +122,6 @@
145122
<artifactId>commons-io</artifactId>
146123
<scope>test</scope>
147124
</dependency>
148-
<!-- Required by Maven Testing Harness -->
149-
<dependency>
150-
<groupId>org.apache.maven</groupId>
151-
<artifactId>maven-compat</artifactId>
152-
<scope>test</scope>
153-
</dependency>
154125
</dependencies>
155126

156127
<build>

Diff for: versions-common/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected ArtifactVersion getHighestLowerBound(ArtifactVersion lowerBoundVersion
9292
* or {@link Optional#empty()} if there are no ranges
9393
*/
9494
protected Optional<Restriction> getSelectedRestriction(ArtifactVersion selectedVersion) {
95-
assert selectedVersion != null;
95+
Objects.requireNonNull(selectedVersion);
9696
return Optional.ofNullable(getCurrentVersionRange())
9797
.map(VersionRange::getRestrictions)
9898
.flatMap(r -> r.stream()

Diff for: versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java

+5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ public class DefaultVersionsHelper implements VersionsHelper {
110110

111111
private static final int LOOKUP_PARALLEL_THREADS = 5;
112112

113+
// for testing purpose
114+
RuleSet getRuleSet() {
115+
return ruleSet;
116+
}
117+
113118
/**
114119
* The artifact comparison rules to use.
115120
*

Diff for: versions-common/src/test/java/org/codehaus/mojo/versions/api/AbstractVersionDetailsTest.java

+16-21
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@
2121
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
2222
import org.codehaus.mojo.versions.ordering.MavenVersionComparator;
2323
import org.codehaus.mojo.versions.ordering.VersionComparator;
24-
import org.junit.Before;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
2626

2727
import static java.util.Optional.empty;
2828
import static java.util.Optional.of;
2929
import static org.codehaus.mojo.versions.api.Segment.MAJOR;
3030
import static org.codehaus.mojo.versions.utils.ArtifactVersionUtils.version;
3131
import static org.hamcrest.MatcherAssert.assertThat;
3232
import static org.hamcrest.Matchers.is;
33-
import static org.junit.Assert.fail;
33+
import static org.junit.jupiter.api.Assertions.assertThrows;
3434

3535
/**
3636
* Unit tests for {@link AbstractVersionDetails}
3737
*/
38-
public class AbstractVersionDetailsTest {
38+
class AbstractVersionDetailsTest {
3939

4040
private AbstractVersionDetails instance;
4141

42-
@Before
43-
public void setUp() {
42+
@BeforeEach
43+
void setUp() {
4444
instance = new AbstractVersionDetails() {
4545
@Override
4646
public VersionComparator getVersionComparator() {
@@ -55,7 +55,7 @@ public ArtifactVersion[] getVersions(boolean includeSnapshots) {
5555
}
5656

5757
@Test
58-
public void testRestrictionForUnchangedSegmentWithSimpleVersion() throws InvalidSegmentException {
58+
void testRestrictionForUnchangedSegmentWithSimpleVersion() throws InvalidSegmentException {
5959
assertThat(
6060
instance.restrictionForUnchangedSegment(version("1.0.0"), of(MAJOR), false)
6161
.containsVersion(version("1.0.0")),
@@ -75,7 +75,7 @@ public void testRestrictionForUnchangedSegmentWithSimpleVersion() throws Invalid
7575
}
7676

7777
@Test
78-
public void testRestrictionForUnchangedSegmentWithRange()
78+
void testRestrictionForUnchangedSegmentWithRange()
7979
throws InvalidSegmentException, InvalidVersionSpecificationException {
8080
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("(0.0.1, 1.0.0]"));
8181
assertThat(
@@ -97,7 +97,7 @@ public void testRestrictionForUnchangedSegmentWithRange()
9797
}
9898

9999
@Test
100-
public void testRestrictionForUnchangedSegmentWithTwoRanges()
100+
void testRestrictionForUnchangedSegmentWithTwoRanges()
101101
throws InvalidSegmentException, InvalidVersionSpecificationException {
102102
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("(0.0.1, 1.0.0],(1.0.0,2.0.0]"));
103103
assertThat(
@@ -119,7 +119,7 @@ public void testRestrictionForUnchangedSegmentWithTwoRanges()
119119
}
120120

121121
@Test
122-
public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges1()
122+
void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges1()
123123
throws InvalidSegmentException, InvalidVersionSpecificationException {
124124
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("(0.0.1, 1.0.0),(1.0.0,2.0.0]"));
125125
assertThat(
@@ -129,7 +129,7 @@ public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges1()
129129
}
130130

131131
@Test
132-
public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges2()
132+
void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges2()
133133
throws InvalidSegmentException, InvalidVersionSpecificationException {
134134
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("(0.0.1, 1.0.0),(1.0.0,2.0.0]"));
135135
assertThat(
@@ -139,7 +139,7 @@ public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges2()
139139
}
140140

141141
@Test
142-
public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges3()
142+
void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges3()
143143
throws InvalidSegmentException, InvalidVersionSpecificationException {
144144
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("(0.0.1, 1.0.0),(1.0.0,2.0.0]"));
145145
assertThat(
@@ -149,7 +149,7 @@ public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges3()
149149
}
150150

151151
@Test
152-
public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges4()
152+
void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges4()
153153
throws InvalidSegmentException, InvalidVersionSpecificationException {
154154
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("(0.0.1, 1.0.0),(1.0.0,2.0.0]"));
155155
assertThat(
@@ -159,7 +159,7 @@ public void testRestrictionForUnchangedSegmentWithTwoNotConnectingRanges4()
159159
}
160160

161161
@Test
162-
public void testRestrictionForUnchangedSegmentWithoutVersionInformation()
162+
void testRestrictionForUnchangedSegmentWithoutVersionInformation()
163163
throws InvalidSegmentException, InvalidVersionSpecificationException {
164164
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("[,0]"));
165165
assertThat(
@@ -168,13 +168,8 @@ public void testRestrictionForUnchangedSegmentWithoutVersionInformation()
168168
}
169169

170170
@Test
171-
public void testGetSelectedRestrictionForNoVersion()
172-
throws InvalidVersionSpecificationException, InvalidSegmentException {
171+
void testGetSelectedRestrictionForNoVersion() throws InvalidVersionSpecificationException {
173172
instance.setCurrentVersionRange(VersionRange.createFromVersionSpec("[,0]"));
174-
try {
175-
instance.getSelectedRestriction(null);
176-
fail("Expected a NullPointerException to be thrown or assertions are not enabled.");
177-
} catch (AssertionError ignored) {
178-
}
173+
assertThrows(NullPointerException.class, () -> instance.getSelectedRestriction(null));
179174
}
180175
}

Diff for: versions-common/src/test/java/org/codehaus/mojo/versions/api/ArtifactVersionsTest.java

+20-20
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.codehaus.mojo.versions.ordering.MavenVersionComparator;
3333
import org.codehaus.mojo.versions.ordering.MercuryVersionComparator;
3434
import org.codehaus.mojo.versions.ordering.VersionComparator;
35-
import org.junit.Test;
35+
import org.junit.jupiter.api.Test;
3636

3737
import static java.util.Optional.of;
3838
import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL;
@@ -47,11 +47,11 @@
4747
import static org.hamcrest.Matchers.hasToString;
4848
import static org.hamcrest.Matchers.is;
4949
import static org.hamcrest.Matchers.nullValue;
50-
import static org.junit.Assert.assertArrayEquals;
51-
import static org.junit.Assert.assertEquals;
52-
import static org.junit.Assert.assertNull;
50+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
51+
import static org.junit.jupiter.api.Assertions.assertEquals;
52+
import static org.junit.jupiter.api.Assertions.assertNull;
5353

54-
public class ArtifactVersionsTest {
54+
class ArtifactVersionsTest {
5555

5656
private void test4DigitVersion(VersionComparator comparator) throws InvalidVersionSpecificationException {
5757
ArtifactVersions instance = new ArtifactVersions(
@@ -101,17 +101,17 @@ private void test4DigitVersion(VersionComparator comparator) throws InvalidVersi
101101
}
102102

103103
@Test
104-
public void test4DigitVersionsMercury() throws Exception {
104+
void test4DigitVersionsMercury() throws Exception {
105105
test4DigitVersion(new MercuryVersionComparator());
106106
}
107107

108108
@Test
109-
public void test4DigitVersionsMaven() throws Exception {
109+
void test4DigitVersionsMaven() throws Exception {
110110
test4DigitVersion(new MavenVersionComparator());
111111
}
112112

113113
@Test
114-
public void testIsEmpty() throws Exception {
114+
void testIsEmpty() throws Exception {
115115
ArtifactVersions instance = new ArtifactVersions(
116116
new DefaultArtifact(
117117
"group",
@@ -128,7 +128,7 @@ public void testIsEmpty() throws Exception {
128128
}
129129

130130
@Test
131-
public void testSmokes() throws Exception {
131+
void testSmokes() throws Exception {
132132
ArtifactVersions instance = new ArtifactVersions(
133133
new DefaultArtifact(
134134
"group",
@@ -155,7 +155,7 @@ public void testSmokes() throws Exception {
155155
}
156156

157157
@Test
158-
public void testReportLabels() {
158+
void testReportLabels() {
159159
ArtifactVersions instance = new ArtifactVersions(
160160
new DefaultArtifact("default-group", "dummy-api", "1.1", "foo", "bar", "jar", null),
161161
Arrays.asList(versions(
@@ -188,7 +188,7 @@ public void testReportLabels() {
188188
}
189189

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

209209
@Test
210-
public void testAllVersionsForIgnoreScopeSubIncremental() {
210+
void testAllVersionsForIgnoreScopeSubIncremental() {
211211
ArtifactVersions instance = createInstance(versions("1.0.0", "1.0.0-1", "1.0.1"));
212212
ArtifactVersion[] filteredVersions = instance.getVersions(
213213
instance.restrictionForIgnoreScope(instance.getCurrentVersion(), of(SUBINCREMENTAL)), false);
@@ -216,7 +216,7 @@ public void testAllVersionsForIgnoreScopeSubIncremental() {
216216
}
217217

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

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

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

244244
@Test
245-
public void testGetReportNewestUpdateWithOnlyMajorUpdate() {
245+
void testGetReportNewestUpdateWithOnlyMajorUpdate() {
246246
ArtifactVersions instance = createInstance(versions("1.0.0", "2.0.0"));
247247
assertThat(instance.getReportNewestUpdate(Optional.empty(), true).toString(), is("2.0.0"));
248248
assertThat(instance.getReportNewestUpdate(of(MAJOR), true), hasToString("2.0.0"));
@@ -252,7 +252,7 @@ public void testGetReportNewestUpdateWithOnlyMajorUpdate() {
252252
}
253253

254254
@Test
255-
public void testGetReportNewestUpdateWithMinorAndMajor() {
255+
void testGetReportNewestUpdateWithMinorAndMajor() {
256256
ArtifactVersions instance = createInstance(versions("1.0.0", "1.1.0", "2.0.0"));
257257
assertThat(instance.getReportNewestUpdate(Optional.empty(), true).toString(), is("2.0.0"));
258258
assertThat(instance.getReportNewestUpdate(of(MAJOR), true), hasToString("2.0.0"));
@@ -262,7 +262,7 @@ public void testGetReportNewestUpdateWithMinorAndMajor() {
262262
}
263263

264264
@Test
265-
public void testGetReportNewestUpdateWithIncrementalAndMajor() {
265+
void testGetReportNewestUpdateWithIncrementalAndMajor() {
266266
ArtifactVersions instance = createInstance(versions("1.0.0", "1.0.1", "2.0.0"));
267267
assertThat(instance.getReportNewestUpdate(Optional.empty(), true).toString(), is("2.0.0"));
268268
assertThat(instance.getReportNewestUpdate(of(MAJOR), true), hasToString("2.0.0"));
@@ -272,7 +272,7 @@ public void testGetReportNewestUpdateWithIncrementalAndMajor() {
272272
}
273273

274274
@Test
275-
public void testGetNewestVersionWithLesserSegment() throws InvalidSegmentException {
275+
void testGetNewestVersionWithLesserSegment() throws InvalidSegmentException {
276276
ArtifactVersions instance = createInstance(versions("1.0.0-1"));
277277
assertThat(instance.getNewestVersion("1.0.0", of(MAJOR), false, false).get(), hasToString("1.0.0-1"));
278278
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
283283
}
284284

285285
@Test
286-
public void testGetNewestVersionWithLesserSegmentWithSnapshots() throws InvalidSegmentException {
286+
void testGetNewestVersionWithLesserSegmentWithSnapshots() throws InvalidSegmentException {
287287
ArtifactVersions instance = createInstance(versions("1.0.0-1-SNAPSHOT"));
288288
assertThat(instance.getNewestVersion("1.0.0", of(MAJOR), true, false).get(), hasToString("1.0.0-1-SNAPSHOT"));
289289
assertThat(instance.getNewestVersion("1.0.0", of(MINOR), true, false).get(), hasToString("1.0.0-1-SNAPSHOT"));

0 commit comments

Comments
 (0)