diff --git a/api/maven-api-core/src/test/java/org/apache/maven/api/MonotonicClockTest.java b/api/maven-api-core/src/test/java/org/apache/maven/api/MonotonicClockTest.java index de561fb591a4..c77c18e2870a 100644 --- a/api/maven-api-core/src/test/java/org/apache/maven/api/MonotonicClockTest.java +++ b/api/maven-api-core/src/test/java/org/apache/maven/api/MonotonicClockTest.java @@ -28,69 +28,76 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class MonotonicClockTest { @Test @DisplayName("MonotonicClock singleton instance should always return the same instance") - void testSingletonInstance() { + void singletonInstance() { MonotonicClock clock1 = MonotonicClock.get(); MonotonicClock clock2 = MonotonicClock.get(); - assertSame(clock1, clock2, "Multiple calls to get() should return the same instance"); + assertThat(clock2) + .as("Multiple calls to get() should return the same instance") + .isSameAs(clock1); } @Test @DisplayName("MonotonicClock should always use UTC timezone") - void testClockTimezone() { + void clockTimezone() { MonotonicClock clock = MonotonicClock.get(); - assertEquals(ZoneOffset.UTC, clock.getZone(), "Clock should use UTC timezone"); + assertThat(clock.getZone()).as("Clock should use UTC timezone").isEqualTo(ZoneOffset.UTC); // Verify that attempting to change timezone returns the same instance Clock newClock = clock.withZone(ZoneId.systemDefault()); - assertSame(clock, newClock, "withZone() should return the same clock instance"); + assertThat(newClock) + .as("withZone() should return the same clock instance") + .isSameAs(clock); } @Test @DisplayName("MonotonicClock should maintain monotonic time progression") - void testMonotonicBehavior() throws InterruptedException { + void monotonicBehavior() throws InterruptedException { Instant first = MonotonicClock.now(); Thread.sleep(10); // Small delay Instant second = MonotonicClock.now(); Thread.sleep(10); // Small delay Instant third = MonotonicClock.now(); - assertTrue(first.isBefore(second), "Time should progress forward between measurements"); - assertTrue(second.isBefore(third), "Time should progress forward between measurements"); + assertThat(first.isBefore(second)) + .as("Time should progress forward between measurements") + .isTrue(); + assertThat(second.isBefore(third)) + .as("Time should progress forward between measurements") + .isTrue(); } @Test @DisplayName("MonotonicClock elapsed time should increase") - void testElapsedTime() throws InterruptedException { + void elapsedTime() throws InterruptedException { Duration initial = MonotonicClock.elapsed(); Thread.sleep(50); // Longer delay for more reliable measurement Duration later = MonotonicClock.elapsed(); - assertTrue(later.compareTo(initial) > 0, "Elapsed time should increase"); - assertTrue( - later.minus(initial).toMillis() >= 45, - "Elapsed time difference should be at least 45ms (accounting for some timing variance)"); + assertThat(later.compareTo(initial) > 0) + .as("Elapsed time should increase") + .isTrue(); + assertThat(later.minus(initial).toMillis() >= 45) + .as("Elapsed time difference should be at least 45ms (accounting for some timing variance)") + .isTrue(); } @Test @DisplayName("MonotonicClock start time should remain constant") - void testStartTime() throws InterruptedException { + void startTime() throws InterruptedException { Instant start1 = MonotonicClock.start(); Thread.sleep(10); Instant start2 = MonotonicClock.start(); - assertEquals(start1, start2, "Start time should remain constant"); - assertNotNull(start1, "Start time should not be null"); + assertThat(start2).as("Start time should remain constant").isEqualTo(start1); + assertThat(start1).as("Start time should not be null").isNotNull(); } @Nested @@ -99,31 +106,33 @@ class TimeConsistencyTests { @Test @DisplayName("Current time should be after start time") - void testCurrentTimeAfterStart() { + void currentTimeAfterStart() { Instant now = MonotonicClock.now(); Instant start = MonotonicClock.start(); - assertTrue(now.isAfter(start), "Current time should be after start time"); + assertThat(now.isAfter(start)) + .as("Current time should be after start time") + .isTrue(); } @Test @DisplayName("Elapsed time should match time difference") - void testElapsedTimeConsistency() { + void elapsedTimeConsistency() { MonotonicClock clock = MonotonicClock.get(); Instant now = clock.instant(); Duration elapsed = clock.elapsedTime(); Duration calculated = Duration.between(clock.startInstant(), now); // Allow for small timing differences (1ms) due to execution time between measurements - assertTrue( - Math.abs(elapsed.toMillis() - calculated.toMillis()) <= 1, - "Elapsed time should match calculated duration between start and now"); + assertThat(Math.abs(elapsed.toMillis() - calculated.toMillis()) <= 1) + .as("Elapsed time should match calculated duration between start and now") + .isTrue(); } } @Test @DisplayName("MonotonicClock should handle rapid successive calls") - void testRapidCalls() { + void rapidCalls() { Instant[] instants = new Instant[1000]; for (int i = 0; i < instants.length; i++) { instants[i] = MonotonicClock.now(); @@ -131,20 +140,22 @@ void testRapidCalls() { // Verify monotonic behavior across all measurements for (int i = 1; i < instants.length; i++) { - assertTrue( - instants[i].compareTo(instants[i - 1]) >= 0, - "Time should never go backwards even with rapid successive calls"); + assertThat(instants[i].compareTo(instants[i - 1]) >= 0) + .as("Time should never go backwards even with rapid successive calls") + .isTrue(); } } @Test @DisplayName("MonotonicClock should maintain reasonable alignment with system time") - void testSystemTimeAlignment() { + void systemTimeAlignment() { Instant monotonic = MonotonicClock.now(); Instant system = Instant.now(); // The difference should be relatively small (allow for 1 second max) Duration difference = Duration.between(monotonic, system).abs(); - assertTrue(difference.getSeconds() <= 1, "Monotonic time should be reasonably aligned with system time"); + assertThat(difference.getSeconds() <= 1) + .as("Monotonic time should be reasonably aligned with system time") + .isTrue(); } } diff --git a/api/maven-api-core/src/test/java/org/apache/maven/api/services/RequestImplementationTest.java b/api/maven-api-core/src/test/java/org/apache/maven/api/services/RequestImplementationTest.java index eef64a138888..f45cb2fcdec1 100644 --- a/api/maven-api-core/src/test/java/org/apache/maven/api/services/RequestImplementationTest.java +++ b/api/maven-api-core/src/test/java/org/apache/maven/api/services/RequestImplementationTest.java @@ -27,15 +27,13 @@ import org.apache.maven.api.Session; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; class RequestImplementationTest { @Test - void testArtifactResolverRequestEquality() { + void artifactResolverRequestEquality() { Session session = mock(Session.class); ArtifactCoordinates coords1 = mock(ArtifactCoordinates.class); ArtifactCoordinates coords2 = mock(ArtifactCoordinates.class); @@ -63,30 +61,30 @@ void testArtifactResolverRequestEquality() { .build(); // Test equals and hashCode - assertEquals(request1, request2); - assertEquals(request1.hashCode(), request2.hashCode()); - assertNotEquals(request1, request3); + assertThat(request2).isEqualTo(request1); + assertThat(request2.hashCode()).isEqualTo(request1.hashCode()); + assertThat(request3).isNotEqualTo(request1); // Test toString String toString = request1.toString(); - assertTrue(toString.contains("coordinates=")); - assertTrue(toString.contains("repositories=")); + assertThat(toString.contains("coordinates=")).isTrue(); + assertThat(toString.contains("repositories=")).isTrue(); } @Test - void testRequestTraceIntegration() { + void requestTraceIntegration() { Session session = mock(Session.class); RequestTrace trace = new RequestTrace("test-context", null, "test-data"); ArtifactInstallerRequest request = ArtifactInstallerRequest.builder().session(session).trace(trace).build(); - assertEquals(trace, request.getTrace()); - assertEquals(session, request.getSession()); + assertThat(request.getTrace()).isEqualTo(trace); + assertThat(request.getSession()).isEqualTo(session); } @Test - void testDependencyResolverRequestEquality() { + void dependencyResolverRequestEquality() { Session session = mock(Session.class); DependencyResolverRequest.DependencyResolverRequestBuilder builder = DependencyResolverRequest.builder(); @@ -105,12 +103,12 @@ void testDependencyResolverRequestEquality() { .pathScope(PathScope.MAIN_COMPILE) .build(); - assertEquals(request1, request2); - assertEquals(request1.hashCode(), request2.hashCode()); - assertNotEquals(request1, request3); + assertThat(request2).isEqualTo(request1); + assertThat(request2.hashCode()).isEqualTo(request1.hashCode()); + assertThat(request3).isNotEqualTo(request1); String toString = request1.toString(); - assertTrue(toString.contains("requestType=")); - assertTrue(toString.contains("pathScope=")); + assertThat(toString.contains("requestType=")).isTrue(); + assertThat(toString.contains("pathScope=")).isTrue(); } } diff --git a/api/maven-api-core/src/test/java/org/apache/maven/api/services/RequestTraceTest.java b/api/maven-api-core/src/test/java/org/apache/maven/api/services/RequestTraceTest.java index 78534f9ae5f5..142b8a74e80c 100644 --- a/api/maven-api-core/src/test/java/org/apache/maven/api/services/RequestTraceTest.java +++ b/api/maven-api-core/src/test/java/org/apache/maven/api/services/RequestTraceTest.java @@ -20,68 +20,66 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; +import static org.assertj.core.api.Assertions.assertThat; class RequestTraceTest { @Test - void testRequestTraceCreation() { + void requestTraceCreation() { RequestTrace parentTrace = new RequestTrace("parent-context", null, "parent-data"); RequestTrace childTrace = new RequestTrace("child-context", parentTrace, "child-data"); - assertEquals("parent-context", parentTrace.context()); - assertNull(parentTrace.parent()); - assertEquals("parent-data", parentTrace.data()); + assertThat(parentTrace.context()).isEqualTo("parent-context"); + assertThat(parentTrace.parent()).isNull(); + assertThat(parentTrace.data()).isEqualTo("parent-data"); - assertEquals("child-context", childTrace.context()); - assertSame(parentTrace, childTrace.parent()); - assertEquals("child-data", childTrace.data()); + assertThat(childTrace.context()).isEqualTo("child-context"); + assertThat(childTrace.parent()).isSameAs(parentTrace); + assertThat(childTrace.data()).isEqualTo("child-data"); } @Test - void testRequestTraceWithParentContextInheritance() { + void requestTraceWithParentContextInheritance() { RequestTrace parentTrace = new RequestTrace("parent-context", null, "parent-data"); RequestTrace childTrace = new RequestTrace(parentTrace, "child-data"); - assertEquals("parent-context", parentTrace.context()); - assertEquals("parent-context", childTrace.context()); - assertEquals("child-data", childTrace.data()); + assertThat(parentTrace.context()).isEqualTo("parent-context"); + assertThat(childTrace.context()).isEqualTo("parent-context"); + assertThat(childTrace.data()).isEqualTo("child-data"); } @Test - void testPredefinedContexts() { - assertEquals("plugin", RequestTrace.CONTEXT_PLUGIN); - assertEquals("project", RequestTrace.CONTEXT_PROJECT); - assertEquals("bootstrap", RequestTrace.CONTEXT_BOOTSTRAP); + void predefinedContexts() { + assertThat(RequestTrace.CONTEXT_PLUGIN).isEqualTo("plugin"); + assertThat(RequestTrace.CONTEXT_PROJECT).isEqualTo("project"); + assertThat(RequestTrace.CONTEXT_BOOTSTRAP).isEqualTo("bootstrap"); } @Test - void testNullValues() { + void nullValues() { RequestTrace trace = new RequestTrace(null, null, null); - assertNull(trace.context()); - assertNull(trace.parent()); - assertNull(trace.data()); + assertThat(trace.context()).isNull(); + assertThat(trace.parent()).isNull(); + assertThat(trace.data()).isNull(); } @Test - void testChainedTraces() { + void chainedTraces() { RequestTrace root = new RequestTrace("root", null, "root-data"); RequestTrace level1 = new RequestTrace("level1", root, "level1-data"); RequestTrace level2 = new RequestTrace("level2", level1, "level2-data"); RequestTrace level3 = new RequestTrace(level2, "level3-data"); // Verify the chain - assertNull(root.parent()); - assertEquals(root, level1.parent()); - assertEquals(level1, level2.parent()); - assertEquals(level2, level3.parent()); + assertThat(root.parent()).isNull(); + assertThat(level1.parent()).isEqualTo(root); + assertThat(level2.parent()).isEqualTo(level1); + assertThat(level3.parent()).isEqualTo(level2); // Verify context inheritance - assertEquals("root", root.context()); - assertEquals("level1", level1.context()); - assertEquals("level2", level2.context()); - assertEquals("level2", level3.context()); // Inherited from parent + assertThat(root.context()).isEqualTo("root"); + assertThat(level1.context()).isEqualTo("level1"); + assertThat(level2.context()).isEqualTo("level2"); + assertThat(level3.context()).isEqualTo("level2"); // Inherited from parent } } diff --git a/api/maven-api-core/src/test/java/org/apache/maven/api/services/SourcesTest.java b/api/maven-api-core/src/test/java/org/apache/maven/api/services/SourcesTest.java index f9abbe66d28b..ff0dc711ebb2 100644 --- a/api/maven-api-core/src/test/java/org/apache/maven/api/services/SourcesTest.java +++ b/api/maven-api-core/src/test/java/org/apache/maven/api/services/SourcesTest.java @@ -27,11 +27,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -43,53 +40,53 @@ class SourcesTest { Path tempDir; @Test - void testFromPath() { + void fromPath() { Path path = Paths.get("/tmp"); Source source = Sources.fromPath(path); - assertNotNull(source); - assertInstanceOf(Sources.PathSource.class, source); - assertEquals(path.normalize(), source.getPath()); + assertThat(source).isNotNull(); + assertThat(source).isInstanceOf(Sources.PathSource.class); + assertThat(source.getPath()).isEqualTo(path.normalize()); } @Test - void testBuildSource() { + void buildSource() { Path path = Paths.get("/tmp"); ModelSource source = Sources.buildSource(path); - assertNotNull(source); - assertInstanceOf(Sources.BuildPathSource.class, source); - assertEquals(path.normalize(), source.getPath()); + assertThat(source).isNotNull(); + assertThat(source).isInstanceOf(Sources.BuildPathSource.class); + assertThat(source.getPath()).isEqualTo(path.normalize()); } @Test - void testResolvedSource() { + void resolvedSource() { Path path = Paths.get("/tmp"); String location = "custom-location"; ModelSource source = Sources.resolvedSource(path, location); - assertNotNull(source); - assertInstanceOf(Sources.ResolvedPathSource.class, source); - assertNull(source.getPath()); - assertEquals(location, source.getLocation()); + assertThat(source).isNotNull(); + assertThat(source).isInstanceOf(Sources.ResolvedPathSource.class); + assertThat(source.getPath()).isNull(); + assertThat(source.getLocation()).isEqualTo(location); } @Test - void testPathSourceFunctionality() { + void pathSourceFunctionality() { // Test basic source functionality Path path = Paths.get("/tmp"); Sources.PathSource source = (Sources.PathSource) Sources.fromPath(path); - assertEquals(path.normalize(), source.getPath()); - assertEquals(path.toString(), source.getLocation()); + assertThat(source.getPath()).isEqualTo(path.normalize()); + assertThat(source.getLocation()).isEqualTo(path.toString()); Source resolved = source.resolve("subdir"); - assertNotNull(resolved); - assertEquals(path.resolve("subdir").normalize(), resolved.getPath()); + assertThat(resolved).isNotNull(); + assertThat(resolved.getPath()).isEqualTo(path.resolve("subdir").normalize()); } @Test - void testBuildPathSourceFunctionality() { + void buildPathSourceFunctionality() { // Test build source functionality Path basePath = Paths.get("/tmp"); ModelSource.ModelLocator locator = mock(ModelSource.ModelLocator.class); @@ -99,31 +96,31 @@ void testBuildPathSourceFunctionality() { Sources.BuildPathSource source = (Sources.BuildPathSource) Sources.buildSource(basePath); ModelSource resolved = source.resolve(locator, "subproject"); - assertNotNull(resolved); - assertInstanceOf(Sources.BuildPathSource.class, resolved); - assertEquals(resolvedPath, resolved.getPath()); + assertThat(resolved).isNotNull(); + assertThat(resolved).isInstanceOf(Sources.BuildPathSource.class); + assertThat(resolved.getPath()).isEqualTo(resolvedPath); verify(locator).locateExistingPom(any(Path.class)); } @Test - void testResolvedPathSourceFunctionality() { + void resolvedPathSourceFunctionality() { // Test resolved source functionality Path path = Paths.get("/tmp"); String location = "custom-location"; Sources.ResolvedPathSource source = (Sources.ResolvedPathSource) Sources.resolvedSource(path, location); - assertNull(source.getPath()); - assertEquals(location, source.getLocation()); - assertNull(source.resolve("subdir")); + assertThat(source.getPath()).isNull(); + assertThat(source.getLocation()).isEqualTo(location); + assertThat(source.resolve("subdir")).isNull(); ModelSource.ModelLocator locator = mock(ModelSource.ModelLocator.class); - assertNull(source.resolve(locator, "subproject")); + assertThat(source.resolve(locator, "subproject")).isNull(); verify(locator, never()).locateExistingPom(any(Path.class)); } @Test - void testStreamReading() throws IOException { + void streamReading() throws IOException { // Test stream reading functionality Path testFile = tempDir.resolve("test.txt"); String content = "test content"; @@ -132,14 +129,15 @@ void testStreamReading() throws IOException { Source source = Sources.fromPath(testFile); try (InputStream inputStream = source.openStream()) { String readContent = new String(inputStream.readAllBytes()); - assertEquals(content, readContent); + assertThat(readContent).isEqualTo(content); } } @Test - void testNullHandling() { - assertThrows(NullPointerException.class, () -> Sources.fromPath(null)); - assertThrows(NullPointerException.class, () -> Sources.buildSource(null)); - assertThrows(NullPointerException.class, () -> Sources.resolvedSource(null, "location")); + void nullHandling() { + assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> Sources.fromPath(null)); + assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> Sources.buildSource(null)); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Sources.resolvedSource(null, "location")); } } diff --git a/api/maven-api-plugin/pom.xml b/api/maven-api-plugin/pom.xml index 37ed030feaf2..aa4874eed563 100644 --- a/api/maven-api-plugin/pom.xml +++ b/api/maven-api-plugin/pom.xml @@ -45,6 +45,11 @@ under the License. junit-jupiter-api test + + org.assertj + assertj-core + test + diff --git a/api/maven-api-plugin/src/test/java/org/apache/maven/api/plugin/descriptor/another/ExtendedPluginDescriptorTest.java b/api/maven-api-plugin/src/test/java/org/apache/maven/api/plugin/descriptor/another/ExtendedPluginDescriptorTest.java index c6b5e9ad67be..d107b03709ca 100644 --- a/api/maven-api-plugin/src/test/java/org/apache/maven/api/plugin/descriptor/another/ExtendedPluginDescriptorTest.java +++ b/api/maven-api-plugin/src/test/java/org/apache/maven/api/plugin/descriptor/another/ExtendedPluginDescriptorTest.java @@ -21,7 +21,7 @@ import org.apache.maven.api.plugin.descriptor.PluginDescriptor; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Verifies that subclasses from generated model classes are possible. @@ -63,7 +63,7 @@ public ExtendedPluginDescriptor build() { } @Test - void testExtendedPluginDescriptor() { + void extendedPluginDescriptor() { ExtendedPluginDescriptor.Builder builder = new ExtendedPluginDescriptor.Builder(); // make sure to call the subclasses' builder methods first, otherwise fluent API would not work builder.additionalField("additional") @@ -71,7 +71,7 @@ void testExtendedPluginDescriptor() { .artifactId("maven-plugin-api") .version("1.0.0"); ExtendedPluginDescriptor descriptor = builder.build(); - assertEquals("additional", descriptor.getAdditionalField()); - assertEquals("org.apache.maven", descriptor.getGroupId()); + assertThat(descriptor.getAdditionalField()).isEqualTo("additional"); + assertThat(descriptor.getGroupId()).isEqualTo("org.apache.maven"); } } diff --git a/api/maven-api-settings/pom.xml b/api/maven-api-settings/pom.xml index df4242455509..b01c29de961e 100644 --- a/api/maven-api-settings/pom.xml +++ b/api/maven-api-settings/pom.xml @@ -46,6 +46,11 @@ under the License. junit-jupiter-api test + + org.assertj + assertj-core + test + diff --git a/api/maven-api-settings/src/test/java/org/apache/maven/api/settings/SettingsTest.java b/api/maven-api-settings/src/test/java/org/apache/maven/api/settings/SettingsTest.java index b78630752ad6..3d9932e59d7d 100644 --- a/api/maven-api-settings/src/test/java/org/apache/maven/api/settings/SettingsTest.java +++ b/api/maven-api-settings/src/test/java/org/apache/maven/api/settings/SettingsTest.java @@ -20,22 +20,21 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; class SettingsTest { @Test - void testSetLocalRepository() { + void setLocalRepository() { Settings s = Settings.newInstance(); s = s.withLocalRepository("xxx"); - assertEquals("xxx", s.getLocalRepository()); + assertThat(s.getLocalRepository()).isEqualTo("xxx"); s = s.withLocalRepository("yyy"); - assertEquals("yyy", s.getLocalRepository()); + assertThat(s.getLocalRepository()).isEqualTo("yyy"); s = s.withLocalRepository(null); - assertNull(s.getLocalRepository()); + assertThat(s.getLocalRepository()).isNull(); } } diff --git a/compat/maven-artifact/src/test/java/org/apache/maven/artifact/ArtifactUtilsTest.java b/compat/maven-artifact/src/test/java/org/apache/maven/artifact/ArtifactUtilsTest.java index 740bdee4100b..d6375dba1ae9 100644 --- a/compat/maven-artifact/src/test/java/org/apache/maven/artifact/ArtifactUtilsTest.java +++ b/compat/maven-artifact/src/test/java/org/apache/maven/artifact/ArtifactUtilsTest.java @@ -25,10 +25,7 @@ import org.apache.maven.artifact.versioning.VersionRange; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@link ArtifactUtils}. @@ -41,29 +38,29 @@ private Artifact newArtifact(String aid) { } @Test - void testIsSnapshot() { - assertFalse(ArtifactUtils.isSnapshot(null)); - assertFalse(ArtifactUtils.isSnapshot("")); - assertFalse(ArtifactUtils.isSnapshot("1.2.3")); - assertTrue(ArtifactUtils.isSnapshot("1.2.3-SNAPSHOT")); - assertTrue(ArtifactUtils.isSnapshot("1.2.3-snapshot")); - assertTrue(ArtifactUtils.isSnapshot("1.2.3-20090413.094722-2")); - assertFalse(ArtifactUtils.isSnapshot("1.2.3-20090413X094722-2")); + void isSnapshot() { + assertThat(ArtifactUtils.isSnapshot(null)).isFalse(); + assertThat(ArtifactUtils.isSnapshot("")).isFalse(); + assertThat(ArtifactUtils.isSnapshot("1.2.3")).isFalse(); + assertThat(ArtifactUtils.isSnapshot("1.2.3-SNAPSHOT")).isTrue(); + assertThat(ArtifactUtils.isSnapshot("1.2.3-snapshot")).isTrue(); + assertThat(ArtifactUtils.isSnapshot("1.2.3-20090413.094722-2")).isTrue(); + assertThat(ArtifactUtils.isSnapshot("1.2.3-20090413X094722-2")).isFalse(); } @Test - void testToSnapshotVersion() { - assertEquals("1.2.3", ArtifactUtils.toSnapshotVersion("1.2.3")); - assertEquals("1.2.3-SNAPSHOT", ArtifactUtils.toSnapshotVersion("1.2.3-SNAPSHOT")); - assertEquals("1.2.3-SNAPSHOT", ArtifactUtils.toSnapshotVersion("1.2.3-20090413.094722-2")); - assertEquals("1.2.3-20090413X094722-2", ArtifactUtils.toSnapshotVersion("1.2.3-20090413X094722-2")); + void toSnapshotVersion() { + assertThat(ArtifactUtils.toSnapshotVersion("1.2.3")).isEqualTo("1.2.3"); + assertThat(ArtifactUtils.toSnapshotVersion("1.2.3-SNAPSHOT")).isEqualTo("1.2.3-SNAPSHOT"); + assertThat(ArtifactUtils.toSnapshotVersion("1.2.3-20090413.094722-2")).isEqualTo("1.2.3-SNAPSHOT"); + assertThat(ArtifactUtils.toSnapshotVersion("1.2.3-20090413X094722-2")).isEqualTo("1.2.3-20090413X094722-2"); } /** * Tests that the ordering of the map resembles the ordering of the input collection of artifacts. */ @Test - void testArtifactMapByVersionlessIdOrdering() throws Exception { + void artifactMapByVersionlessIdOrdering() throws Exception { List list = new ArrayList<>(); list.add(newArtifact("b")); list.add(newArtifact("a")); @@ -72,7 +69,7 @@ void testArtifactMapByVersionlessIdOrdering() throws Exception { list.add(newArtifact("d")); Map map = ArtifactUtils.artifactMapByVersionlessId(list); - assertNotNull(map); - assertEquals(list, new ArrayList<>(map.values())); + assertThat(map).isNotNull(); + assertThat(new ArrayList<>(map.values())).isEqualTo(list); } } diff --git a/compat/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java b/compat/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java index 74fcd5fb93a8..5ce42335b1f2 100644 --- a/compat/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java +++ b/compat/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java @@ -28,10 +28,8 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; class DefaultArtifactTest { @@ -66,111 +64,105 @@ void setUp() throws Exception { } @Test - void testGetVersionReturnsResolvedVersionOnSnapshot() { - assertEquals(snapshotResolvedVersion, snapshotArtifact.getVersion()); + void getVersionReturnsResolvedVersionOnSnapshot() { + assertThat(snapshotArtifact.getVersion()).isEqualTo(snapshotResolvedVersion); // this is FOUL! // snapshotArtifact.isSnapshot(); - assertEquals(snapshotSpecVersion, snapshotArtifact.getBaseVersion()); + assertThat(snapshotArtifact.getBaseVersion()).isEqualTo(snapshotSpecVersion); } @Test - void testGetDependencyConflictId() { - assertEquals(groupId + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId()); + void getDependencyConflictId() { + assertThat(artifact.getDependencyConflictId()).isEqualTo(groupId + ":" + artifactId + ":" + type + ":" + classifier); } @Test - void testGetDependencyConflictIdNullGroupId() { + void getDependencyConflictIdNullGroupId() { artifact.setGroupId(null); - assertEquals(null + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId()); + assertThat(artifact.getDependencyConflictId()).isEqualTo(null + ":" + artifactId + ":" + type + ":" + classifier); } @Test - void testGetDependencyConflictIdNullClassifier() { + void getDependencyConflictIdNullClassifier() { artifact = new DefaultArtifact(groupId, artifactId, versionRange, scope, type, null, artifactHandler); - assertEquals(groupId + ":" + artifactId + ":" + type, artifact.getDependencyConflictId()); + assertThat(artifact.getDependencyConflictId()).isEqualTo(groupId + ":" + artifactId + ":" + type); } @Test - void testGetDependencyConflictIdNullScope() { + void getDependencyConflictIdNullScope() { artifact.setScope(null); - assertEquals(groupId + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId()); + assertThat(artifact.getDependencyConflictId()).isEqualTo(groupId + ":" + artifactId + ":" + type + ":" + classifier); } @Test void testToString() { - assertEquals( - groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope, - artifact.toString()); + assertThat(artifact.toString()).isEqualTo(groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope); } @Test - void testToStringNullGroupId() { + void toStringNullGroupId() { artifact.setGroupId(null); - assertEquals(artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope, artifact.toString()); + assertThat(artifact.toString()).isEqualTo(artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope); } @Test - void testToStringNullClassifier() { + void toStringNullClassifier() { artifact = new DefaultArtifact(groupId, artifactId, versionRange, scope, type, null, artifactHandler); - assertEquals(groupId + ":" + artifactId + ":" + type + ":" + version + ":" + scope, artifact.toString()); + assertThat(artifact.toString()).isEqualTo(groupId + ":" + artifactId + ":" + type + ":" + version + ":" + scope); } @Test - void testToStringNullScope() { + void toStringNullScope() { artifact.setScope(null); - assertEquals(groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version, artifact.toString()); + assertThat(artifact.toString()).isEqualTo(groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version); } @Test - void testComparisonByVersion() { + void comparisonByVersion() { Artifact artifact1 = new DefaultArtifact( groupId, artifactId, VersionRange.createFromVersion("5.0"), scope, type, classifier, artifactHandler); Artifact artifact2 = new DefaultArtifact( groupId, artifactId, VersionRange.createFromVersion("12.0"), scope, type, classifier, artifactHandler); - assertTrue(artifact1.compareTo(artifact2) < 0); - assertTrue(artifact2.compareTo(artifact1) > 0); + assertThat(artifact1.compareTo(artifact2) < 0).isTrue(); + assertThat(artifact2.compareTo(artifact1) > 0).isTrue(); Artifact artifact = new DefaultArtifact( groupId, artifactId, VersionRange.createFromVersion("5.0"), scope, type, classifier, artifactHandler); - assertTrue(artifact.compareTo(artifact1) == 0); - assertTrue(artifact1.compareTo(artifact) == 0); + assertThat(artifact.compareTo(artifact1)).isEqualTo(0); + assertThat(artifact1.compareTo(artifact)).isEqualTo(0); } @Test - void testNonResolvedVersionRangeConsistentlyYieldsNullVersions() throws Exception { + void nonResolvedVersionRangeConsistentlyYieldsNullVersions() throws Exception { VersionRange vr = VersionRange.createFromVersionSpec("[1.0,2.0)"); artifact = new DefaultArtifact(groupId, artifactId, vr, scope, type, null, artifactHandler); - assertNull(artifact.getVersion()); - assertNull(artifact.getBaseVersion()); + assertThat(artifact.getVersion()).isNull(); + assertThat(artifact.getBaseVersion()).isNull(); } @Test - void testMNG7780() throws Exception { + void mng7780() throws Exception { VersionRange vr = VersionRange.createFromVersionSpec("[1.0,2.0)"); artifact = new DefaultArtifact(groupId, artifactId, vr, scope, type, null, artifactHandler); - assertNull(artifact.getVersion()); - assertNull(artifact.getBaseVersion()); + assertThat(artifact.getVersion()).isNull(); + assertThat(artifact.getBaseVersion()).isNull(); DefaultArtifact nullVersionArtifact = new DefaultArtifact(groupId, artifactId, vr, scope, type, null, artifactHandler); - assertEquals(artifact, nullVersionArtifact); + assertThat(nullVersionArtifact).isEqualTo(artifact); } @ParameterizedTest @MethodSource("invalidMavenCoordinates") - void testIllegalCoordinatesInConstructor(String groupId, String artifactId, String version) { - assertThrows( - InvalidArtifactRTException.class, - () -> new DefaultArtifact( - groupId, artifactId, version, scope, type, classifier, artifactHandler, false)); + void illegalCoordinatesInConstructor(String groupId, String artifactId, String version) { + assertThatExceptionOfType(InvalidArtifactRTException.class).isThrownBy(() -> new DefaultArtifact( + groupId, artifactId, version, scope, type, classifier, artifactHandler, false)); if (version == null) { - assertThrows( - InvalidArtifactRTException.class, - () -> new DefaultArtifact( - groupId, artifactId, (VersionRange) null, scope, type, classifier, artifactHandler, false)); + assertThatExceptionOfType(InvalidArtifactRTException.class).isThrownBy(() -> new DefaultArtifact( + groupId, artifactId, (VersionRange) null, scope, type, classifier, artifactHandler, false)); } } diff --git a/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionIT.java b/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionIT.java index a78591dafd76..929953c3147f 100644 --- a/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionIT.java +++ b/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionIT.java @@ -30,7 +30,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; class ComparableVersionIT { @@ -52,7 +52,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO }); try { - assertEquals(0, p.waitFor(), "Unexpected exit code"); + assertThat(p.waitFor()).as("Unexpected exit code").isEqualTo(0); } catch (InterruptedException e) { throw new InterruptedIOException(e.toString()); } diff --git a/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java b/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java index 11561aa16689..a8b2812ea1d4 100644 --- a/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java +++ b/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java @@ -22,8 +22,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Test ComparableVersion. @@ -35,10 +34,7 @@ private ComparableVersion newComparable(String version) { String canonical = ret.getCanonical(); String parsedCanonical = new ComparableVersion(canonical).getCanonical(); - assertEquals( - canonical, - parsedCanonical, - "canonical( " + version + " ) = " + canonical + " -> canonical: " + parsedCanonical); + assertThat(parsedCanonical).as("canonical( " + version + " ) = " + canonical + " -> canonical: " + parsedCanonical).isEqualTo(canonical); return ret; } @@ -83,8 +79,8 @@ private void checkVersionsOrder(String[] versions) { Comparable low = c[i - 1]; for (int j = i; j < versions.length; j++) { Comparable high = c[j]; - assertTrue(low.compareTo(high) < 0, "expected " + low + " < " + high); - assertTrue(high.compareTo(low) > 0, "expected " + high + " > " + low); + assertThat(low.compareTo(high) < 0).as("expected " + low + " < " + high).isTrue(); + assertThat(high.compareTo(low) > 0).as("expected " + high + " > " + low).isTrue(); } } } @@ -92,18 +88,18 @@ private void checkVersionsOrder(String[] versions) { private void checkVersionsEqual(String v1, String v2) { Comparable c1 = newComparable(v1); Comparable c2 = newComparable(v2); - assertEquals(0, c1.compareTo(c2), "expected " + v1 + " == " + v2); - assertEquals(0, c2.compareTo(c1), "expected " + v2 + " == " + v1); - assertEquals(c1.hashCode(), c2.hashCode(), "expected same hashcode for " + v1 + " and " + v2); - assertEquals(c1, c2, "expected " + v1 + ".equals( " + v2 + " )"); - assertEquals(c2, c1, "expected " + v2 + ".equals( " + v1 + " )"); + assertThat(c1.compareTo(c2)).as("expected " + v1 + " == " + v2).isEqualTo(0); + assertThat(c2.compareTo(c1)).as("expected " + v2 + " == " + v1).isEqualTo(0); + assertThat(c2.hashCode()).as("expected same hashcode for " + v1 + " and " + v2).isEqualTo(c1.hashCode()); + assertThat(c2).as("expected " + v1 + ".equals( " + v2 + " )").isEqualTo(c1); + assertThat(c1).as("expected " + v2 + ".equals( " + v1 + " )").isEqualTo(c2); } private void checkVersionsHaveSameOrder(String v1, String v2) { ComparableVersion c1 = new ComparableVersion(v1); ComparableVersion c2 = new ComparableVersion(v2); - assertEquals(0, c1.compareTo(c2), "expected " + v1 + " == " + v2); - assertEquals(0, c2.compareTo(c1), "expected " + v2 + " == " + v1); + assertThat(c1.compareTo(c2)).as("expected " + v1 + " == " + v2).isEqualTo(0); + assertThat(c2.compareTo(c1)).as("expected " + v2 + " == " + v1).isEqualTo(0); } private void checkVersionsArrayEqual(String[] array) { @@ -118,22 +114,22 @@ private void checkVersionsArrayEqual(String[] array) { private void checkVersionsOrder(String v1, String v2) { Comparable c1 = newComparable(v1); Comparable c2 = newComparable(v2); - assertTrue(c1.compareTo(c2) < 0, "expected " + v1 + " < " + v2); - assertTrue(c2.compareTo(c1) > 0, "expected " + v2 + " > " + v1); + assertThat(c1.compareTo(c2) < 0).as("expected " + v1 + " < " + v2).isTrue(); + assertThat(c2.compareTo(c1) > 0).as("expected " + v2 + " > " + v1).isTrue(); } @Test - void testVersionsQualifier() { + void versionsQualifier() { checkVersionsOrder(VERSIONS_QUALIFIER); } @Test - void testVersionsNumber() { + void versionsNumber() { checkVersionsOrder(VERSIONS_NUMBER); } @Test - void testVersionsEqual() { + void versionsEqual() { newComparable("1.0-alpha"); checkVersionsEqual("1", "1"); checkVersionsEqual("1", "1.0"); @@ -173,7 +169,7 @@ void testVersionsEqual() { } @Test - void testVersionsHaveSameOrderButAreNotEqual() { + void versionsHaveSameOrderButAreNotEqual() { checkVersionsHaveSameOrder("1ga", "1"); checkVersionsHaveSameOrder("1release", "1"); checkVersionsHaveSameOrder("1final", "1"); @@ -188,7 +184,7 @@ void testVersionsHaveSameOrderButAreNotEqual() { } @Test - void testVersionComparing() { + void versionComparing() { checkVersionsOrder("1", "2"); checkVersionsOrder("1.5", "2"); checkVersionsOrder("1", "2.5"); @@ -219,30 +215,30 @@ void testVersionComparing() { } @Test - void testLeadingZeroes() { + void leadingZeroes() { checkVersionsOrder("0.7", "2"); checkVersionsOrder("0.2", "1.0.7"); } @Test - void testDigitGreaterThanNonAscii() { + void digitGreaterThanNonAscii() { ComparableVersion c1 = new ComparableVersion("1"); ComparableVersion c2 = new ComparableVersion("é"); - assertTrue(c1.compareTo(c2) > 0, "expected " + "1" + " > " + "\uD835\uDFE4"); - assertTrue(c2.compareTo(c1) < 0, "expected " + "\uD835\uDFE4" + " < " + "1"); + assertThat(c1.compareTo(c2) > 0).as("expected " + "1" + " > " + "\uD835\uDFE4").isTrue(); + assertThat(c2.compareTo(c1) < 0).as("expected " + "\uD835\uDFE4" + " < " + "1").isTrue(); } @Test - void testDigitGreaterThanNonBmpCharacters() { + void digitGreaterThanNonBmpCharacters() { ComparableVersion c1 = new ComparableVersion("1"); // MATHEMATICAL SANS-SERIF DIGIT TWO ComparableVersion c2 = new ComparableVersion("\uD835\uDFE4"); - assertTrue(c1.compareTo(c2) > 0, "expected " + "1" + " > " + "\uD835\uDFE4"); - assertTrue(c2.compareTo(c1) < 0, "expected " + "\uD835\uDFE4" + " < " + "1"); + assertThat(c1.compareTo(c2) > 0).as("expected " + "1" + " > " + "\uD835\uDFE4").isTrue(); + assertThat(c2.compareTo(c1) < 0).as("expected " + "\uD835\uDFE4" + " < " + "1").isTrue(); } @Test - void testGetCanonical() { + void getCanonical() { // MNG-7700 newComparable("0.x"); newComparable("0-x"); @@ -250,73 +246,73 @@ void testGetCanonical() { newComparable("0-1"); ComparableVersion version = new ComparableVersion("0.x"); - assertEquals("x", version.getCanonical()); + assertThat(version.getCanonical()).isEqualTo("x"); ComparableVersion version2 = new ComparableVersion("0.2"); - assertEquals("0.2", version2.getCanonical()); + assertThat(version2.getCanonical()).isEqualTo("0.2"); } @Test - void testLexicographicASCIISortOrder() { // Required by Semver 1.0 + void lexicographicASCIISortOrder() { // Required by Semver 1.0 ComparableVersion lower = new ComparableVersion("1.0.0-alpha1"); ComparableVersion upper = new ComparableVersion("1.0.0-ALPHA1"); // Lower case is equal to upper case. This is *NOT* what Semver 1.0 // specifies. Here we are explicitly deviating from Semver 1.0. - assertTrue(upper.compareTo(lower) == 0, "expected 1.0.0-ALPHA1 == 1.0.0-alpha1"); - assertTrue(lower.compareTo(upper) == 0, "expected 1.0.0-alpha1 == 1.0.0-ALPHA1"); + assertThat(upper.compareTo(lower)).as("expected 1.0.0-ALPHA1 == 1.0.0-alpha1").isEqualTo(0); + assertThat(lower.compareTo(upper)).as("expected 1.0.0-alpha1 == 1.0.0-ALPHA1").isEqualTo(0); } @Test - void testCompareLowerCaseToUpperCaseASCII() { + void compareLowerCaseToUpperCaseASCII() { ComparableVersion lower = new ComparableVersion("1.a"); ComparableVersion upper = new ComparableVersion("1.A"); // Lower case is equal to upper case - assertTrue(upper.compareTo(lower) == 0, "expected 1.A == 1.a"); - assertTrue(lower.compareTo(upper) == 0, "expected 1.a == 1.A"); + assertThat(upper.compareTo(lower)).as("expected 1.A == 1.a").isEqualTo(0); + assertThat(lower.compareTo(upper)).as("expected 1.a == 1.A").isEqualTo(0); } @Test - void testCompareLowerCaseToUpperCaseNonASCII() { + void compareLowerCaseToUpperCaseNonASCII() { ComparableVersion lower = new ComparableVersion("1.é"); ComparableVersion upper = new ComparableVersion("1.É"); // Lower case is equal to upper case - assertTrue(upper.compareTo(lower) == 0, "expected 1.É < 1.é"); - assertTrue(lower.compareTo(upper) == 0, "expected 1.é > 1.É"); + assertThat(upper.compareTo(lower)).as("expected 1.É < 1.é").isEqualTo(0); + assertThat(lower.compareTo(upper)).as("expected 1.é > 1.É").isEqualTo(0); } @Test - void testCompareDigitToLetter() { + void compareDigitToLetter() { ComparableVersion seven = new ComparableVersion("7"); ComparableVersion capitalJ = new ComparableVersion("J"); ComparableVersion lowerCaseC = new ComparableVersion("c"); // Digits are greater than letters - assertTrue(seven.compareTo(capitalJ) > 0, "expected 7 > J"); - assertTrue(capitalJ.compareTo(seven) < 0, "expected J < 1"); - assertTrue(seven.compareTo(lowerCaseC) > 0, "expected 7 > c"); - assertTrue(lowerCaseC.compareTo(seven) < 0, "expected c < 7"); + assertThat(seven.compareTo(capitalJ) > 0).as("expected 7 > J").isTrue(); + assertThat(capitalJ.compareTo(seven) < 0).as("expected J < 1").isTrue(); + assertThat(seven.compareTo(lowerCaseC) > 0).as("expected 7 > c").isTrue(); + assertThat(lowerCaseC.compareTo(seven) < 0).as("expected c < 7").isTrue(); } @Test - void testNonAsciiDigits() { // These should not be treated as digits. + void nonAsciiDigits() { // These should not be treated as digits. ComparableVersion asciiOne = new ComparableVersion("1"); ComparableVersion arabicEight = new ComparableVersion("\u0668"); ComparableVersion asciiNine = new ComparableVersion("9"); - assertTrue(asciiOne.compareTo(arabicEight) > 0, "expected " + "1" + " > " + "\u0668"); - assertTrue(arabicEight.compareTo(asciiOne) < 0, "expected " + "\u0668" + " < " + "1"); - assertTrue(asciiNine.compareTo(arabicEight) > 0, "expected " + "9" + " > " + "\u0668"); - assertTrue(arabicEight.compareTo(asciiNine) < 0, "expected " + "\u0668" + " < " + "9"); + assertThat(asciiOne.compareTo(arabicEight) > 0).as("expected " + "1" + " > " + "\u0668").isTrue(); + assertThat(arabicEight.compareTo(asciiOne) < 0).as("expected " + "\u0668" + " < " + "1").isTrue(); + assertThat(asciiNine.compareTo(arabicEight) > 0).as("expected " + "9" + " > " + "\u0668").isTrue(); + assertThat(arabicEight.compareTo(asciiNine) < 0).as("expected " + "\u0668" + " < " + "9").isTrue(); } @Test - void testLexicographicOrder() { + void lexicographicOrder() { ComparableVersion aardvark = new ComparableVersion("aardvark"); ComparableVersion zebra = new ComparableVersion("zebra"); - assertTrue(zebra.compareTo(aardvark) > 0); - assertTrue(aardvark.compareTo(zebra) < 0); + assertThat(zebra.compareTo(aardvark) > 0).isTrue(); + assertThat(aardvark.compareTo(zebra) < 0).isTrue(); // Greek zebra ComparableVersion greek = new ComparableVersion("ζέβρα"); - assertTrue(greek.compareTo(zebra) > 0); - assertTrue(zebra.compareTo(greek) < 0); + assertThat(greek.compareTo(zebra) > 0).isTrue(); + assertThat(zebra.compareTo(greek) < 0).isTrue(); } /** @@ -327,7 +323,7 @@ void testLexicographicOrder() { * 226100 */ @Test - void testMng5568() { + void mng5568() { String a = "6.1.0"; String b = "6.1.0rc3"; String c = "6.1H.5-beta"; // this is the unusual version string, with 'H' in the middle @@ -341,7 +337,7 @@ void testMng5568() { * Test MNG-6572 optimization. */ @Test - void testMng6572() { + void mng6572() { String a = "20190126.230843"; // resembles a SNAPSHOT String b = "1234567890.12345"; // 10 digit number String c = "123456789012345.1H.5-beta"; // 15 digit number @@ -360,7 +356,7 @@ void testMng6572() { * (related to MNG-6572 optimization) */ @Test - void testVersionEqualWithLeadingZeroes() { + void versionEqualWithLeadingZeroes() { // versions with string lengths from 1 to 19 String[] arr = new String[] { "0000000000000000001", @@ -392,7 +388,7 @@ void testVersionEqualWithLeadingZeroes() { * (related to MNG-6572 optimization) */ @Test - void testVersionZeroEqualWithLeadingZeroes() { + void versionZeroEqualWithLeadingZeroes() { // versions with string lengths from 1 to 19 String[] arr = new String[] { "0000000000000000000", @@ -424,7 +420,7 @@ void testVersionZeroEqualWithLeadingZeroes() { * for qualifiers that start with "-0.", which was showing A == C and B == C but A < B. */ @Test - void testMng6964() { + void mng6964() { String a = "1-0.alpha"; String b = "1-0.beta"; String c = "1"; @@ -435,7 +431,7 @@ void testMng6964() { } @Test - void testLocaleIndependent() { + void localeIndependent() { Locale orig = Locale.getDefault(); Locale[] locales = {Locale.ENGLISH, new Locale("tr"), Locale.getDefault()}; try { @@ -449,13 +445,13 @@ void testLocaleIndependent() { } @Test - void testReuse() { + void reuse() { ComparableVersion c1 = new ComparableVersion("1"); c1.parseVersion("2"); Comparable c2 = newComparable("2"); - assertEquals(c1, c2, "reused instance should be equivalent to new instance"); + assertThat(c2).as("reused instance should be equivalent to new instance").isEqualTo(c1); } /** @@ -464,7 +460,7 @@ void testReuse() { * 1.0.0.X1 < 1.0.0-X2 for any string X */ @Test - void testMng7644() { + void mng7644() { for (String x : new String[] {"abc", "alpha", "a", "beta", "b", "def", "milestone", "m", "RC"}) { // 1.0.0.X1 < 1.0.0-X2 for any string x checkVersionsOrder("1.0.0." + x + "1", "1.0.0-" + x + "2"); @@ -476,13 +472,13 @@ void testMng7644() { } @Test - public void testMng7714() { + void mng7714() { ComparableVersion f = new ComparableVersion("1.0.final-redhat"); ComparableVersion sp1 = new ComparableVersion("1.0-sp1-redhat"); ComparableVersion sp2 = new ComparableVersion("1.0-sp-1-redhat"); ComparableVersion sp3 = new ComparableVersion("1.0-sp.1-redhat"); - assertTrue(f.compareTo(sp1) < 0, "expected " + f + " < " + sp1); - assertTrue(f.compareTo(sp2) < 0, "expected " + f + " < " + sp2); - assertTrue(f.compareTo(sp3) < 0, "expected " + f + " < " + sp3); + assertThat(f.compareTo(sp1) < 0).as("expected " + f + " < " + sp1).isTrue(); + assertThat(f.compareTo(sp2) < 0).as("expected " + f + " < " + sp2).isTrue(); + assertThat(f.compareTo(sp3) < 0).as("expected " + f + " < " + sp3).isTrue(); } } diff --git a/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java b/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java index 370b0f0c5cc3..7ed25d03bfe4 100644 --- a/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java +++ b/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -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.assertj.core.api.Assertions.assertThat; /** * Test DefaultArtifactVersion. @@ -39,16 +37,16 @@ private void checkVersionParsing( String parsed = "'" + version + "' parsed as ('" + artifactVersion.getMajorVersion() + "', '" + artifactVersion.getMinorVersion() + "', '" + artifactVersion.getIncrementalVersion() + "', '" + artifactVersion.getBuildNumber() + "', '" + artifactVersion.getQualifier() + "'), "; - assertEquals(major, artifactVersion.getMajorVersion(), parsed + "check major version"); - assertEquals(minor, artifactVersion.getMinorVersion(), parsed + "check minor version"); - assertEquals(incremental, artifactVersion.getIncrementalVersion(), parsed + "check incremental version"); - assertEquals(buildnumber, artifactVersion.getBuildNumber(), parsed + "check build number"); - assertEquals(qualifier, artifactVersion.getQualifier(), parsed + "check qualifier"); - assertEquals(version, artifactVersion.toString(), "check " + version + " string value"); + assertThat(artifactVersion.getMajorVersion()).as(parsed + "check major version").isEqualTo(major); + assertThat(artifactVersion.getMinorVersion()).as(parsed + "check minor version").isEqualTo(minor); + assertThat(artifactVersion.getIncrementalVersion()).as(parsed + "check incremental version").isEqualTo(incremental); + assertThat(artifactVersion.getBuildNumber()).as(parsed + "check build number").isEqualTo(buildnumber); + assertThat(artifactVersion.getQualifier()).as(parsed + "check qualifier").isEqualTo(qualifier); + assertThat(artifactVersion.toString()).as("check " + version + " string value").isEqualTo(version); } @Test - void testVersionParsing() { + void versionParsing() { checkVersionParsing("1", 1, 0, 0, 0, null); checkVersionParsing("1.2", 1, 2, 0, 0, null); checkVersionParsing("1.2.3", 1, 2, 3, 0, null); @@ -85,7 +83,7 @@ void testVersionParsing() { } @Test - void testVersionComparing() { + void versionComparing() { assertVersionEqual("1", "1"); assertVersionOlder("1", "2"); assertVersionOlder("1.5", "2"); @@ -132,7 +130,7 @@ void testVersionComparing() { } @Test - void testVersionSnapshotComparing() { + void versionSnapshotComparing() { assertVersionEqual("1-SNAPSHOT", "1-SNAPSHOT"); assertVersionOlder("1-SNAPSHOT", "2-SNAPSHOT"); assertVersionOlder("1.5-SNAPSHOT", "2-SNAPSHOT"); @@ -166,7 +164,7 @@ void testVersionSnapshotComparing() { } @Test - void testSnapshotVsReleases() { + void snapshotVsReleases() { assertVersionOlder("1.0-RC1", "1.0-SNAPSHOT"); assertVersionOlder("1.0-rc1", "1.0-SNAPSHOT"); assertVersionOlder("1.0-rc-1", "1.0-SNAPSHOT"); @@ -176,35 +174,27 @@ void testSnapshotVsReleases() { void testHashCode() { ArtifactVersion v1 = newArtifactVersion("1"); ArtifactVersion v2 = newArtifactVersion("1.0"); - assertTrue(v1.equals(v2)); - assertEquals(v1.hashCode(), v2.hashCode()); + assertThat(v2).isEqualTo(v1); + assertThat(v2.hashCode()).isEqualTo(v1.hashCode()); } @Test - void testEqualsNullSafe() { - assertFalse(newArtifactVersion("1").equals(null)); + void equalsNullSafe() { + assertThat(newArtifactVersion("1")).isNotEqualTo(null); } @Test - void testEqualsTypeSafe() { - assertFalse(newArtifactVersion("1").equals("non-an-artifact-version-instance")); + void equalsTypeSafe() { + assertThat(newArtifactVersion("1")).isNotEqualTo("non-an-artifact-version-instance"); } private void assertVersionOlder(String left, String right) { - assertTrue( - newArtifactVersion(left).compareTo(newArtifactVersion(right)) < 0, - left + " should be older than " + right); - assertTrue( - newArtifactVersion(right).compareTo(newArtifactVersion(left)) > 0, - right + " should be newer than " + left); + assertThat(newArtifactVersion(left).compareTo(newArtifactVersion(right)) < 0).as(left + " should be older than " + right).isTrue(); + assertThat(newArtifactVersion(right).compareTo(newArtifactVersion(left)) > 0).as(right + " should be newer than " + left).isTrue(); } private void assertVersionEqual(String left, String right) { - assertTrue( - newArtifactVersion(left).compareTo(newArtifactVersion(right)) == 0, - left + " should be equal to " + right); - assertTrue( - newArtifactVersion(right).compareTo(newArtifactVersion(left)) == 0, - right + " should be equal to " + left); + assertThat(newArtifactVersion(left).compareTo(newArtifactVersion(right))).as(left + " should be equal to " + right).isEqualTo(0); + assertThat(newArtifactVersion(right).compareTo(newArtifactVersion(left))).as(right + " should be equal to " + left).isEqualTo(0); } } diff --git a/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java b/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java index 8ccf5bcca4f2..49886fcecbdd 100644 --- a/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java +++ b/compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java @@ -23,12 +23,8 @@ import org.apache.maven.artifact.Artifact; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; /** * Tests version range construction. @@ -52,118 +48,118 @@ class VersionRangeTest { private static final String CHECK_SELECTED_VERSION = "check selected version"; @Test - void testRange() throws InvalidVersionSpecificationException, OverConstrainedVersionException { + void range() throws InvalidVersionSpecificationException, OverConstrainedVersionException { Artifact artifact = null; VersionRange range = VersionRange.createFromVersionSpec("(,1.0]"); List restrictions = range.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); Restriction restriction = restrictions.get(0); - assertNull(restriction.getLowerBound(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); - assertNull(range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); - assertFalse(range.isSelectedVersionKnown(artifact), CHECK_SELECTED_VERSION_KNOWN); - assertNull(range.getSelectedVersion(artifact), CHECK_SELECTED_VERSION); + assertThat(restriction.getLowerBound()).as(CHECK_LOWER_BOUND).isNull(); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.0"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); + assertThat(range.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); + assertThat(range.isSelectedVersionKnown(artifact)).as(CHECK_SELECTED_VERSION_KNOWN).isFalse(); + assertThat(range.getSelectedVersion(artifact)).as(CHECK_SELECTED_VERSION).isNull(); range = VersionRange.createFromVersionSpec("1.0"); - assertEquals("1.0", range.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION); + assertThat(range.getRecommendedVersion().toString()).as(CHECK_VERSION_RECOMMENDATION).isEqualTo("1.0"); restrictions = range.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertNull(restriction.getLowerBound(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertNull(restriction.getUpperBound(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); - assertTrue(range.isSelectedVersionKnown(artifact), CHECK_SELECTED_VERSION_KNOWN); - assertEquals("1.0", range.getSelectedVersion(artifact).toString(), CHECK_SELECTED_VERSION); + assertThat(restriction.getLowerBound()).as(CHECK_LOWER_BOUND).isNull(); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound()).as(CHECK_UPPER_BOUND).isNull(); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); + assertThat(range.isSelectedVersionKnown(artifact)).as(CHECK_SELECTED_VERSION_KNOWN).isTrue(); + assertThat(range.getSelectedVersion(artifact).toString()).as(CHECK_SELECTED_VERSION).isEqualTo("1.0"); range = VersionRange.createFromVersionSpec("[1.0]"); restrictions = range.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.0", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); - assertNull(range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); - assertFalse(range.isSelectedVersionKnown(artifact), CHECK_SELECTED_VERSION_KNOWN); - assertNull(range.getSelectedVersion(artifact), CHECK_SELECTED_VERSION); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.0"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.0"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); + assertThat(range.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); + assertThat(range.isSelectedVersionKnown(artifact)).as(CHECK_SELECTED_VERSION_KNOWN).isFalse(); + assertThat(range.getSelectedVersion(artifact)).as(CHECK_SELECTED_VERSION).isNull(); range = VersionRange.createFromVersionSpec("[1.2,1.3]"); restrictions = range.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); - assertNull(range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); - assertFalse(range.isSelectedVersionKnown(artifact), CHECK_SELECTED_VERSION_KNOWN); - assertNull(range.getSelectedVersion(artifact), CHECK_SELECTED_VERSION); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); + assertThat(range.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); + assertThat(range.isSelectedVersionKnown(artifact)).as(CHECK_SELECTED_VERSION_KNOWN).isFalse(); + assertThat(range.getSelectedVersion(artifact)).as(CHECK_SELECTED_VERSION).isNull(); range = VersionRange.createFromVersionSpec("[1.0,2.0)"); restrictions = range.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.0", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("2.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); - assertNull(range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); - assertFalse(range.isSelectedVersionKnown(artifact), CHECK_SELECTED_VERSION_KNOWN); - assertNull(range.getSelectedVersion(artifact), CHECK_SELECTED_VERSION); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.0"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("2.0"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); + assertThat(range.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); + assertThat(range.isSelectedVersionKnown(artifact)).as(CHECK_SELECTED_VERSION_KNOWN).isFalse(); + assertThat(range.getSelectedVersion(artifact)).as(CHECK_SELECTED_VERSION).isNull(); range = VersionRange.createFromVersionSpec("[1.5,)"); restrictions = range.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.5", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertNull(restriction.getUpperBound(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); - assertNull(range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); - assertFalse(range.isSelectedVersionKnown(artifact), CHECK_SELECTED_VERSION_KNOWN); - assertNull(range.getSelectedVersion(artifact), CHECK_SELECTED_VERSION); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.5"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound()).as(CHECK_UPPER_BOUND).isNull(); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); + assertThat(range.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); + assertThat(range.isSelectedVersionKnown(artifact)).as(CHECK_SELECTED_VERSION_KNOWN).isFalse(); + assertThat(range.getSelectedVersion(artifact)).as(CHECK_SELECTED_VERSION).isNull(); range = VersionRange.createFromVersionSpec("(,1.0],[1.2,)"); restrictions = range.getRestrictions(); - assertEquals(2, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(2); restriction = restrictions.get(0); - assertNull(restriction.getLowerBound(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); - assertNull(range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(restriction.getLowerBound()).as(CHECK_LOWER_BOUND).isNull(); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.0"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); + assertThat(range.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restriction = restrictions.get(1); - assertEquals("1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertNull(restriction.getUpperBound(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); - assertNull(range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); - assertFalse(range.isSelectedVersionKnown(artifact), CHECK_SELECTED_VERSION_KNOWN); - assertNull(range.getSelectedVersion(artifact), CHECK_SELECTED_VERSION); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound()).as(CHECK_UPPER_BOUND).isNull(); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); + assertThat(range.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); + assertThat(range.isSelectedVersionKnown(artifact)).as(CHECK_SELECTED_VERSION_KNOWN).isFalse(); + assertThat(range.getSelectedVersion(artifact)).as(CHECK_SELECTED_VERSION).isNull(); range = VersionRange.createFromVersionSpec("[1.0,)"); - assertFalse(range.containsVersion(new DefaultArtifactVersion("1.0-SNAPSHOT"))); + assertThat(range.containsVersion(new DefaultArtifactVersion("1.0-SNAPSHOT"))).isFalse(); range = VersionRange.createFromVersionSpec("[1.0,1.1-SNAPSHOT]"); - assertTrue(range.containsVersion(new DefaultArtifactVersion("1.1-SNAPSHOT"))); + assertThat(range.containsVersion(new DefaultArtifactVersion("1.1-SNAPSHOT"))).isTrue(); range = VersionRange.createFromVersionSpec("[5.0.9.0,5.0.10.0)"); - assertTrue(range.containsVersion(new DefaultArtifactVersion("5.0.9.0"))); + assertThat(range.containsVersion(new DefaultArtifactVersion("5.0.9.0"))).isTrue(); } @Test - void testSameUpperAndLowerBoundRoundtrip() throws InvalidVersionSpecificationException { + void sameUpperAndLowerBoundRoundtrip() throws InvalidVersionSpecificationException { VersionRange range = VersionRange.createFromVersionSpec("[1.0]"); VersionRange range2 = VersionRange.createFromVersionSpec(range.toString()); - assertEquals(range, range2); + assertThat(range2).isEqualTo(range); } @Test - void testInvalidRanges() { + void invalidRanges() { checkInvalidRange("(1.0)"); checkInvalidRange("[1.0)"); checkInvalidRange("(1.0]"); @@ -182,535 +178,532 @@ void testInvalidRanges() { @Test @SuppressWarnings("checkstyle:MethodLength") - void testIntersections() throws InvalidVersionSpecificationException { + void intersections() throws InvalidVersionSpecificationException { VersionRange range1 = VersionRange.createFromVersionSpec("1.0"); VersionRange range2 = VersionRange.createFromVersionSpec("1.1"); VersionRange mergedRange = range1.restrict(range2); // TODO current policy is to retain the original version - is this correct, do we need strategies or is that // handled elsewhere? // assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION ); - assertEquals("1.0", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion().toString()).as(CHECK_VERSION_RECOMMENDATION).isEqualTo("1.0"); List restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); Restriction restriction = restrictions.get(0); - assertNull(restriction.getLowerBound(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertNull(restriction.getUpperBound(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound()).as(CHECK_LOWER_BOUND).isNull(); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound()).as(CHECK_UPPER_BOUND).isNull(); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); mergedRange = range2.restrict(range1); - assertEquals("1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion().toString()).as(CHECK_VERSION_RECOMMENDATION).isEqualTo("1.1"); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertNull(restriction.getLowerBound(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertNull(restriction.getUpperBound(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound()).as(CHECK_LOWER_BOUND).isNull(); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound()).as(CHECK_UPPER_BOUND).isNull(); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); // TODO test reversed restrictions on all below range1 = VersionRange.createFromVersionSpec("[1.0,)"); range2 = VersionRange.createFromVersionSpec("1.1"); mergedRange = range1.restrict(range2); - assertEquals("1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion().toString()).as(CHECK_VERSION_RECOMMENDATION).isEqualTo("1.1"); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.0", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertNull(restriction.getUpperBound(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.0"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound()).as(CHECK_UPPER_BOUND).isNull(); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); range1 = VersionRange.createFromVersionSpec("[1.1,)"); range2 = VersionRange.createFromVersionSpec("1.1"); mergedRange = range1.restrict(range2); - assertEquals("1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion().toString()).as(CHECK_VERSION_RECOMMENDATION).isEqualTo("1.1"); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertNull(restriction.getUpperBound(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound()).as(CHECK_UPPER_BOUND).isNull(); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); range1 = VersionRange.createFromVersionSpec("[1.1]"); range2 = VersionRange.createFromVersionSpec("1.1"); mergedRange = range1.restrict(range2); - assertEquals("1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion().toString()).as(CHECK_VERSION_RECOMMENDATION).isEqualTo("1.1"); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getLowerBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("(1.1,)"); range2 = VersionRange.createFromVersionSpec("1.1"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertNull(restriction.getUpperBound(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound()).as(CHECK_UPPER_BOUND).isNull(); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); range1 = VersionRange.createFromVersionSpec("[1.2,)"); range2 = VersionRange.createFromVersionSpec("1.1"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertNull(restriction.getUpperBound(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound()).as(CHECK_UPPER_BOUND).isNull(); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); range1 = VersionRange.createFromVersionSpec("(,1.2]"); range2 = VersionRange.createFromVersionSpec("1.1"); mergedRange = range1.restrict(range2); - assertEquals("1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion().toString()).as(CHECK_VERSION_RECOMMENDATION).isEqualTo("1.1"); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertNull(restriction.getLowerBound(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound()).as(CHECK_LOWER_BOUND).isNull(); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("(,1.1]"); range2 = VersionRange.createFromVersionSpec("1.1"); mergedRange = range1.restrict(range2); - assertEquals("1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion().toString()).as(CHECK_VERSION_RECOMMENDATION).isEqualTo("1.1"); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertNull(restriction.getLowerBound(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound()).as(CHECK_LOWER_BOUND).isNull(); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("(,1.1)"); range2 = VersionRange.createFromVersionSpec("1.1"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertNull(restriction.getLowerBound(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound()).as(CHECK_LOWER_BOUND).isNull(); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); range1 = VersionRange.createFromVersionSpec("(,1.0]"); range2 = VersionRange.createFromVersionSpec("1.1"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertNull(restriction.getLowerBound(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound()).as(CHECK_LOWER_BOUND).isNull(); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.0"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("(,1.0], [1.1,)"); range2 = VersionRange.createFromVersionSpec("1.2"); mergedRange = range1.restrict(range2); - assertEquals("1.2", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion().toString()).as(CHECK_VERSION_RECOMMENDATION).isEqualTo("1.2"); restrictions = mergedRange.getRestrictions(); - assertEquals(2, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(2); restriction = restrictions.get(0); - assertNull(restriction.getLowerBound(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound()).as(CHECK_LOWER_BOUND).isNull(); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.0"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); restriction = restrictions.get(1); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertNull(restriction.getUpperBound(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound()).as(CHECK_UPPER_BOUND).isNull(); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); range1 = VersionRange.createFromVersionSpec("(,1.0], [1.1,)"); range2 = VersionRange.createFromVersionSpec("1.0.5"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(2, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(2); restriction = restrictions.get(0); - assertNull(restriction.getLowerBound(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound()).as(CHECK_LOWER_BOUND).isNull(); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.0"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); restriction = restrictions.get(1); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertNull(restriction.getUpperBound(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound()).as(CHECK_UPPER_BOUND).isNull(); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); range1 = VersionRange.createFromVersionSpec("(,1.1), (1.1,)"); range2 = VersionRange.createFromVersionSpec("1.1"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(2, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(2); restriction = restrictions.get(0); - assertNull(restriction.getLowerBound(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound()).as(CHECK_LOWER_BOUND).isNull(); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); restriction = restrictions.get(1); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertNull(restriction.getUpperBound(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound()).as(CHECK_UPPER_BOUND).isNull(); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); range1 = VersionRange.createFromVersionSpec("[1.1,1.3]"); range2 = VersionRange.createFromVersionSpec("(1.1,)"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("(,1.3)"); range2 = VersionRange.createFromVersionSpec("[1.2,1.3]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); range1 = VersionRange.createFromVersionSpec("[1.1,1.3]"); range2 = VersionRange.createFromVersionSpec("[1.2,)"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("(,1.3]"); range2 = VersionRange.createFromVersionSpec("[1.2,1.4]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("(1.2,1.3]"); range2 = VersionRange.createFromVersionSpec("[1.1,1.4]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("(1.2,1.3)"); range2 = VersionRange.createFromVersionSpec("[1.1,1.4]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); range1 = VersionRange.createFromVersionSpec("[1.2,1.3)"); range2 = VersionRange.createFromVersionSpec("[1.1,1.4]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); range1 = VersionRange.createFromVersionSpec("[1.0,1.1]"); range2 = VersionRange.createFromVersionSpec("[1.1,1.4]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("[1.0,1.1)"); range2 = VersionRange.createFromVersionSpec("[1.1,1.4]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(0, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(0); range1 = VersionRange.createFromVersionSpec("[1.0,1.2],[1.3,1.5]"); range2 = VersionRange.createFromVersionSpec("[1.1]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("[1.0,1.2],[1.3,1.5]"); range2 = VersionRange.createFromVersionSpec("[1.4]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); restriction = restrictions.get(0); - assertEquals("1.4", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.4"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.4"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("[1.0,1.2],[1.3,1.5]"); range2 = VersionRange.createFromVersionSpec("[1.1,1.4]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(2, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(2); restriction = restrictions.get(0); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); restriction = restrictions.get(1); - assertEquals("1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.4"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("[1.0,1.2),(1.3,1.5]"); range2 = VersionRange.createFromVersionSpec("[1.1,1.4]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(2, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(2); restriction = restrictions.get(0); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); restriction = restrictions.get(1); - assertEquals("1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.4"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("[1.0,1.2],[1.3,1.5]"); range2 = VersionRange.createFromVersionSpec("(1.1,1.4)"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(2, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(2); restriction = restrictions.get(0); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); restriction = restrictions.get(1); - assertEquals("1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.4"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); range1 = VersionRange.createFromVersionSpec("[1.0,1.2),(1.3,1.5]"); range2 = VersionRange.createFromVersionSpec("(1.1,1.4)"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(2, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(2); restriction = restrictions.get(0); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); restriction = restrictions.get(1); - assertEquals("1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertFalse(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertFalse(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isFalse(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.4"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isFalse(); range1 = VersionRange.createFromVersionSpec("(,1.1),(1.4,)"); range2 = VersionRange.createFromVersionSpec("[1.1,1.4]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(0, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(0); range1 = VersionRange.createFromVersionSpec("(,1.1],[1.4,)"); range2 = VersionRange.createFromVersionSpec("(1.1,1.4)"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(0, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(0); range1 = VersionRange.createFromVersionSpec("[,1.1],[1.4,]"); range2 = VersionRange.createFromVersionSpec("[1.2,1.3]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(0, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(0); range1 = VersionRange.createFromVersionSpec("[1.0,1.2],[1.3,1.5]"); range2 = VersionRange.createFromVersionSpec("[1.1,1.4],[1.6,]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(2, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(2); restriction = restrictions.get(0); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); restriction = restrictions.get(1); - assertEquals("1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.4"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("[1.0,1.2],[1.3,1.5]"); range2 = VersionRange.createFromVersionSpec("[1.1,1.4],[1.5,]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(3, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(3); restriction = restrictions.get(0); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); restriction = restrictions.get(1); - assertEquals("1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.4"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); restriction = restrictions.get(2); - assertEquals("1.5", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.5", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.5"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.5"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); range1 = VersionRange.createFromVersionSpec("[1.0,1.2],[1.3,1.7]"); range2 = VersionRange.createFromVersionSpec("[1.1,1.4],[1.5,1.6]"); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(3, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(3); restriction = restrictions.get(0); - assertEquals("1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.1"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.2"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); restriction = restrictions.get(1); - assertEquals("1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.3"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.4"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); restriction = restrictions.get(2); - assertEquals("1.5", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND); - assertTrue(restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE); - assertEquals("1.6", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND); - assertTrue(restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE); + assertThat(restriction.getLowerBound().toString()).as(CHECK_LOWER_BOUND).isEqualTo("1.5"); + assertThat(restriction.isLowerBoundInclusive()).as(CHECK_LOWER_BOUND_INCLUSIVE).isTrue(); + assertThat(restriction.getUpperBound().toString()).as(CHECK_UPPER_BOUND).isEqualTo("1.6"); + assertThat(restriction.isUpperBoundInclusive()).as(CHECK_UPPER_BOUND_INCLUSIVE).isTrue(); // test restricting empty sets range1 = VersionRange.createFromVersionSpec("[,1.1],[1.4,]"); range2 = VersionRange.createFromVersionSpec("[1.2,1.3]"); range1 = range1.restrict(range2); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(0, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(0); range1 = VersionRange.createFromVersionSpec("[,1.1],[1.4,]"); range2 = VersionRange.createFromVersionSpec("[1.2,1.3]"); range2 = range1.restrict(range2); mergedRange = range1.restrict(range2); - assertNull(mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION); + assertThat(mergedRange.getRecommendedVersion()).as(CHECK_VERSION_RECOMMENDATION).isNull(); restrictions = mergedRange.getRestrictions(); - assertEquals(0, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(0); } @Test - void testReleaseRangeBoundsContainsSnapshots() throws InvalidVersionSpecificationException { + void releaseRangeBoundsContainsSnapshots() throws InvalidVersionSpecificationException { VersionRange range = VersionRange.createFromVersionSpec("[1.0,1.2]"); - assertTrue(range.containsVersion(new DefaultArtifactVersion("1.1-SNAPSHOT"))); - assertTrue(range.containsVersion(new DefaultArtifactVersion("1.2-SNAPSHOT"))); - assertFalse(range.containsVersion(new DefaultArtifactVersion("1.0-SNAPSHOT"))); + assertThat(range.containsVersion(new DefaultArtifactVersion("1.1-SNAPSHOT"))).isTrue(); + assertThat(range.containsVersion(new DefaultArtifactVersion("1.2-SNAPSHOT"))).isTrue(); + assertThat(range.containsVersion(new DefaultArtifactVersion("1.0-SNAPSHOT"))).isFalse(); } @Test - void testSnapshotRangeBoundsCanContainSnapshots() throws InvalidVersionSpecificationException { + void snapshotRangeBoundsCanContainSnapshots() throws InvalidVersionSpecificationException { VersionRange range = VersionRange.createFromVersionSpec("[1.0,1.2-SNAPSHOT]"); - assertTrue(range.containsVersion(new DefaultArtifactVersion("1.1-SNAPSHOT"))); - assertTrue(range.containsVersion(new DefaultArtifactVersion("1.2-SNAPSHOT"))); + assertThat(range.containsVersion(new DefaultArtifactVersion("1.1-SNAPSHOT"))).isTrue(); + assertThat(range.containsVersion(new DefaultArtifactVersion("1.2-SNAPSHOT"))).isTrue(); range = VersionRange.createFromVersionSpec("[1.0-SNAPSHOT,1.2]"); - assertTrue(range.containsVersion(new DefaultArtifactVersion("1.0-SNAPSHOT"))); - assertTrue(range.containsVersion(new DefaultArtifactVersion("1.1-SNAPSHOT"))); + assertThat(range.containsVersion(new DefaultArtifactVersion("1.0-SNAPSHOT"))).isTrue(); + assertThat(range.containsVersion(new DefaultArtifactVersion("1.1-SNAPSHOT"))).isTrue(); } @Test - void testSnapshotSoftVersionCanContainSnapshot() throws InvalidVersionSpecificationException { + void snapshotSoftVersionCanContainSnapshot() throws InvalidVersionSpecificationException { VersionRange range = VersionRange.createFromVersionSpec("1.0-SNAPSHOT"); - assertTrue(range.containsVersion(new DefaultArtifactVersion("1.0-SNAPSHOT"))); + assertThat(range.containsVersion(new DefaultArtifactVersion("1.0-SNAPSHOT"))).isTrue(); } private void checkInvalidRange(String version) { - assertThrows( - InvalidVersionSpecificationException.class, - () -> VersionRange.createFromVersionSpec(version), - "Version " + version + " should have failed to construct"); + assertThatExceptionOfType(InvalidVersionSpecificationException.class).as("Version " + version + " should have failed to construct").isThrownBy(() -> VersionRange.createFromVersionSpec(version)); } @Test - void testContains() throws InvalidVersionSpecificationException { + void contains() throws InvalidVersionSpecificationException { ArtifactVersion actualVersion = new DefaultArtifactVersion("2.0.5"); - assertTrue(enforceVersion("2.0.5", actualVersion)); - assertTrue(enforceVersion("2.0.4", actualVersion)); - assertTrue(enforceVersion("[2.0.5]", actualVersion)); - assertFalse(enforceVersion("[2.0.6,)", actualVersion)); - assertFalse(enforceVersion("[2.0.6]", actualVersion)); - assertTrue(enforceVersion("[2.0,2.1]", actualVersion)); - assertFalse(enforceVersion("[2.0,2.0.3]", actualVersion)); - assertTrue(enforceVersion("[2.0,2.0.5]", actualVersion)); - assertFalse(enforceVersion("[2.0,2.0.5)", actualVersion)); + assertThat(enforceVersion("2.0.5", actualVersion)).isTrue(); + assertThat(enforceVersion("2.0.4", actualVersion)).isTrue(); + assertThat(enforceVersion("[2.0.5]", actualVersion)).isTrue(); + assertThat(enforceVersion("[2.0.6,)", actualVersion)).isFalse(); + assertThat(enforceVersion("[2.0.6]", actualVersion)).isFalse(); + assertThat(enforceVersion("[2.0,2.1]", actualVersion)).isTrue(); + assertThat(enforceVersion("[2.0,2.0.3]", actualVersion)).isFalse(); + assertThat(enforceVersion("[2.0,2.0.5]", actualVersion)).isTrue(); + assertThat(enforceVersion("[2.0,2.0.5)", actualVersion)).isFalse(); } public boolean enforceVersion(String requiredVersionRange, ArtifactVersion actualVersion) @@ -721,22 +714,20 @@ public boolean enforceVersion(String requiredVersionRange, ArtifactVersion actua } @Test - void testCache() throws InvalidVersionSpecificationException { + void cache() throws InvalidVersionSpecificationException { VersionRange range = VersionRange.createFromVersionSpec("[1.0,1.2]"); - assertSame(range, VersionRange.createFromVersionSpec("[1.0,1.2]")); // same instance from spec cache + assertThat(VersionRange.createFromVersionSpec("[1.0,1.2]")).isSameAs(range); // same instance from spec cache VersionRange spec = VersionRange.createFromVersionSpec("1.0"); - assertSame(spec, VersionRange.createFromVersionSpec("1.0")); // same instance from spec cache + assertThat(VersionRange.createFromVersionSpec("1.0")).isSameAs(spec); // same instance from spec cache List restrictions = spec.getRestrictions(); - assertEquals(1, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(1); VersionRange version = VersionRange.createFromVersion("1.0"); - assertSame(version, VersionRange.createFromVersion("1.0")); // same instance from version cache + assertThat(VersionRange.createFromVersion("1.0")).isSameAs(version); // same instance from version cache restrictions = version.getRestrictions(); - assertEquals(0, restrictions.size(), CHECK_NUM_RESTRICTIONS); + assertThat(restrictions.size()).as(CHECK_NUM_RESTRICTIONS).isEqualTo(0); - assertFalse( - spec.equals(version), - "check !VersionRange.createFromVersionSpec(x).equals(VersionRange.createFromVersion(x))"); + assertThat(version).as("check !VersionRange.createFromVersionSpec(x).equals(VersionRange.createFromVersion(x))").isNotEqualTo(spec); } } diff --git a/compat/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemCollectorTest.java b/compat/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemCollectorTest.java index 4ff6750e5ad0..895a8b3b8ada 100644 --- a/compat/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemCollectorTest.java +++ b/compat/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemCollectorTest.java @@ -21,42 +21,40 @@ import org.apache.maven.building.Problem.Severity; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; class DefaultProblemCollectorTest { @Test - void testGetProblems() { + void getProblems() { DefaultProblemCollector collector = new DefaultProblemCollector(null); - assertNotNull(collector.getProblems()); - assertEquals(0, collector.getProblems().size()); + assertThat(collector.getProblems()).isNotNull(); + assertThat(collector.getProblems().size()).isEqualTo(0); collector.add(null, "MESSAGE1", -1, -1, null); Exception e2 = new Exception(); collector.add(Severity.WARNING, null, 42, 127, e2); - assertEquals(2, collector.getProblems().size()); + assertThat(collector.getProblems().size()).isEqualTo(2); Problem p1 = collector.getProblems().get(0); - assertEquals(Severity.ERROR, p1.getSeverity()); - assertEquals("MESSAGE1", p1.getMessage()); - assertEquals(-1, p1.getLineNumber()); - assertEquals(-1, p1.getColumnNumber()); - assertNull(p1.getException()); + assertThat(p1.getSeverity()).isEqualTo(Severity.ERROR); + assertThat(p1.getMessage()).isEqualTo("MESSAGE1"); + assertThat(p1.getLineNumber()).isEqualTo(-1); + assertThat(p1.getColumnNumber()).isEqualTo(-1); + assertThat(p1.getException()).isNull(); Problem p2 = collector.getProblems().get(1); - assertEquals(Severity.WARNING, p2.getSeverity()); - assertEquals("", p2.getMessage()); - assertEquals(42, p2.getLineNumber()); - assertEquals(127, p2.getColumnNumber()); - assertEquals(e2, p2.getException()); + assertThat(p2.getSeverity()).isEqualTo(Severity.WARNING); + assertThat(p2.getMessage()).isEqualTo(""); + assertThat(p2.getLineNumber()).isEqualTo(42); + assertThat(p2.getColumnNumber()).isEqualTo(127); + assertThat(p2.getException()).isEqualTo(e2); } @Test - void testSetSource() { + void setSource() { DefaultProblemCollector collector = new DefaultProblemCollector(null); collector.add(null, "PROBLEM1", -1, -1, null); @@ -67,8 +65,8 @@ void testSetSource() { collector.setSource("SOURCE_PROBLEM3"); collector.add(null, "PROBLEM3", -1, -1, null); - assertEquals("", collector.getProblems().get(0).getSource()); - assertEquals("SOURCE_PROBLEM2", collector.getProblems().get(1).getSource()); - assertEquals("SOURCE_PROBLEM3", collector.getProblems().get(2).getSource()); + assertThat(collector.getProblems().get(0).getSource()).isEqualTo(""); + assertThat(collector.getProblems().get(1).getSource()).isEqualTo("SOURCE_PROBLEM2"); + assertThat(collector.getProblems().get(2).getSource()).isEqualTo("SOURCE_PROBLEM3"); } } diff --git a/compat/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemTest.java b/compat/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemTest.java index 3bd8a9aa9ec0..95b5bd2df269 100644 --- a/compat/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemTest.java +++ b/compat/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemTest.java @@ -21,108 +21,106 @@ import org.apache.maven.building.Problem.Severity; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; +import static org.assertj.core.api.Assertions.assertThat; class DefaultProblemTest { @Test - void testGetSeverity() { + void getSeverity() { DefaultProblem problem = new DefaultProblem(null, null, null, -1, -1, null); - assertEquals(Severity.ERROR, problem.getSeverity()); + assertThat(problem.getSeverity()).isEqualTo(Severity.ERROR); problem = new DefaultProblem(null, Severity.FATAL, null, -1, -1, null); - assertEquals(Severity.FATAL, problem.getSeverity()); + assertThat(problem.getSeverity()).isEqualTo(Severity.FATAL); problem = new DefaultProblem(null, Severity.ERROR, null, -1, -1, null); - assertEquals(Severity.ERROR, problem.getSeverity()); + assertThat(problem.getSeverity()).isEqualTo(Severity.ERROR); problem = new DefaultProblem(null, Severity.WARNING, null, -1, -1, null); - assertEquals(Severity.WARNING, problem.getSeverity()); + assertThat(problem.getSeverity()).isEqualTo(Severity.WARNING); } @Test - void testGetLineNumber() { + void getLineNumber() { DefaultProblem problem = new DefaultProblem(null, null, null, -1, -1, null); - assertEquals(-1, problem.getLineNumber()); + assertThat(problem.getLineNumber()).isEqualTo(-1); problem = new DefaultProblem(null, null, null, 42, -1, null); - assertEquals(42, problem.getLineNumber()); + assertThat(problem.getLineNumber()).isEqualTo(42); problem = new DefaultProblem(null, null, null, Integer.MAX_VALUE, -1, null); - assertEquals(Integer.MAX_VALUE, problem.getLineNumber()); + assertThat(problem.getLineNumber()).isEqualTo(Integer.MAX_VALUE); // this case is not specified, might also return -1 problem = new DefaultProblem(null, null, null, Integer.MIN_VALUE, -1, null); - assertEquals(Integer.MIN_VALUE, problem.getLineNumber()); + assertThat(problem.getLineNumber()).isEqualTo(Integer.MIN_VALUE); } @Test - void testGetColumnNumber() { + void getColumnNumber() { DefaultProblem problem = new DefaultProblem(null, null, null, -1, -1, null); - assertEquals(-1, problem.getColumnNumber()); + assertThat(problem.getColumnNumber()).isEqualTo(-1); problem = new DefaultProblem(null, null, null, -1, 42, null); - assertEquals(42, problem.getColumnNumber()); + assertThat(problem.getColumnNumber()).isEqualTo(42); problem = new DefaultProblem(null, null, null, -1, Integer.MAX_VALUE, null); - assertEquals(Integer.MAX_VALUE, problem.getColumnNumber()); + assertThat(problem.getColumnNumber()).isEqualTo(Integer.MAX_VALUE); // this case is not specified, might also return -1 problem = new DefaultProblem(null, null, null, -1, Integer.MIN_VALUE, null); - assertEquals(Integer.MIN_VALUE, problem.getColumnNumber()); + assertThat(problem.getColumnNumber()).isEqualTo(Integer.MIN_VALUE); } @Test - void testGetException() { + void getException() { DefaultProblem problem = new DefaultProblem(null, null, null, -1, -1, null); - assertNull(problem.getException()); + assertThat(problem.getException()).isNull(); Exception e = new Exception(); problem = new DefaultProblem(null, null, null, -1, -1, e); - assertSame(e, problem.getException()); + assertThat(problem.getException()).isSameAs(e); } @Test - void testGetSource() { + void getSource() { DefaultProblem problem = new DefaultProblem(null, null, null, -1, -1, null); - assertEquals("", problem.getSource()); + assertThat(problem.getSource()).isEqualTo(""); problem = new DefaultProblem(null, null, "", -1, -1, null); - assertEquals("", problem.getSource()); + assertThat(problem.getSource()).isEqualTo(""); problem = new DefaultProblem(null, null, "SOURCE", -1, -1, null); - assertEquals("SOURCE", problem.getSource()); + assertThat(problem.getSource()).isEqualTo("SOURCE"); } @Test - void testGetLocation() { + void getLocation() { DefaultProblem problem = new DefaultProblem(null, null, null, -1, -1, null); - assertEquals("", problem.getLocation()); + assertThat(problem.getLocation()).isEqualTo(""); problem = new DefaultProblem(null, null, "SOURCE", -1, -1, null); - assertEquals("SOURCE", problem.getLocation()); + assertThat(problem.getLocation()).isEqualTo("SOURCE"); problem = new DefaultProblem(null, null, null, 42, -1, null); - assertEquals("line 42", problem.getLocation()); + assertThat(problem.getLocation()).isEqualTo("line 42"); problem = new DefaultProblem(null, null, null, -1, 127, null); - assertEquals("column 127", problem.getLocation()); + assertThat(problem.getLocation()).isEqualTo("column 127"); problem = new DefaultProblem(null, null, "SOURCE", 42, 127, null); - assertEquals("SOURCE, line 42, column 127", problem.getLocation()); + assertThat(problem.getLocation()).isEqualTo("SOURCE, line 42, column 127"); } @Test - void testGetMessage() { + void getMessage() { DefaultProblem problem = new DefaultProblem("MESSAGE", null, null, -1, -1, null); - assertEquals("MESSAGE", problem.getMessage()); + assertThat(problem.getMessage()).isEqualTo("MESSAGE"); problem = new DefaultProblem(null, null, null, -1, -1, new Exception()); - assertEquals("", problem.getMessage()); + assertThat(problem.getMessage()).isEqualTo(""); problem = new DefaultProblem(null, null, null, -1, -1, new Exception("EXCEPTION MESSAGE")); - assertEquals("EXCEPTION MESSAGE", problem.getMessage()); + assertThat(problem.getMessage()).isEqualTo("EXCEPTION MESSAGE"); } } diff --git a/compat/maven-builder-support/src/test/java/org/apache/maven/building/FileSourceTest.java b/compat/maven-builder-support/src/test/java/org/apache/maven/building/FileSourceTest.java index 33dd09373548..af7985ddff1e 100644 --- a/compat/maven-builder-support/src/test/java/org/apache/maven/building/FileSourceTest.java +++ b/compat/maven-builder-support/src/test/java/org/apache/maven/building/FileSourceTest.java @@ -24,43 +24,40 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; class FileSourceTest { @Test - void testFileSource() { - NullPointerException e = assertThrows( - NullPointerException.class, - () -> new FileSource((File) null), - "Should fail, since you must specify a file"); - assertEquals("file cannot be null", e.getMessage()); + void fileSource() { + NullPointerException e = assertThatExceptionOfType(NullPointerException.class).as("Should fail, since you must specify a file").isThrownBy(() -> new FileSource((File) null)).actual(); + assertThat(e.getMessage()).isEqualTo("file cannot be null"); } @Test - void testGetInputStream() throws Exception { + void getInputStream() throws Exception { File txtFile = new File("target/test-classes/source.txt"); FileSource source = new FileSource(txtFile); try (InputStream is = source.getInputStream(); Scanner scanner = new Scanner(is)) { - assertEquals("Hello World!", scanner.nextLine()); + assertThat(scanner.nextLine()).isEqualTo("Hello World!"); } } @Test - void testGetLocation() { + void getLocation() { File txtFile = new File("target/test-classes/source.txt"); FileSource source = new FileSource(txtFile); - assertEquals(txtFile.getAbsolutePath(), source.getLocation()); + assertThat(source.getLocation()).isEqualTo(txtFile.getAbsolutePath()); } @Test - void testGetFile() { + void getFile() { File txtFile = new File("target/test-classes/source.txt"); FileSource source = new FileSource(txtFile); - assertEquals(txtFile.getAbsoluteFile(), source.getFile()); + assertThat(source.getFile()).isEqualTo(txtFile.getAbsoluteFile()); } } diff --git a/compat/maven-builder-support/src/test/java/org/apache/maven/building/ProblemCollectorFactoryTest.java b/compat/maven-builder-support/src/test/java/org/apache/maven/building/ProblemCollectorFactoryTest.java index 6705992befc5..1c3714c0caba 100644 --- a/compat/maven-builder-support/src/test/java/org/apache/maven/building/ProblemCollectorFactoryTest.java +++ b/compat/maven-builder-support/src/test/java/org/apache/maven/building/ProblemCollectorFactoryTest.java @@ -22,20 +22,20 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertNotSame; class ProblemCollectorFactoryTest { @Test - void testNewInstance() { + void newInstance() { ProblemCollector collector1 = ProblemCollectorFactory.newInstance(null); Problem problem = new DefaultProblem("MESSAGE1", null, null, -1, -1, null); ProblemCollector collector2 = ProblemCollectorFactory.newInstance(Collections.singletonList(problem)); assertNotSame(collector1, collector2); - assertEquals(0, collector1.getProblems().size()); - assertEquals(1, collector2.getProblems().size()); + assertThat(collector1.getProblems().size()).isEqualTo(0); + assertThat(collector2.getProblems().size()).isEqualTo(1); } } diff --git a/compat/maven-builder-support/src/test/java/org/apache/maven/building/StringSourceTest.java b/compat/maven-builder-support/src/test/java/org/apache/maven/building/StringSourceTest.java index 8bd2a41587f0..7ebf5c37810b 100644 --- a/compat/maven-builder-support/src/test/java/org/apache/maven/building/StringSourceTest.java +++ b/compat/maven-builder-support/src/test/java/org/apache/maven/building/StringSourceTest.java @@ -23,34 +23,34 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; class StringSourceTest { @Test - void testGetInputStream() throws Exception { + void getInputStream() throws Exception { StringSource source = new StringSource("Hello World!"); try (InputStream is = source.getInputStream(); Scanner scanner = new Scanner(is)) { - assertEquals("Hello World!", scanner.nextLine()); + assertThat(scanner.nextLine()).isEqualTo("Hello World!"); } } @Test - void testGetLocation() { + void getLocation() { StringSource source = new StringSource("Hello World!"); - assertEquals("(memory)", source.getLocation()); + assertThat(source.getLocation()).isEqualTo("(memory)"); source = new StringSource("Hello World!", "LOCATION"); - assertEquals("LOCATION", source.getLocation()); + assertThat(source.getLocation()).isEqualTo("LOCATION"); } @Test - void testGetContent() { + void getContent() { StringSource source = new StringSource(null); - assertEquals("", source.getContent()); + assertThat(source.getContent()).isEqualTo(""); source = new StringSource("Hello World!", "LOCATION"); - assertEquals("Hello World!", source.getContent()); + assertThat(source.getContent()).isEqualTo("Hello World!"); } } diff --git a/compat/maven-builder-support/src/test/java/org/apache/maven/building/UrlSourceTest.java b/compat/maven-builder-support/src/test/java/org/apache/maven/building/UrlSourceTest.java index 216c5d7c72a4..c9f802561e98 100644 --- a/compat/maven-builder-support/src/test/java/org/apache/maven/building/UrlSourceTest.java +++ b/compat/maven-builder-support/src/test/java/org/apache/maven/building/UrlSourceTest.java @@ -25,32 +25,31 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; class UrlSourceTest { @Test - void testUrlSource() { - NullPointerException e = assertThrows( - NullPointerException.class, () -> new UrlSource(null), "Should fail, since you must specify a url"); - assertEquals("url cannot be null", e.getMessage()); + void urlSource() { + NullPointerException e = assertThatExceptionOfType(NullPointerException.class).as("Should fail, since you must specify a url").isThrownBy(() -> new UrlSource(null)).actual(); + assertThat(e.getMessage()).isEqualTo("url cannot be null"); } @Test - void testGetInputStream() throws Exception { + void getInputStream() throws Exception { URL txtFile = new File("target/test-classes/source.txt").toURI().toURL(); UrlSource source = new UrlSource(txtFile); try (InputStream is = source.getInputStream(); Scanner scanner = new Scanner(is)) { - assertEquals("Hello World!", scanner.nextLine()); + assertThat(scanner.nextLine()).isEqualTo("Hello World!"); } } @Test - void testGetLocation() throws Exception { + void getLocation() throws Exception { URL txtFile = new File("target/test-classes/source.txt").toURI().toURL(); UrlSource source = new UrlSource(txtFile); - assertEquals(txtFile.toExternalForm(), source.getLocation()); + assertThat(source.getLocation()).isEqualTo(txtFile.toExternalForm()); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java b/compat/maven-compat/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java index 5cc242c09648..25fba367dcb7 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java @@ -31,10 +31,10 @@ import org.apache.maven.project.MavenProject; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.endsWith; -import static org.junit.jupiter.api.Assertions.assertEquals; @Deprecated class ProjectDependenciesResolverTest extends AbstractCoreMavenComponentTestCase { @@ -46,7 +46,7 @@ protected String getProjectsDirectory() { } @Test - void testSystemScopeDependencies() throws Exception { + void systemScopeDependencies() throws Exception { MavenSession session = createMavenSession(null); MavenProject project = session.getCurrentProject(); @@ -60,11 +60,11 @@ void testSystemScopeDependencies() throws Exception { Set artifactDependencies = resolver.resolve(project, Collections.singleton(Artifact.SCOPE_COMPILE), session); - assertEquals(1, artifactDependencies.size()); + assertThat(artifactDependencies.size()).isEqualTo(1); } @Test - void testSystemScopeDependencyIsPresentInTheCompileClasspathElements() throws Exception { + void systemScopeDependencyIsPresentInTheCompileClasspathElements() throws Exception { File pom = getProject("it0063"); Properties eps = new Properties(); @@ -76,11 +76,11 @@ void testSystemScopeDependencyIsPresentInTheCompileClasspathElements() throws Ex project.setArtifacts(resolver.resolve(project, Collections.singleton(Artifact.SCOPE_COMPILE), session)); List elements = project.getCompileClasspathElements(); - assertEquals(2, elements.size()); + assertThat(elements.size()).isEqualTo(2); @SuppressWarnings("deprecation") List artifacts = project.getCompileArtifacts(); - assertEquals(1, artifacts.size()); + assertThat(artifacts.size()).isEqualTo(1); assertThat(artifacts.get(0).getFile().getName(), endsWith("tools.jar")); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java index 14f394c0c1cd..2e914638d244 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java @@ -75,9 +75,8 @@ import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy; import org.junit.jupiter.api.BeforeEach; +import static org.assertj.core.api.Assertions.assertThat; import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; /** */ @@ -176,7 +175,7 @@ protected void assertRemoteArtifactPresent(Artifact artifact) throws Exception { File file = new File(remoteRepo.getBasedir(), path); - assertTrue(file.exists(), "Remote artifact " + file + " should be present."); + assertThat(file.exists()).as("Remote artifact " + file + " should be present.").isTrue(); } protected void assertLocalArtifactPresent(Artifact artifact) throws Exception { @@ -186,7 +185,7 @@ protected void assertLocalArtifactPresent(Artifact artifact) throws Exception { File file = new File(localRepo.getBasedir(), path); - assertTrue(file.exists(), "Local artifact " + file + " should be present."); + assertThat(file.exists()).as("Local artifact " + file + " should be present.").isTrue(); } protected void assertRemoteArtifactNotPresent(Artifact artifact) throws Exception { @@ -196,7 +195,7 @@ protected void assertRemoteArtifactNotPresent(Artifact artifact) throws Exceptio File file = new File(remoteRepo.getBasedir(), path); - assertFalse(file.exists(), "Remote artifact " + file + " should not be present."); + assertThat(file.exists()).as("Remote artifact " + file + " should not be present.").isFalse(); } protected void assertLocalArtifactNotPresent(Artifact artifact) throws Exception { @@ -206,7 +205,7 @@ protected void assertLocalArtifactNotPresent(Artifact artifact) throws Exception File file = new File(localRepo.getBasedir(), path); - assertFalse(file.exists(), "Local artifact " + file + " should not be present."); + assertThat(file.exists()).as("Local artifact " + file + " should not be present.").isFalse(); } // ---------------------------------------------------------------------- diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java index 0435e1195252..d15ee8ea1c8b 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java @@ -31,9 +31,8 @@ import org.apache.maven.session.scope.internal.SessionScope; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; /** @@ -51,7 +50,7 @@ protected String component() { } @Test - void testArtifactInstallation() throws Exception { + void artifactInstallation() throws Exception { sessionScope.enter(); try { sessionScope.seed(MavenSession.class, mock(MavenSession.class)); @@ -61,14 +60,14 @@ void testArtifactInstallation() throws Exception { Artifact artifact = createArtifact("artifact", "1.0"); File file = new File(artifactBasedir, "artifact-1.0.jar"); - assertEquals("dummy", new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8).trim()); + assertThat(new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8).trim()).isEqualTo("dummy"); artifactDeployer.deploy(file, artifact, remoteRepository(), localRepository()); ArtifactRepository remoteRepository = remoteRepository(); File deployedFile = new File(remoteRepository.getBasedir(), remoteRepository.pathOf(artifact)); - assertTrue(deployedFile.exists()); - assertEquals("dummy", new String(Files.readAllBytes(deployedFile.toPath()), StandardCharsets.UTF_8).trim()); + assertThat(deployedFile.exists()).isTrue(); + assertThat(new String(Files.readAllBytes(deployedFile.toPath()), StandardCharsets.UTF_8).trim()).isEqualTo("dummy"); } finally { sessionScope.exit(); } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java index 634e7f7462ef..5078879087db 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java @@ -25,7 +25,7 @@ import org.codehaus.plexus.testing.PlexusTest; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; @PlexusTest @Deprecated @@ -35,7 +35,7 @@ class DefaultArtifactFactoryTest { ArtifactFactory factory; @Test - void testPropagationOfSystemScopeRegardlessOfInheritedScope() { + void propagationOfSystemScopeRegardlessOfInheritedScope() { Artifact artifact = factory.createDependencyArtifact( "test-grp", "test-artifact", VersionRange.createFromVersion("1.0"), "type", null, "system", "provided"); Artifact artifact2 = factory.createDependencyArtifact( @@ -61,10 +61,10 @@ void testPropagationOfSystemScopeRegardlessOfInheritedScope() { Artifact artifact5 = factory.createDependencyArtifact( "test-grp", "test-artifact-5", VersionRange.createFromVersion("1.0"), "type", null, "system", "system"); - assertEquals("system", artifact.getScope()); - assertEquals("system", artifact2.getScope()); - assertEquals("system", artifact3.getScope()); - assertEquals("system", artifact4.getScope()); - assertEquals("system", artifact5.getScope()); + assertThat(artifact.getScope()).isEqualTo("system"); + assertThat(artifact2.getScope()).isEqualTo("system"); + assertThat(artifact3.getScope()).isEqualTo("system"); + assertThat(artifact4.getScope()).isEqualTo("system"); + assertThat(artifact5.getScope()).isEqualTo("system"); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java index 0d24d73bcbc1..06313ccd1059 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java @@ -46,7 +46,7 @@ protected String component() { } @Test - void testArtifactInstallation() throws Exception { + void artifactInstallation() throws Exception { sessionScope.enter(); try { sessionScope.seed(MavenSession.class, mock(MavenSession.class)); diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/repository/MavenArtifactRepositoryTest.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/repository/MavenArtifactRepositoryTest.java index f529ae822ba4..2a44a0c961cb 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/repository/MavenArtifactRepositoryTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/repository/MavenArtifactRepositoryTest.java @@ -20,8 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; @Deprecated class MavenArtifactRepositoryTest { @@ -39,18 +38,18 @@ public String getId() { } @Test - void testHashCodeEquals() { + void hashCodeEquals() { MavenArtifactRepositorySubclass r1 = new MavenArtifactRepositorySubclass("foo"); MavenArtifactRepositorySubclass r2 = new MavenArtifactRepositorySubclass("foo"); MavenArtifactRepositorySubclass r3 = new MavenArtifactRepositorySubclass("bar"); - assertTrue(r1.hashCode() == r2.hashCode()); - assertFalse(r1.hashCode() == r3.hashCode()); + assertThat(r2.hashCode()).isEqualTo(r1.hashCode()); + assertThat(r1.hashCode() == r3.hashCode()).isFalse(); - assertTrue(r1.equals(r2)); - assertTrue(r2.equals(r1)); + assertThat(r2).isEqualTo(r1); + assertThat(r1).isEqualTo(r2); - assertFalse(r1.equals(r3)); - assertFalse(r3.equals(r1)); + assertThat(r3).isNotEqualTo(r1); + assertThat(r1).isNotEqualTo(r3); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolutionExceptionTest.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolutionExceptionTest.java index 385660370138..64bf2ba841d0 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolutionExceptionTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolutionExceptionTest.java @@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Test the artifact resolution exception message @@ -33,7 +33,7 @@ class ArtifactResolutionExceptionTest { private static final String LS = System.lineSeparator(); @Test - void testMissingArtifactMessageFormat() { + void missingArtifactMessageFormat() { String message = "Missing artifact"; String indentation = " "; String groupId = "aGroupId"; @@ -54,6 +54,6 @@ void testMissingArtifactMessageFormat() { + LS + " \t2) dependency2" + LS + LS; String actual = AbstractArtifactResolutionException.constructMissingArtifactMessage( message, indentation, groupId, artifactId, version, type, classifier, downloadUrl, path); - assertEquals(expected, actual); + assertThat(actual).isEqualTo(expected); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java index 30ade70a919b..8aa0fcfbd036 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java @@ -39,9 +39,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; // It would be cool if there was a hook that I could use to set up a test environment. // I want to set up a local/remote repositories for testing but I don't want to have @@ -79,7 +78,7 @@ protected String component() { } @Test - void testResolutionOfASingleArtifactWhereTheArtifactIsPresentInTheLocalRepository() throws Exception { + void resolutionOfASingleArtifactWhereTheArtifactIsPresentInTheLocalRepository() throws Exception { Artifact a = createLocalArtifact("a", "1.0"); artifactResolver.resolve(a, remoteRepositories(), localRepository()); @@ -88,7 +87,7 @@ void testResolutionOfASingleArtifactWhereTheArtifactIsPresentInTheLocalRepositor } @Test - void testResolutionOfASingleArtifactWhereTheArtifactIsNotPresentLocallyAndMustBeRetrievedFromTheRemoteRepository() + void resolutionOfASingleArtifactWhereTheArtifactIsNotPresentLocallyAndMustBeRetrievedFromTheRemoteRepository() throws Exception { Artifact b = createRemoteArtifact("b", "1.0-SNAPSHOT"); deleteLocalArtifact(b); @@ -103,7 +102,7 @@ protected Artifact createArtifact(String groupId, String artifactId, String vers } @Test - void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository() throws Exception { + void transitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository() throws Exception { Artifact g = createLocalArtifact("g", "1.0"); Artifact h = createLocalArtifact("h", "1.0"); @@ -113,11 +112,11 @@ void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository() t printErrors(result); - assertEquals(2, result.getArtifacts().size()); + assertThat(result.getArtifacts().size()).isEqualTo(2); - assertTrue(result.getArtifacts().contains(g)); + assertThat(result.getArtifacts().contains(g)).isTrue(); - assertTrue(result.getArtifacts().contains(h)); + assertThat(result.getArtifacts().contains(h)).isTrue(); assertLocalArtifactPresent(g); @@ -126,7 +125,7 @@ void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository() t @Test void - testTransitiveResolutionWhereAllArtifactsAreNotPresentInTheLocalRepositoryAndMustBeRetrievedFromTheRemoteRepository() + transitiveResolutionWhereAllArtifactsAreNotPresentInTheLocalRepositoryAndMustBeRetrievedFromTheRemoteRepository() throws Exception { Artifact i = createRemoteArtifact("i", "1.0-SNAPSHOT"); deleteLocalArtifact(i); @@ -139,11 +138,11 @@ void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository() t printErrors(result); - assertEquals(2, result.getArtifacts().size()); + assertThat(result.getArtifacts().size()).isEqualTo(2); - assertTrue(result.getArtifacts().contains(i)); + assertThat(result.getArtifacts().contains(i)).isTrue(); - assertTrue(result.getArtifacts().contains(j)); + assertThat(result.getArtifacts().contains(j)).isTrue(); assertLocalArtifactPresent(i); @@ -151,17 +150,14 @@ void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository() t } @Test - void testResolutionFailureWhenArtifactNotPresentInRemoteRepository() throws Exception { + void resolutionFailureWhenArtifactNotPresentInRemoteRepository() throws Exception { Artifact k = createArtifact("k", "1.0"); - assertThrows( - ArtifactNotFoundException.class, - () -> artifactResolver.resolve(k, remoteRepositories(), localRepository()), - "Resolution succeeded when it should have failed"); + assertThatExceptionOfType(ArtifactNotFoundException.class).as("Resolution succeeded when it should have failed").isThrownBy(() -> artifactResolver.resolve(k, remoteRepositories(), localRepository())); } @Test - void testResolutionOfAnArtifactWhereOneRemoteRepositoryIsBadButOneIsGood() throws Exception { + void resolutionOfAnArtifactWhereOneRemoteRepositoryIsBadButOneIsGood() throws Exception { Artifact l = createRemoteArtifact("l", "1.0-SNAPSHOT"); deleteLocalArtifact(l); @@ -175,19 +171,19 @@ void testResolutionOfAnArtifactWhereOneRemoteRepositoryIsBadButOneIsGood() throw } @Test - public void testReadRepoFromModel() throws Exception { + void readRepoFromModel() throws Exception { Artifact artifact = createArtifact(TestMavenWorkspaceReader.ARTIFACT_ID, TestMavenWorkspaceReader.VERSION); ArtifactMetadataSource source = getContainer().lookup(ArtifactMetadataSource.class, "maven"); ResolutionGroup group = source.retrieve(artifact, localRepository(), new ArrayList<>()); List repositories = group.getResolutionRepositories(); - assertEquals(1, repositories.size(), "There should be one repository!"); + assertThat(repositories.size()).as("There should be one repository!").isEqualTo(1); ArtifactRepository repository = repositories.get(0); - assertEquals(TestMavenWorkspaceReader.REPO_ID, repository.getId()); - assertEquals(TestMavenWorkspaceReader.REPO_URL, repository.getUrl()); + assertThat(repository.getId()).isEqualTo(TestMavenWorkspaceReader.REPO_ID); + assertThat(repository.getUrl()).isEqualTo(TestMavenWorkspaceReader.REPO_URL); } @Test - void testTransitiveResolutionOrder() throws Exception { + void transitiveResolutionOrder() throws Exception { Artifact m = createLocalArtifact("m", "1.0"); Artifact n = createLocalArtifact("n", "1.0"); @@ -241,8 +237,8 @@ public List retrieveAvailableVersions(MetadataResolutionRequest printErrors(result); Iterator i = result.getArtifacts().iterator(); - assertEquals(n, i.next(), "n should be first"); - assertEquals(m, i.next(), "m should be second"); + assertThat(i.next()).as("n should be first").isEqualTo(n); + assertThat(i.next()).as("m should be second").isEqualTo(m); // inverse order set = new LinkedHashSet<>(); @@ -255,8 +251,8 @@ public List retrieveAvailableVersions(MetadataResolutionRequest printErrors(result); i = result.getArtifacts().iterator(); - assertEquals(m, i.next(), "m should be first"); - assertEquals(n, i.next(), "n should be second"); + assertThat(i.next()).as("m should be first").isEqualTo(m); + assertThat(i.next()).as("n should be second").isEqualTo(n); } private void printErrors(ArtifactResolutionResult result) { diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java index a523b0d356af..0aeca49c728c 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java @@ -27,8 +27,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; @Deprecated class DefaultArtifactResolverTest extends AbstractArtifactComponentTestCase { @@ -50,7 +49,7 @@ protected String component() { } @Test - void testMNG4738() throws Exception { + void mng4738() throws Exception { Artifact g = createLocalArtifact("g", "1.0"); createLocalArtifact("h", "1.0"); artifactResolver.resolveTransitively( @@ -81,16 +80,16 @@ void testMNG4738() throws Exception { for (Thread active : ts) { String name = active.getName(); boolean daemon = active.isDaemon(); - assertTrue(daemon, name + " is no daemon Thread."); + assertThat(daemon).as(name + " is no daemon Thread.").isTrue(); } } - assertTrue(seen, "Could not find ThreadGroup: " + DefaultArtifactResolver.DaemonThreadCreator.THREADGROUP_NAME); + assertThat(seen).as("Could not find ThreadGroup: " + DefaultArtifactResolver.DaemonThreadCreator.THREADGROUP_NAME).isTrue(); } @Test - void testLookup() throws Exception { + void lookup() throws Exception { ArtifactResolver resolver = getContainer().lookup(ArtifactResolver.class, "default"); - assertNotNull(resolver); + assertThat(resolver).isNotNull(); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/AndArtifactFilterTest.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/AndArtifactFilterTest.java index fe0343c857cb..45a3cc385fa9 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/AndArtifactFilterTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/AndArtifactFilterTest.java @@ -22,9 +22,7 @@ import org.junit.jupiter.api.Test; -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.assertj.core.api.Assertions.assertThat; /** * Tests {@link AndArtifactFilter}. @@ -37,16 +35,16 @@ private ArtifactFilter newSubFilter() { } @Test - void testEquals() { + void equals() { AndArtifactFilter filter1 = new AndArtifactFilter(); AndArtifactFilter filter2 = new AndArtifactFilter(Arrays.asList(newSubFilter())); - assertFalse(filter1.equals(null)); - assertTrue(filter1.equals(filter1)); - assertEquals(filter1.hashCode(), filter1.hashCode()); + assertThat(filter1).isNotEqualTo(null); + assertThat(filter1).isEqualTo(filter1); + assertThat(filter1.hashCode()).isEqualTo(filter1.hashCode()); - assertFalse(filter1.equals(filter2)); - assertFalse(filter2.equals(filter1)); + assertThat(filter2).isNotEqualTo(filter1); + assertThat(filter1).isNotEqualTo(filter2); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/FilterHashEqualsTest.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/FilterHashEqualsTest.java index 53a26db4ea12..36de5d10459c 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/FilterHashEqualsTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/FilterHashEqualsTest.java @@ -23,26 +23,26 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** */ class FilterHashEqualsTest { @Test - void testIncludesExcludesArtifactFilter() { + void includesExcludesArtifactFilter() { List patterns = Arrays.asList("c", "d", "e"); IncludesArtifactFilter f1 = new IncludesArtifactFilter(patterns); IncludesArtifactFilter f2 = new IncludesArtifactFilter(patterns); - assertTrue(f1.equals(f2)); - assertTrue(f2.equals(f1)); - assertTrue(f1.hashCode() == f2.hashCode()); + assertThat(f2).isEqualTo(f1); + assertThat(f1).isEqualTo(f2); + assertThat(f2.hashCode()).isEqualTo(f1.hashCode()); IncludesArtifactFilter f3 = new IncludesArtifactFilter(Arrays.asList("d", "c", "e")); - assertTrue(f1.equals(f3)); - assertTrue(f1.hashCode() == f3.hashCode()); + assertThat(f3).isEqualTo(f1); + assertThat(f3.hashCode()).isEqualTo(f1.hashCode()); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/OrArtifactFilterTest.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/OrArtifactFilterTest.java index 6c8cda6802bc..62b8f58c2d96 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/OrArtifactFilterTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/OrArtifactFilterTest.java @@ -22,9 +22,7 @@ import org.junit.jupiter.api.Test; -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.assertj.core.api.Assertions.assertThat; /** * Tests {@link OrArtifactFilter}. @@ -38,16 +36,16 @@ private ArtifactFilter newSubFilter() { } @Test - void testEquals() { + void equals() { OrArtifactFilter filter1 = new OrArtifactFilter(); OrArtifactFilter filter2 = new OrArtifactFilter(Arrays.asList(newSubFilter())); - assertFalse(filter1.equals(null)); - assertTrue(filter1.equals(filter1)); - assertEquals(filter1.hashCode(), filter1.hashCode()); + assertThat(filter1).isNotEqualTo(null); + assertThat(filter1).isEqualTo(filter1); + assertThat(filter1.hashCode()).isEqualTo(filter1.hashCode()); - assertFalse(filter1.equals(filter2)); - assertFalse(filter2.equals(filter1)); + assertThat(filter2).isNotEqualTo(filter1); + assertThat(filter1).isNotEqualTo(filter2); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilterTest.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilterTest.java index 0addbe8023bd..19b20768723b 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilterTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilterTest.java @@ -22,8 +22,7 @@ import org.apache.maven.artifact.DefaultArtifact; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@link ScopeArtifactFilter}. @@ -36,57 +35,57 @@ private Artifact newArtifact(String scope) { } @Test - void testIncludeCompile() { + void includeCompile() { ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_COMPILE); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_COMPILE))); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_SYSTEM))); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_PROVIDED))); - assertFalse(filter.include(newArtifact(Artifact.SCOPE_RUNTIME))); - assertFalse(filter.include(newArtifact(Artifact.SCOPE_TEST))); + assertThat(filter.include(newArtifact(Artifact.SCOPE_COMPILE))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_SYSTEM))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_PROVIDED))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_RUNTIME))).isFalse(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_TEST))).isFalse(); } @Test - void testIncludeCompilePlusRuntime() { + void includeCompilePlusRuntime() { ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_COMPILE_PLUS_RUNTIME); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_COMPILE))); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_SYSTEM))); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_PROVIDED))); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_RUNTIME))); - assertFalse(filter.include(newArtifact(Artifact.SCOPE_TEST))); + assertThat(filter.include(newArtifact(Artifact.SCOPE_COMPILE))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_SYSTEM))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_PROVIDED))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_RUNTIME))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_TEST))).isFalse(); } @Test - void testIncludeRuntime() { + void includeRuntime() { ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_COMPILE))); - assertFalse(filter.include(newArtifact(Artifact.SCOPE_SYSTEM))); - assertFalse(filter.include(newArtifact(Artifact.SCOPE_PROVIDED))); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_RUNTIME))); - assertFalse(filter.include(newArtifact(Artifact.SCOPE_TEST))); + assertThat(filter.include(newArtifact(Artifact.SCOPE_COMPILE))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_SYSTEM))).isFalse(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_PROVIDED))).isFalse(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_RUNTIME))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_TEST))).isFalse(); } @Test - void testIncludeRuntimePlusSystem() { + void includeRuntimePlusSystem() { ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME_PLUS_SYSTEM); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_COMPILE))); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_SYSTEM))); - assertFalse(filter.include(newArtifact(Artifact.SCOPE_PROVIDED))); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_RUNTIME))); - assertFalse(filter.include(newArtifact(Artifact.SCOPE_TEST))); + assertThat(filter.include(newArtifact(Artifact.SCOPE_COMPILE))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_SYSTEM))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_PROVIDED))).isFalse(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_RUNTIME))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_TEST))).isFalse(); } @Test - void testIncludeTest() { + void includeTest() { ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_TEST); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_COMPILE))); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_SYSTEM))); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_PROVIDED))); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_RUNTIME))); - assertTrue(filter.include(newArtifact(Artifact.SCOPE_TEST))); + assertThat(filter.include(newArtifact(Artifact.SCOPE_COMPILE))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_SYSTEM))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_PROVIDED))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_RUNTIME))).isTrue(); + assertThat(filter.include(newArtifact(Artifact.SCOPE_TEST))).isTrue(); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java index 47372855ca2d..a953d30c3d8c 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java @@ -26,9 +26,7 @@ import org.codehaus.plexus.util.FileUtils; -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.assertj.core.api.Assertions.assertThat; @Deprecated public class TestFileManager { @@ -120,9 +118,9 @@ public void assertFileExistence(File dir, String filename, boolean shouldExist) File file = new File(dir, filename); if (shouldExist) { - assertTrue(file.exists()); + assertThat(file.exists()).isTrue(); } else { - assertFalse(file.exists()); + assertThat(file.exists()).isFalse(); } } @@ -133,7 +131,7 @@ public void assertFileContents(File dir, String filename, String contentsTest, S String contents = FileUtils.fileRead(file, encoding); - assertEquals(contentsTest, contents); + assertThat(contents).isEqualTo(contentsTest); } public File createFile(File dir, String filename, String contents, String encoding) throws IOException { diff --git a/compat/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java b/compat/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java index 4e76243abe66..a3eeced5f419 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java @@ -30,8 +30,7 @@ import org.codehaus.plexus.testing.PlexusTest; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; @PlexusTest @Deprecated @@ -40,21 +39,15 @@ class TransformationManagerTest { ArtifactTransformationManager tm; @Test - void testTransformationManager() { + void transformationManager() { List tms = tm.getArtifactTransformations(); - assertEquals(3, tms.size()); + assertThat(tms.size()).isEqualTo(3); - assertTrue( - tms.get(0) instanceof ReleaseArtifactTransformation, - "We expected the release transformation and got " + tms.get(0)); + assertThat((tms.get(0) instanceof ReleaseArtifactTransformation)).as("We expected the release transformation and got " + tms.get(0)).isTrue(); - assertTrue( - tms.get(1) instanceof LatestArtifactTransformation, - "We expected the latest transformation and got " + tms.get(1)); + assertThat((tms.get(1) instanceof LatestArtifactTransformation)).as("We expected the latest transformation and got " + tms.get(1)).isTrue(); - assertTrue( - tms.get(2) instanceof SnapshotTransformation, - "We expected the snapshot transformation and got " + tms.get(2)); + assertThat((tms.get(2) instanceof SnapshotTransformation)).as("We expected the snapshot transformation and got " + tms.get(2)).isTrue(); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java b/compat/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java index d0d798b7e007..327adfbf2460 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java @@ -32,8 +32,7 @@ import org.codehaus.plexus.testing.PlexusTest; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; @PlexusTest @Deprecated @@ -47,7 +46,7 @@ protected PlexusContainer getContainer() { } @Test - void testShouldActivateDefaultProfile() throws Exception { + void shouldActivateDefaultProfile() throws Exception { Profile notActivated = new Profile(); notActivated.setId("notActivated"); @@ -75,13 +74,13 @@ void testShouldActivateDefaultProfile() throws Exception { List active = profileManager.getActiveProfiles(); - assertNotNull(active); - assertEquals(1, active.size()); - assertEquals("defaultActivated", ((Profile) active.get(0)).getId()); + assertThat(active).isNotNull(); + assertThat(active.size()).isEqualTo(1); + assertThat(((Profile) active.get(0)).getId()).isEqualTo("defaultActivated"); } @Test - void testShouldNotActivateDefaultProfile() throws Exception { + void shouldNotActivateDefaultProfile() throws Exception { Profile syspropActivated = new Profile(); syspropActivated.setId("syspropActivated"); @@ -112,13 +111,13 @@ void testShouldNotActivateDefaultProfile() throws Exception { List active = profileManager.getActiveProfiles(); - assertNotNull(active); - assertEquals(1, active.size()); - assertEquals("syspropActivated", ((Profile) active.get(0)).getId()); + assertThat(active).isNotNull(); + assertThat(active.size()).isEqualTo(1); + assertThat(((Profile) active.get(0)).getId()).isEqualTo("syspropActivated"); } @Test - void testShouldNotActivateReversalOfPresentSystemProperty() throws Exception { + void shouldNotActivateReversalOfPresentSystemProperty() throws Exception { Profile syspropActivated = new Profile(); syspropActivated.setId("syspropActivated"); @@ -139,12 +138,12 @@ void testShouldNotActivateReversalOfPresentSystemProperty() throws Exception { List active = profileManager.getActiveProfiles(); - assertNotNull(active); - assertEquals(0, active.size()); + assertThat(active).isNotNull(); + assertThat(active.size()).isEqualTo(0); } @Test - void testShouldOverrideAndActivateInactiveProfile() throws Exception { + void shouldOverrideAndActivateInactiveProfile() throws Exception { Profile syspropActivated = new Profile(); syspropActivated.setId("syspropActivated"); @@ -167,13 +166,13 @@ void testShouldOverrideAndActivateInactiveProfile() throws Exception { List active = profileManager.getActiveProfiles(); - assertNotNull(active); - assertEquals(1, active.size()); - assertEquals("syspropActivated", ((Profile) active.get(0)).getId()); + assertThat(active).isNotNull(); + assertThat(active.size()).isEqualTo(1); + assertThat(((Profile) active.get(0)).getId()).isEqualTo("syspropActivated"); } @Test - void testShouldOverrideAndDeactivateActiveProfile() throws Exception { + void shouldOverrideAndDeactivateActiveProfile() throws Exception { Profile syspropActivated = new Profile(); syspropActivated.setId("syspropActivated"); @@ -196,7 +195,7 @@ void testShouldOverrideAndDeactivateActiveProfile() throws Exception { List active = profileManager.getActiveProfiles(); - assertNotNull(active); - assertEquals(0, active.size()); + assertThat(active).isNotNull(); + assertThat(active.size()).isEqualTo(0); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/compat/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java index 56f62cf65dc5..f5e3502bab95 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java @@ -47,7 +47,7 @@ import org.eclipse.aether.DefaultRepositorySystemSession; import org.junit.jupiter.api.BeforeEach; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; /** */ diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTestType.java b/compat/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTestType.java index 24af8e7dfdc6..0c297c25c83e 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTestType.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTestType.java @@ -28,9 +28,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; @Deprecated class ProjectClasspathTestType extends AbstractMavenProjectTestCase { @@ -52,14 +50,14 @@ public void setUp() throws Exception { } @Test - void testProjectClasspath() throws Exception { + void projectClasspath() throws Exception { File f = getFileForClasspathResource(DIR + "project-with-scoped-dependencies.xml"); MavenProject project = getProjectWithDependencies(f); Artifact artifact; - assertNotNull(project, "Test project can't be null!"); + assertThat(project).as("Test project can't be null!").isNotNull(); checkArtifactIdScope(project, "provided", "provided"); checkArtifactIdScope(project, "test", "test"); @@ -69,59 +67,59 @@ void testProjectClasspath() throws Exception { // check all transitive deps of a test dependency are test, except test and provided which is skipped artifact = getArtifact(project, "maven-test-test", "scope-provided"); - assertNull(artifact, "Check no provided dependencies are transitive"); + assertThat(artifact).as("Check no provided dependencies are transitive").isNull(); artifact = getArtifact(project, "maven-test-test", "scope-test"); - assertNull(artifact, "Check no test dependencies are transitive"); + assertThat(artifact).as("Check no test dependencies are transitive").isNull(); artifact = getArtifact(project, "maven-test-test", "scope-compile"); - assertNotNull(artifact); + assertThat(artifact).isNotNull(); System.out.println("a = " + artifact); System.out.println("b = " + artifact.getScope()); - assertEquals("test", artifact.getScope(), "Check scope"); + assertThat(artifact.getScope()).as("Check scope").isEqualTo("test"); artifact = getArtifact(project, "maven-test-test", "scope-default"); - assertEquals("test", artifact.getScope(), "Check scope"); + assertThat(artifact.getScope()).as("Check scope").isEqualTo("test"); artifact = getArtifact(project, "maven-test-test", "scope-runtime"); - assertEquals("test", artifact.getScope(), "Check scope"); + assertThat(artifact.getScope()).as("Check scope").isEqualTo("test"); // check all transitive deps of a provided dependency are provided scope, except for test checkGroupIdScope(project, "provided", "maven-test-provided"); artifact = getArtifact(project, "maven-test-provided", "scope-runtime"); - assertEquals("provided", artifact.getScope(), "Check scope"); + assertThat(artifact.getScope()).as("Check scope").isEqualTo("provided"); // check all transitive deps of a runtime dependency are runtime scope, except for test checkGroupIdScope(project, "runtime", "maven-test-runtime"); artifact = getArtifact(project, "maven-test-runtime", "scope-runtime"); - assertEquals("runtime", artifact.getScope(), "Check scope"); + assertThat(artifact.getScope()).as("Check scope").isEqualTo("runtime"); // check all transitive deps of a compile dependency are compile scope, except for runtime and test checkGroupIdScope(project, "compile", "maven-test-compile"); artifact = getArtifact(project, "maven-test-compile", "scope-runtime"); - assertEquals("runtime", artifact.getScope(), "Check scope"); + assertThat(artifact.getScope()).as("Check scope").isEqualTo("runtime"); // check all transitive deps of a default dependency are compile scope, except for runtime and test checkGroupIdScope(project, "compile", "maven-test-default"); artifact = getArtifact(project, "maven-test-default", "scope-runtime"); - assertEquals("runtime", artifact.getScope(), "Check scope"); + assertThat(artifact.getScope()).as("Check scope").isEqualTo("runtime"); } private void checkGroupIdScope(MavenProject project, String scopeValue, String groupId) { Artifact artifact; artifact = getArtifact(project, groupId, "scope-compile"); - assertEquals(scopeValue, artifact.getScope(), "Check scope"); + assertThat(artifact.getScope()).as("Check scope").isEqualTo(scopeValue); artifact = getArtifact(project, groupId, "scope-test"); - assertNull(artifact, "Check test dependency is not transitive"); + assertThat(artifact).as("Check test dependency is not transitive").isNull(); artifact = getArtifact(project, groupId, "scope-provided"); - assertNull(artifact, "Check provided dependency is not transitive"); + assertThat(artifact).as("Check provided dependency is not transitive").isNull(); artifact = getArtifact(project, groupId, "scope-default"); - assertEquals(scopeValue, artifact.getScope(), "Check scope"); + assertThat(artifact.getScope()).as("Check scope").isEqualTo(scopeValue); } private void checkArtifactIdScope(MavenProject project, String scope, String scopeValue) { String artifactId = "scope-" + scope; Artifact artifact = getArtifact(project, "maven-test", artifactId); - assertNotNull(artifact); - assertEquals(scopeValue, artifact.getScope(), "Check scope"); + assertThat(artifact).isNotNull(); + assertThat(artifact.getScope()).as("Check scope").isEqualTo(scopeValue); } private Artifact getArtifact(MavenProject project, String groupId, String artifactId) { diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java index 20938963639a..c3081e5280b0 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java @@ -30,7 +30,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertNotSame; /** @@ -45,7 +45,7 @@ void setUp() { } @Test - void testCacheKey() throws Exception { + void cacheKey() throws Exception { Artifact a1 = repositorySystem.createArtifact("testGroup", "testArtifact", "1.2.3", "jar"); @SuppressWarnings("deprecation") ArtifactRepository lr1 = new DelegatingLocalArtifactRepository(repositorySystem.createDefaultLocalRepository()); @@ -68,6 +68,6 @@ void testCacheKey() throws Exception { DefaultMavenMetadataCache.CacheKey k2 = new DefaultMavenMetadataCache.CacheKey(a2, false, lr2, Collections.singletonList(rr2)); - assertEquals(k1.hashCode(), k2.hashCode()); + assertThat(k2.hashCode()).isEqualTo(k1.hashCode()); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t00/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t00/ProjectInheritanceTest.java index 88f0ddcc3581..e25ab9c419ce 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t00/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t00/ProjectInheritanceTest.java @@ -22,7 +22,7 @@ import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * A test which demonstrates maven's recursive inheritance where @@ -51,41 +51,41 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { // ---------------------------------------------------------------------- @Test - void testProjectInheritance() throws Exception { + void projectInheritance() throws Exception { MavenProject p4 = getProject(projectFile("p4")); - assertEquals("p4", p4.getName()); + assertThat(p4.getName()).isEqualTo("p4"); // ---------------------------------------------------------------------- // Value inherited from p3 // ---------------------------------------------------------------------- - assertEquals("2000", p4.getInceptionYear()); + assertThat(p4.getInceptionYear()).isEqualTo("2000"); // ---------------------------------------------------------------------- // Value taken from p2 // ---------------------------------------------------------------------- - assertEquals("mailing-list", p4.getMailingLists().get(0).getName()); + assertThat(p4.getMailingLists().get(0).getName()).isEqualTo("mailing-list"); // ---------------------------------------------------------------------- // Value taken from p1 // ---------------------------------------------------------------------- - assertEquals("scm-url/p2/p3/p4", p4.getScm().getUrl()); + assertThat(p4.getScm().getUrl()).isEqualTo("scm-url/p2/p3/p4"); // ---------------------------------------------------------------------- // Value taken from p4 // ---------------------------------------------------------------------- - assertEquals("Codehaus", p4.getOrganization().getName()); + assertThat(p4.getOrganization().getName()).isEqualTo("Codehaus"); // ---------------------------------------------------------------------- // Value taken from super model // ---------------------------------------------------------------------- - assertEquals("4.0.0", p4.getModelVersion()); + assertThat(p4.getModelVersion()).isEqualTo("4.0.0"); - assertEquals("4.0.0", p4.getModelVersion()); + assertThat(p4.getModelVersion()).isEqualTo("4.0.0"); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t01/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t01/ProjectInheritanceTest.java index 8e5368718bc8..2312ae5faeb6 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t01/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t01/ProjectInheritanceTest.java @@ -22,7 +22,7 @@ import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * A test which demonstrates maven's recursive inheritance where @@ -48,14 +48,14 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { // ---------------------------------------------------------------------- @Test - void testProjectInheritance() throws Exception { + void projectInheritance() throws Exception { // ---------------------------------------------------------------------- // Check p0 value for org name // ---------------------------------------------------------------------- MavenProject p0 = getProject(projectFile("maven.t01", "p0")); - assertEquals("p0-org", p0.getOrganization().getName()); + assertThat(p0.getOrganization().getName()).isEqualTo("p0-org"); // ---------------------------------------------------------------------- // Check p1 value for org name @@ -63,7 +63,7 @@ void testProjectInheritance() throws Exception { MavenProject p1 = getProject(projectFile("maven.t01", "p1")); - assertEquals("p1-org", p1.getOrganization().getName()); + assertThat(p1.getOrganization().getName()).isEqualTo("p1-org"); // ---------------------------------------------------------------------- // Check p2 value for org name @@ -71,7 +71,7 @@ void testProjectInheritance() throws Exception { MavenProject p2 = getProject(projectFile("maven.t01", "p2")); - assertEquals("p2-org", p2.getOrganization().getName()); + assertThat(p2.getOrganization().getName()).isEqualTo("p2-org"); // ---------------------------------------------------------------------- // Check p2 value for org name @@ -79,7 +79,7 @@ void testProjectInheritance() throws Exception { MavenProject p3 = getProject(projectFile("maven.t01", "p3")); - assertEquals("p3-org", p3.getOrganization().getName()); + assertThat(p3.getOrganization().getName()).isEqualTo("p3-org"); // ---------------------------------------------------------------------- // Check p4 value for org name @@ -87,6 +87,6 @@ void testProjectInheritance() throws Exception { MavenProject p4 = getProject(projectFile("maven.t01", "p4")); - assertEquals("p4-org", p4.getOrganization().getName()); + assertThat(p4.getOrganization().getName()).isEqualTo("p4-org"); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java index b277dad26d7f..346ec706fa7e 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java @@ -32,9 +32,7 @@ import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.OS; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * A test which demonstrates maven's recursive inheritance where @@ -65,7 +63,7 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { @Test @DisabledOnOs(OS.WINDOWS) // need to investigate why it fails on windows - void testProjectInheritance() throws Exception { + void projectInheritance() throws Exception { File localRepo = getLocalRepositoryPath(); System.out.println("Local repository is at: " + localRepo.getAbsolutePath()); @@ -87,37 +85,37 @@ void testProjectInheritance() throws Exception { MavenProject project4 = getProject(pom4); MavenProject project5 = getProject(pom5); - assertEquals("p4", project4.getName()); + assertThat(project4.getName()).isEqualTo("p4"); // ---------------------------------------------------------------------- // Value inherited from p3 // ---------------------------------------------------------------------- - assertEquals("2000", project4.getInceptionYear()); + assertThat(project4.getInceptionYear()).isEqualTo("2000"); // ---------------------------------------------------------------------- // Value taken from p2 // ---------------------------------------------------------------------- - assertEquals("mailing-list", project4.getMailingLists().get(0).getName()); + assertThat(project4.getMailingLists().get(0).getName()).isEqualTo("mailing-list"); // ---------------------------------------------------------------------- // Value taken from p1 // ---------------------------------------------------------------------- - assertEquals("scm-url/p2/p3/p4", project4.getScm().getUrl()); + assertThat(project4.getScm().getUrl()).isEqualTo("scm-url/p2/p3/p4"); // ---------------------------------------------------------------------- // Value taken from p4 // ---------------------------------------------------------------------- - assertEquals("Codehaus", project4.getOrganization().getName()); + assertThat(project4.getOrganization().getName()).isEqualTo("Codehaus"); // ---------------------------------------------------------------------- // Value taken from super model // ---------------------------------------------------------------------- - assertEquals("4.0.0", project4.getModelVersion()); + assertThat(project4.getModelVersion()).isEqualTo("4.0.0"); Build build = project4.getBuild(); List plugins = build.getPlugins(); @@ -139,7 +137,7 @@ void testProjectInheritance() throws Exception { for (Plugin plugin : plugins) { String pluginArtifactId = plugin.getArtifactId(); - assertTrue(validPluginCounts.containsKey(pluginArtifactId), "Illegal plugin found: " + pluginArtifactId); + assertThat(validPluginCounts.containsKey(pluginArtifactId)).as("Illegal plugin found: " + pluginArtifactId).isTrue(); if (pluginArtifactId.equals(testPluginArtifactId)) { testPlugin = plugin; @@ -147,17 +145,17 @@ void testProjectInheritance() throws Exception { Integer count = validPluginCounts.get(pluginArtifactId); - assertEquals(0, (int) count, "Multiple copies of plugin: " + pluginArtifactId + " found in POM."); + assertThat((int) count).as("Multiple copies of plugin: " + pluginArtifactId + " found in POM.").isEqualTo(0); count = count + 1; validPluginCounts.put(pluginArtifactId, count); } - assertNotNull(testPlugin); + assertThat(testPlugin).isNotNull(); List executions = testPlugin.getExecutions(); - assertEquals(1, executions.size()); + assertThat(executions.size()).isEqualTo(1); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t03/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t03/ProjectInheritanceTest.java index 9ff8e4ac8bcb..4cff0737c0f7 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t03/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t03/ProjectInheritanceTest.java @@ -24,7 +24,7 @@ import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * A test which demonstrates maven's recursive inheritance where @@ -51,7 +51,7 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { // ---------------------------------------------------------------------- @Test - void testProjectInheritance() throws Exception { + void projectInheritance() throws Exception { File localRepo = getLocalRepositoryPath(); File pom0 = new File(localRepo, "p0/pom.xml"); @@ -63,6 +63,6 @@ void testProjectInheritance() throws Exception { MavenProject project0 = getProject(pom0); MavenProject project1 = getProject(pom1); - assertEquals(pom0Basedir, project1.getParent().getBasedir()); + assertThat(project1.getParent().getBasedir()).isEqualTo(pom0Basedir); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t04/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t04/ProjectInheritanceTest.java index e6ffa7cf23ae..56f49445f7bf 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t04/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t04/ProjectInheritanceTest.java @@ -26,9 +26,7 @@ import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Verifies the version of a dependency listed in a parent's @@ -55,7 +53,7 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { // ---------------------------------------------------------------------- @Test - void testDependencyManagementOverridesTransitiveDependencyVersion() throws Exception { + void dependencyManagementOverridesTransitiveDependencyVersion() throws Exception { File localRepo = getLocalRepositoryPath(); File pom0 = new File(localRepo, "p0/pom.xml"); File pom0Basedir = pom0.getParentFile(); @@ -65,18 +63,17 @@ void testDependencyManagementOverridesTransitiveDependencyVersion() throws Excep MavenProject project0 = getProjectWithDependencies(pom0); MavenProject project1 = getProjectWithDependencies(pom1); - assertEquals(pom0Basedir, project1.getParent().getBasedir()); + assertThat(project1.getParent().getBasedir()).isEqualTo(pom0Basedir); Set set = project1.getArtifacts(); - assertNotNull(set, "No artifacts"); - assertTrue(set.size() > 0, "No Artifacts"); - assertTrue(set.size() == 3, "Set size should be 3, is " + set.size()); + assertThat(set).as("No artifacts").isNotNull(); + assertThat(set.size() > 0).as("No Artifacts").isTrue(); + assertThat(set.size()).as("Set size should be 3, is " + set.size()).isEqualTo(3); for (Object aSet : set) { Artifact artifact = (Artifact) aSet; System.out.println("Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Optional=" + (artifact.isOptional() ? "true" : "false")); - assertTrue( - artifact.getVersion().equals("1.0"), "Incorrect version for " + artifact.getDependencyConflictId()); + assertThat(artifact.getVersion()).as("Incorrect version for " + artifact.getDependencyConflictId()).isEqualTo("1.0"); } } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t05/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t05/ProjectInheritanceTest.java index a0d610d21043..fae5eeec1326 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t05/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t05/ProjectInheritanceTest.java @@ -26,9 +26,7 @@ import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * A test which demonstrates maven's dependency management @@ -49,7 +47,7 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { // ---------------------------------------------------------------------- @Test - void testDependencyManagement() throws Exception { + void dependencyManagement() throws Exception { File localRepo = getLocalRepositoryPath(); File pom0 = new File(localRepo, "p0/pom.xml"); @@ -61,17 +59,16 @@ void testDependencyManagement() throws Exception { MavenProject project0 = getProjectWithDependencies(pom0); MavenProject project1 = getProjectWithDependencies(pom1); - assertEquals(pom0Basedir, project1.getParent().getBasedir()); + assertThat(project1.getParent().getBasedir()).isEqualTo(pom0Basedir); Set set = project1.getArtifacts(); - assertNotNull(set, "No artifacts"); - assertTrue(set.size() > 0, "No Artifacts"); + assertThat(set).as("No artifacts").isNotNull(); + assertThat(set.size() > 0).as("No Artifacts").isTrue(); for (Object aSet : set) { Artifact artifact = (Artifact) aSet; System.out.println("Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Scope: " + artifact.getScope()); - assertTrue( - artifact.getVersion().equals("1.0"), "Incorrect version for " + artifact.getDependencyConflictId()); + assertThat(artifact.getVersion()).as("Incorrect version for " + artifact.getDependencyConflictId()).isEqualTo("1.0"); } } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t06/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t06/ProjectInheritanceTest.java index 43a666040f1f..6f1e568b9c8a 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t06/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t06/ProjectInheritanceTest.java @@ -27,9 +27,7 @@ import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * A test which demonstrates maven's dependency management @@ -50,7 +48,7 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { // ---------------------------------------------------------------------- @Test - void testDependencyManagement() throws Exception { + void dependencyManagement() throws Exception { File localRepo = getLocalRepositoryPath(); File pom0 = new File(localRepo, "p0/pom.xml"); @@ -62,19 +60,18 @@ void testDependencyManagement() throws Exception { MavenProject project0 = getProjectWithDependencies(pom0); MavenProject project1 = getProjectWithDependencies(pom1); - assertEquals(pom0Basedir, project1.getParent().getBasedir()); + assertThat(project1.getParent().getBasedir()).isEqualTo(pom0Basedir); Set set = project1.getArtifacts(); - assertNotNull(set, "No artifacts"); - assertTrue(set.size() > 0, "No Artifacts"); + assertThat(set).as("No artifacts").isNotNull(); + assertThat(set.size() > 0).as("No Artifacts").isTrue(); Iterator iter = set.iterator(); - assertTrue(set.size() == 4, "Set size should be 4, is " + set.size()); + assertThat(set.size()).as("Set size should be 4, is " + set.size()).isEqualTo(4); while (iter.hasNext()) { Artifact artifact = (Artifact) iter.next(); System.out.println("Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Optional=" + (artifact.isOptional() ? "true" : "false")); - assertTrue( - artifact.getVersion().equals("1.0"), "Incorrect version for " + artifact.getDependencyConflictId()); + assertThat(artifact.getVersion()).as("Incorrect version for " + artifact.getDependencyConflictId()).isEqualTo("1.0"); } } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t07/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t07/ProjectInheritanceTest.java index 45ff8791fd81..7653adf86c33 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t07/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t07/ProjectInheritanceTest.java @@ -26,10 +26,7 @@ import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * A test which demonstrates maven's dependency management @@ -50,7 +47,7 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { // ---------------------------------------------------------------------- @Test - void testDependencyManagement() throws Exception { + void dependencyManagement() throws Exception { File localRepo = getLocalRepositoryPath(); File pom0 = new File(localRepo, "p0/pom.xml"); @@ -61,20 +58,19 @@ void testDependencyManagement() throws Exception { // load everything... MavenProject project1 = getProjectWithDependencies(pom1); - assertEquals(pom0Basedir, project1.getParent().getBasedir()); + assertThat(project1.getParent().getBasedir()).isEqualTo(pom0Basedir); System.out.println("Project " + project1.getId() + " " + project1); Set set = project1.getArtifacts(); - assertNotNull(set, "No artifacts"); - assertTrue(set.size() > 0, "No Artifacts"); - assertTrue(set.size() == 3, "Set size should be 3, is " + set.size()); + assertThat(set).as("No artifacts").isNotNull(); + assertThat(set.size() > 0).as("No Artifacts").isTrue(); + assertThat(set.size()).as("Set size should be 3, is " + set.size()).isEqualTo(3); for (Object aSet : set) { Artifact artifact = (Artifact) aSet; - assertFalse(artifact.getArtifactId().equals("t07-d")); + assertThat(artifact.getArtifactId()).isNotEqualTo("t07-d"); System.out.println("Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Optional=" + (artifact.isOptional() ? "true" : "false")); - assertTrue( - artifact.getVersion().equals("1.0"), "Incorrect version for " + artifact.getDependencyConflictId()); + assertThat(artifact.getVersion()).as("Incorrect version for " + artifact.getDependencyConflictId()).isEqualTo("1.0"); } } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t08/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t08/ProjectInheritanceTest.java index 5158f52e29de..fc3e776b51e8 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t08/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t08/ProjectInheritanceTest.java @@ -27,9 +27,7 @@ import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * A test which demonstrates maven's dependency management @@ -50,7 +48,7 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { // ---------------------------------------------------------------------- @Test - void testDependencyManagement() throws Exception { + void dependencyManagement() throws Exception { File localRepo = getLocalRepositoryPath(); File pom0 = new File(localRepo, "p0/pom.xml"); @@ -62,20 +60,19 @@ void testDependencyManagement() throws Exception { MavenProject project0 = getProjectWithDependencies(pom0); MavenProject project1 = getProjectWithDependencies(pom1); - assertEquals(pom0Basedir, project1.getParent().getBasedir()); + assertThat(project1.getParent().getBasedir()).isEqualTo(pom0Basedir); System.out.println("Project " + project1.getId() + " " + project1); Set set = project1.getArtifacts(); - assertNotNull(set, "No artifacts"); - assertTrue(set.size() > 0, "No Artifacts"); + assertThat(set).as("No artifacts").isNotNull(); + assertThat(set.size() > 0).as("No Artifacts").isTrue(); Iterator iter = set.iterator(); - assertTrue(set.size() == 4, "Set size should be 4, is " + set.size()); + assertThat(set.size()).as("Set size should be 4, is " + set.size()).isEqualTo(4); while (iter.hasNext()) { Artifact artifact = (Artifact) iter.next(); System.out.println("Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Optional=" + (artifact.isOptional() ? "true" : "false")); - assertTrue( - artifact.getVersion().equals("1.0"), "Incorrect version for " + artifact.getDependencyConflictId()); + assertThat(artifact.getVersion()).as("Incorrect version for " + artifact.getDependencyConflictId()).isEqualTo("1.0"); } } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java index 149b7b04e161..0d639ee4c711 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java @@ -25,10 +25,7 @@ import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Verifies exclusions listed in dependencyManagement are valid for @@ -62,7 +59,7 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { * a & b only. */ @Test - void testDependencyManagementExclusionsExcludeTransitively() throws Exception { + void dependencyManagementExclusionsExcludeTransitively() throws Exception { File localRepo = getLocalRepositoryPath(); File pom0 = new File(localRepo, "p0/pom.xml"); @@ -73,17 +70,17 @@ void testDependencyManagementExclusionsExcludeTransitively() throws Exception { MavenProject project0 = getProjectWithDependencies(pom0); MavenProject project1 = getProjectWithDependencies(pom1); - assertNotNull(project1.getParent(), "Parent is null"); - assertEquals(pom0Basedir, project1.getParent().getBasedir()); + assertThat(project1.getParent()).as("Parent is null").isNotNull(); + assertThat(project1.getParent().getBasedir()).isEqualTo(pom0Basedir); Map map = project1.getArtifactMap(); - assertNotNull(map, "No artifacts"); - assertTrue(map.size() > 0, "No Artifacts"); - assertTrue(map.size() == 2, "Set size should be 2, is " + map.size()); + assertThat(map).as("No artifacts").isNotNull(); + assertThat(map.size() > 0).as("No Artifacts").isTrue(); + assertThat(map.size()).as("Set size should be 2, is " + map.size()).isEqualTo(2); - assertTrue(map.containsKey("maven-test:t09-a"), "maven-test:t09-a is not in the project"); - assertTrue(map.containsKey("maven-test:t09-b"), "maven-test:t09-b is not in the project"); - assertFalse(map.containsKey("maven-test:t09-c"), "maven-test:t09-c is in the project"); + assertThat(map.containsKey("maven-test:t09-a")).as("maven-test:t09-a is not in the project").isTrue(); + assertThat(map.containsKey("maven-test:t09-b")).as("maven-test:t09-b is not in the project").isTrue(); + assertThat(map.containsKey("maven-test:t09-c")).as("maven-test:t09-c is in the project").isFalse(); } /** @@ -97,7 +94,7 @@ void testDependencyManagementExclusionsExcludeTransitively() throws Exception { * @throws Exception */ @Test - void testDependencyManagementExclusionDoesNotOverrideGloballyForTransitives() throws Exception { + void dependencyManagementExclusionDoesNotOverrideGloballyForTransitives() throws Exception { File localRepo = getLocalRepositoryPath(); File pom0 = new File(localRepo, "p0/pom.xml"); @@ -108,15 +105,15 @@ void testDependencyManagementExclusionDoesNotOverrideGloballyForTransitives() th MavenProject project0 = getProjectWithDependencies(pom0); MavenProject project2 = getProjectWithDependencies(pom2); - assertEquals(pom0Basedir, project2.getParent().getBasedir()); + assertThat(project2.getParent().getBasedir()).isEqualTo(pom0Basedir); Map map = project2.getArtifactMap(); - assertNotNull(map, "No artifacts"); - assertTrue(map.size() > 0, "No Artifacts"); - assertTrue(map.size() == 4, "Set size should be 4, is " + map.size()); + assertThat(map).as("No artifacts").isNotNull(); + assertThat(map.size() > 0).as("No Artifacts").isTrue(); + assertThat(map.size()).as("Set size should be 4, is " + map.size()).isEqualTo(4); - assertTrue(map.containsKey("maven-test:t09-a"), "maven-test:t09-a is not in the project"); - assertTrue(map.containsKey("maven-test:t09-b"), "maven-test:t09-b is not in the project"); - assertTrue(map.containsKey("maven-test:t09-c"), "maven-test:t09-c is not in the project"); - assertTrue(map.containsKey("maven-test:t09-d"), "maven-test:t09-d is not in the project"); + assertThat(map.containsKey("maven-test:t09-a")).as("maven-test:t09-a is not in the project").isTrue(); + assertThat(map.containsKey("maven-test:t09-b")).as("maven-test:t09-b is not in the project").isTrue(); + assertThat(map.containsKey("maven-test:t09-c")).as("maven-test:t09-c is not in the project").isTrue(); + assertThat(map.containsKey("maven-test:t09-d")).as("maven-test:t09-d is not in the project").isTrue(); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t10/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t10/ProjectInheritanceTest.java index e9004e01133a..cf654982fad2 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t10/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t10/ProjectInheritanceTest.java @@ -26,9 +26,7 @@ import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Verifies scope inheritance of direct and transitive dependencies. @@ -56,7 +54,7 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { // ---------------------------------------------------------------------- @Test - void testDependencyManagementOverridesTransitiveDependencyVersion() throws Exception { + void dependencyManagementOverridesTransitiveDependencyVersion() throws Exception { File localRepo = getLocalRepositoryPath(); File pom0 = new File(localRepo, "p0/pom.xml"); @@ -67,29 +65,29 @@ void testDependencyManagementOverridesTransitiveDependencyVersion() throws Excep MavenProject project0 = getProjectWithDependencies(pom0); MavenProject project1 = getProjectWithDependencies(pom1); - assertEquals(pom0Basedir, project1.getParent().getBasedir()); + assertThat(project1.getParent().getBasedir()).isEqualTo(pom0Basedir); System.out.println("Project " + project1.getId() + " " + project1); Map map = project1.getArtifactMap(); - assertNotNull(map, "No artifacts"); - assertTrue(map.size() > 0, "No Artifacts"); - assertTrue(map.size() == 3, "Set size should be 3, is " + map.size()); + assertThat(map).as("No artifacts").isNotNull(); + assertThat(map.size() > 0).as("No Artifacts").isTrue(); + assertThat(map.size()).as("Set size should be 3, is " + map.size()).isEqualTo(3); Artifact a = (Artifact) map.get("maven-test:t10-a"); Artifact b = (Artifact) map.get("maven-test:t10-b"); Artifact c = (Artifact) map.get("maven-test:t10-c"); - assertNotNull(a); - assertNotNull(b); - assertNotNull(c); + assertThat(a).isNotNull(); + assertThat(b).isNotNull(); + assertThat(c).isNotNull(); // inherited from depMgmt System.out.println(a.getScope()); - assertTrue(a.getScope().equals("test"), "Incorrect scope for " + a.getDependencyConflictId()); + assertThat(a.getScope()).as("Incorrect scope for " + a.getDependencyConflictId()).isEqualTo("test"); // transitive dep, overridden b depMgmt - assertTrue(b.getScope().equals("runtime"), "Incorrect scope for " + b.getDependencyConflictId()); + assertThat(b.getScope()).as("Incorrect scope for " + b.getDependencyConflictId()).isEqualTo("runtime"); // direct dep, overrides depMgmt - assertTrue(c.getScope().equals("runtime"), "Incorrect scope for " + c.getDependencyConflictId()); + assertThat(c.getScope()).as("Incorrect scope for " + c.getDependencyConflictId()).isEqualTo("runtime"); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t11/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t11/ProjectInheritanceTest.java index 9b0a188c5666..5cd460f65b93 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t11/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t11/ProjectInheritanceTest.java @@ -24,8 +24,7 @@ import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Verifies scope of root project is preserved regardless of parent dependency management. @@ -47,7 +46,7 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { // ---------------------------------------------------------------------- @Test - void testDependencyManagementDoesNotOverrideScopeOfCurrentArtifact() throws Exception { + void dependencyManagementDoesNotOverrideScopeOfCurrentArtifact() throws Exception { File localRepo = getLocalRepositoryPath(); File pom0 = new File(localRepo, "p0/pom.xml"); @@ -58,9 +57,7 @@ void testDependencyManagementDoesNotOverrideScopeOfCurrentArtifact() throws Exce MavenProject project0 = getProjectWithDependencies(pom0); MavenProject project1 = getProjectWithDependencies(pom1); - assertEquals(pom0Basedir, project1.getParent().getBasedir()); - assertNull( - project1.getArtifact().getScope(), - "dependencyManagement has overwritten the scope of the currently building child project"); + assertThat(project1.getParent().getBasedir()).isEqualTo(pom0Basedir); + assertThat(project1.getArtifact().getScope()).as("dependencyManagement has overwritten the scope of the currently building child project").isNull(); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12/ProjectInheritanceTest.java index 0a30d34ffa28..b024f7b473b0 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12/ProjectInheritanceTest.java @@ -26,8 +26,7 @@ import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Verifies that plugin execution sections in the parent POM that have @@ -48,7 +47,7 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { // ---------------------------------------------------------------------- @Test - void testFalsePluginExecutionInheritValue() throws Exception { + void falsePluginExecutionInheritValue() throws Exception { File localRepo = getLocalRepositoryPath(); File pom0 = new File(localRepo, "p0/pom.xml"); @@ -61,11 +60,9 @@ void testFalsePluginExecutionInheritValue() throws Exception { Map pluginMap = project1.getBuild().getPluginsAsMap(); Plugin compilerPlugin = (Plugin) pluginMap.get("org.apache.maven.plugins:maven-compiler-plugin"); - assertNotNull(compilerPlugin); + assertThat(compilerPlugin).isNotNull(); Map executionMap = compilerPlugin.getExecutionsAsMap(); - assertNull( - executionMap.get("test"), - "Plugin execution: 'test' should NOT exist in the compiler plugin specification for the child project!"); + assertThat(executionMap.get("test")).as("Plugin execution: 'test' should NOT exist in the compiler plugin specification for the child project!").isNull(); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12scm/ProjectInheritanceTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12scm/ProjectInheritanceTest.java index 61c0c1fb0fac..716c045cfaa6 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12scm/ProjectInheritanceTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12scm/ProjectInheritanceTest.java @@ -24,7 +24,7 @@ import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Verifies SCM inheritance uses modules statement from parent. @@ -43,7 +43,7 @@ class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase { // ---------------------------------------------------------------------- @Test - void testScmInfoCalculatedCorrectlyOnParentAndChildRead() throws Exception { + void scmInfoCalculatedCorrectlyOnParentAndChildRead() throws Exception { File localRepo = getLocalRepositoryPath(); File pom0 = new File(localRepo, "p0/pom.xml"); @@ -54,14 +54,13 @@ void testScmInfoCalculatedCorrectlyOnParentAndChildRead() throws Exception { MavenProject project0 = getProject(pom0); MavenProject project1 = getProject(pom1); - assertEquals(project1.getScm().getUrl(), project0.getScm().getUrl() + "/modules/p1"); - assertEquals(project1.getScm().getConnection(), project0.getScm().getConnection() + "/modules/p1"); - assertEquals( - project1.getScm().getDeveloperConnection(), project0.getScm().getDeveloperConnection() + "/modules/p1"); + assertThat(project0.getScm().getUrl() + "/modules/p1").isEqualTo(project1.getScm().getUrl()); + assertThat(project0.getScm().getConnection() + "/modules/p1").isEqualTo(project1.getScm().getConnection()); + assertThat(project0.getScm().getDeveloperConnection() + "/modules/p1").isEqualTo(project1.getScm().getDeveloperConnection()); } @Test - void testScmInfoCalculatedCorrectlyOnChildOnlyRead() throws Exception { + void scmInfoCalculatedCorrectlyOnChildOnlyRead() throws Exception { File localRepo = getLocalRepositoryPath(); File pom1 = new File(localRepo, "p0/modules/p1/pom.xml"); @@ -69,8 +68,8 @@ void testScmInfoCalculatedCorrectlyOnChildOnlyRead() throws Exception { // load the child project, which inherits from p0... MavenProject project1 = getProject(pom1); - assertEquals("http://host/viewer?path=/p0/modules/p1", project1.getScm().getUrl()); - assertEquals("scm:svn:http://host/p0/modules/p1", project1.getScm().getConnection()); - assertEquals("scm:svn:https://host/p0/modules/p1", project1.getScm().getDeveloperConnection()); + assertThat(project1.getScm().getUrl()).isEqualTo("http://host/viewer?path=/p0/modules/p1"); + assertThat(project1.getScm().getConnection()).isEqualTo("scm:svn:http://host/p0/modules/p1"); + assertThat(project1.getScm().getDeveloperConnection()).isEqualTo("scm:svn:https://host/p0/modules/p1"); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java index d194a78e9c71..c6cad472c8fe 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java @@ -22,35 +22,35 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; @Deprecated class DefaultPathTranslatorTest { @Test - void testAlignToBasedirWhereBasedirExpressionIsTheCompleteValue() { + void alignToBasedirWhereBasedirExpressionIsTheCompleteValue() { File basedir = new File(System.getProperty("java.io.tmpdir"), "test").getAbsoluteFile(); String aligned = new DefaultPathTranslator().alignToBaseDirectory("${basedir}", basedir); - assertEquals(basedir.getAbsolutePath(), aligned); + assertThat(aligned).isEqualTo(basedir.getAbsolutePath()); } @Test - void testAlignToBasedirWhereBasedirExpressionIsTheValuePrefix() { + void alignToBasedirWhereBasedirExpressionIsTheValuePrefix() { File basedir = new File(System.getProperty("java.io.tmpdir"), "test").getAbsoluteFile(); String aligned = new DefaultPathTranslator().alignToBaseDirectory("${basedir}/dir", basedir); - assertEquals(new File(basedir, "dir").getAbsolutePath(), aligned); + assertThat(aligned).isEqualTo(new File(basedir, "dir").getAbsolutePath()); } @Test - void testUnalignToBasedirWherePathEqualsBasedir() { + void unalignToBasedirWherePathEqualsBasedir() { File basedir = new File(System.getProperty("java.io.tmpdir"), "test").getAbsoluteFile(); String unaligned = new DefaultPathTranslator().unalignFromBaseDirectory(basedir.getAbsolutePath(), basedir); - assertEquals(".", unaligned); + assertThat(unaligned).isEqualTo("."); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/DefaultMirrorSelectorTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/DefaultMirrorSelectorTest.java index 2d2a2631806b..7e43f5579753 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/DefaultMirrorSelectorTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/DefaultMirrorSelectorTest.java @@ -22,14 +22,14 @@ import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.assertj.core.api.Assertions.assertThat; @Deprecated class DefaultMirrorSelectorTest { @Test - void testMirrorWithMirrorOfPatternContainingANegationIsNotSelected() { + void mirrorWithMirrorOfPatternContainingANegationIsNotSelected() { ArtifactRepository repository = new DefaultArtifactRepository("snapshots.repo", "http://whatever", null); String pattern = "external:*, !snapshots.repo"; - assertFalse(DefaultMirrorSelector.matchPattern(repository, pattern)); + assertThat(DefaultMirrorSelector.matchPattern(repository, pattern)).isFalse(); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java index 8f9709a175c0..7d23690c5b34 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java @@ -68,10 +68,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@link LegacyRepositorySystem}. @@ -116,7 +114,7 @@ protected ArtifactRepository getLocalRepository() throws Exception { } @Test - void testThatASystemScopedDependencyIsNotResolvedFromRepositories() throws Exception { + void thatASystemScopedDependencyIsNotResolvedFromRepositories() throws Exception { // // We should get a whole slew of dependencies resolving this artifact transitively // @@ -178,14 +176,14 @@ public void setPath(ProducedArtifact artifact, Path path) { ArtifactResolutionResult result = repositorySystem.resolve(request); resolutionErrorHandler.throwErrors(request, result); - assertEquals(2, result.getArtifacts().size()); + assertThat(result.getArtifacts().size()).isEqualTo(2); // // System scoped version which should // d.setScope(Artifact.SCOPE_SYSTEM); File file = new File(getBasedir(), "src/test/repository-system/maven-core-2.1.0.jar"); - assertTrue(file.exists()); + assertThat(file.exists()).isTrue(); d.setSystemPath(file.getCanonicalPath()); artifact = repositorySystem.createDependencyArtifact(d); @@ -202,13 +200,13 @@ public void setPath(ProducedArtifact artifact, Path path) { result = repositorySystem.resolve(request); resolutionErrorHandler.throwErrors(request, result); - assertEquals(1, result.getArtifacts().size()); + assertThat(result.getArtifacts().size()).isEqualTo(1); // // Put in a bogus file to make sure missing files cause the resolution to fail. // file = new File(getBasedir(), "src/test/repository-system/maven-monkey-2.1.0.jar"); - assertFalse(file.exists()); + assertThat(file.exists()).isFalse(); d.setSystemPath(file.getCanonicalPath()); artifact = repositorySystem.createDependencyArtifact(d); @@ -226,24 +224,24 @@ public void setPath(ProducedArtifact artifact, Path path) { result = repositorySystem.resolve(request); resolutionErrorHandler.throwErrors(request, result); } catch (Exception e) { - assertTrue(result.hasMissingArtifacts()); + assertThat(result.hasMissingArtifacts()).isTrue(); } } @Test - void testLocalRepositoryBasedir() throws Exception { + void localRepositoryBasedir() throws Exception { File localRepoDir = new File("").getAbsoluteFile(); ArtifactRepository localRepo = repositorySystem.createLocalRepository(localRepoDir); String basedir = localRepo.getBasedir(); - assertFalse(basedir.endsWith("/")); - assertFalse(basedir.endsWith("\\")); + assertThat(basedir.endsWith("/")).isFalse(); + assertThat(basedir.endsWith("\\")).isFalse(); - assertEquals(localRepoDir, new File(basedir)); + assertThat(new File(basedir)).isEqualTo(localRepoDir); - assertEquals(localRepoDir.getPath(), basedir); + assertThat(basedir).isEqualTo(localRepoDir.getPath()); } @Inject diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java index 34c859807cb0..2a42618491e0 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java @@ -30,10 +30,7 @@ import org.codehaus.plexus.testing.PlexusTest; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; @PlexusTest @Deprecated @@ -45,58 +42,58 @@ class MirrorProcessorTest { private ArtifactRepositoryFactory repositorySystem; @Test - void testExternalURL() { - assertTrue(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://somehost"))); - assertTrue(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://somehost:9090/somepath"))); - assertTrue(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "ftp://somehost"))); - assertTrue(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://192.168.101.1"))); - assertTrue(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://"))); + void externalURL() { + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://somehost"))).isTrue(); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://somehost:9090/somepath"))).isTrue(); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "ftp://somehost"))).isTrue(); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://192.168.101.1"))).isTrue(); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://"))).isTrue(); // these are local - assertFalse(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://localhost:8080"))); - assertFalse(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://127.0.0.1:9090"))); - assertFalse(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "file://localhost/somepath"))); - assertFalse(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "file://localhost/D:/somepath"))); - assertFalse(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://localhost"))); - assertFalse(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://127.0.0.1"))); - assertFalse(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "file:///somepath"))); - assertFalse(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "file://D:/somepath"))); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://localhost:8080"))).isFalse(); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://127.0.0.1:9090"))).isFalse(); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "file://localhost/somepath"))).isFalse(); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "file://localhost/D:/somepath"))).isFalse(); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://localhost"))).isFalse(); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "http://127.0.0.1"))).isFalse(); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "file:///somepath"))).isFalse(); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "file://D:/somepath"))).isFalse(); // not a proper url so returns false; - assertFalse(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "192.168.101.1"))); - assertFalse(DefaultMirrorSelector.isExternalRepo(getRepo("foo", ""))); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", "192.168.101.1"))).isFalse(); + assertThat(DefaultMirrorSelector.isExternalRepo(getRepo("foo", ""))).isFalse(); } @Test - void testMirrorLookup() { + void mirrorLookup() { Mirror mirrorA = newMirror("a", "a", "http://a"); Mirror mirrorB = newMirror("b", "b", "http://b"); List mirrors = Arrays.asList(mirrorA, mirrorB); - assertSame(mirrorA, mirrorSelector.getMirror(getRepo("a", "http://a.a"), mirrors)); + assertThat(mirrorSelector.getMirror(getRepo("a", "http://a.a"), mirrors)).isSameAs(mirrorA); - assertSame(mirrorB, mirrorSelector.getMirror(getRepo("b", "http://a.a"), mirrors)); + assertThat(mirrorSelector.getMirror(getRepo("b", "http://a.a"), mirrors)).isSameAs(mirrorB); - assertNull(mirrorSelector.getMirror(getRepo("c", "http://c.c"), mirrors)); + assertThat(mirrorSelector.getMirror(getRepo("c", "http://c.c"), mirrors)).isNull(); } @Test - void testMirrorWildcardLookup() { + void mirrorWildcardLookup() { Mirror mirrorA = newMirror("a", "a", "http://a"); Mirror mirrorB = newMirror("b", "b", "http://b"); Mirror mirrorC = newMirror("c", "*", "http://wildcard"); List mirrors = Arrays.asList(mirrorA, mirrorB, mirrorC); - assertSame(mirrorA, mirrorSelector.getMirror(getRepo("a", "http://a.a"), mirrors)); + assertThat(mirrorSelector.getMirror(getRepo("a", "http://a.a"), mirrors)).isSameAs(mirrorA); - assertSame(mirrorB, mirrorSelector.getMirror(getRepo("b", "http://a.a"), mirrors)); + assertThat(mirrorSelector.getMirror(getRepo("b", "http://a.a"), mirrors)).isSameAs(mirrorB); - assertSame(mirrorC, mirrorSelector.getMirror(getRepo("c", "http://c.c"), mirrors)); + assertThat(mirrorSelector.getMirror(getRepo("c", "http://c.c"), mirrors)).isSameAs(mirrorC); } @Test - void testMirrorStopOnFirstMatch() { + void mirrorStopOnFirstMatch() { // exact matches win first Mirror mirrorA2 = newMirror("a2", "a,b", "http://a2"); Mirror mirrorA = newMirror("a", "a", "http://a"); @@ -110,90 +107,90 @@ void testMirrorStopOnFirstMatch() { List mirrors = Arrays.asList(mirrorA2, mirrorA, mirrorA3, mirrorB, mirrorC, mirrorC2, mirrorC3); - assertSame(mirrorA, mirrorSelector.getMirror(getRepo("a", "http://a.a"), mirrors)); + assertThat(mirrorSelector.getMirror(getRepo("a", "http://a.a"), mirrors)).isSameAs(mirrorA); - assertSame(mirrorB, mirrorSelector.getMirror(getRepo("b", "http://a.a"), mirrors)); + assertThat(mirrorSelector.getMirror(getRepo("b", "http://a.a"), mirrors)).isSameAs(mirrorB); - assertSame(mirrorC2, mirrorSelector.getMirror(getRepo("c", "http://c.c"), mirrors)); + assertThat(mirrorSelector.getMirror(getRepo("c", "http://c.c"), mirrors)).isSameAs(mirrorC2); - assertSame(mirrorC, mirrorSelector.getMirror(getRepo("d", "http://d"), mirrors)); + assertThat(mirrorSelector.getMirror(getRepo("d", "http://d"), mirrors)).isSameAs(mirrorC); - assertSame(mirrorC, mirrorSelector.getMirror(getRepo("e", "http://e"), mirrors)); + assertThat(mirrorSelector.getMirror(getRepo("e", "http://e"), mirrors)).isSameAs(mirrorC); - assertSame(mirrorC2, mirrorSelector.getMirror(getRepo("f", "http://f"), mirrors)); + assertThat(mirrorSelector.getMirror(getRepo("f", "http://f"), mirrors)).isSameAs(mirrorC2); } @Test - void testPatterns() { - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a"), "*")); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a"), "*,")); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a"), ",*,")); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a"), "*,")); + void patterns() { + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), "*")).isTrue(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), "*,")).isTrue(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), ",*,")).isTrue(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), "*,")).isTrue(); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a"), "a")); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a"), "a,")); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a"), ",a,")); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a"), "a,")); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), "a")).isTrue(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), "a,")).isTrue(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), ",a,")).isTrue(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), "a,")).isTrue(); - assertFalse(DefaultMirrorSelector.matchPattern(getRepo("b"), "a")); - assertFalse(DefaultMirrorSelector.matchPattern(getRepo("b"), "a,")); - assertFalse(DefaultMirrorSelector.matchPattern(getRepo("b"), ",a")); - assertFalse(DefaultMirrorSelector.matchPattern(getRepo("b"), ",a,")); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("b"), "a")).isFalse(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("b"), "a,")).isFalse(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("b"), ",a")).isFalse(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("b"), ",a,")).isFalse(); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a"), "a,b")); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("b"), "a,b")); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), "a,b")).isTrue(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("b"), "a,b")).isTrue(); - assertFalse(DefaultMirrorSelector.matchPattern(getRepo("c"), "a,b")); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("c"), "a,b")).isFalse(); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a"), "*")); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a"), "*,b")); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a"), "*,!b")); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), "*")).isTrue(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), "*,b")).isTrue(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), "*,!b")).isTrue(); - assertFalse(DefaultMirrorSelector.matchPattern(getRepo("a"), "*,!a")); - assertFalse(DefaultMirrorSelector.matchPattern(getRepo("a"), "!a,*")); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), "*,!a")).isFalse(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a"), "!a,*")).isFalse(); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("c"), "*,!a")); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("c"), "!a,*")); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("c"), "*,!a")).isTrue(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("c"), "!a,*")).isTrue(); - assertFalse(DefaultMirrorSelector.matchPattern(getRepo("c"), "!a,!c")); - assertFalse(DefaultMirrorSelector.matchPattern(getRepo("d"), "!a,!c*")); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("c"), "!a,!c")).isFalse(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("d"), "!a,!c*")).isFalse(); } @Test - void testPatternsWithExternal() { - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a", "http://localhost"), "*")); - assertFalse(DefaultMirrorSelector.matchPattern(getRepo("a", "http://localhost"), "external:*")); + void patternsWithExternal() { + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a", "http://localhost"), "*")).isTrue(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a", "http://localhost"), "external:*")).isFalse(); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a", "http://localhost"), "external:*,a")); - assertFalse(DefaultMirrorSelector.matchPattern(getRepo("a", "http://localhost"), "external:*,!a")); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("a", "http://localhost"), "a,external:*")); - assertFalse(DefaultMirrorSelector.matchPattern(getRepo("a", "http://localhost"), "!a,external:*")); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a", "http://localhost"), "external:*,a")).isTrue(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a", "http://localhost"), "external:*,!a")).isFalse(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a", "http://localhost"), "a,external:*")).isTrue(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("a", "http://localhost"), "!a,external:*")).isFalse(); - assertFalse(DefaultMirrorSelector.matchPattern(getRepo("c", "http://localhost"), "!a,external:*")); - assertTrue(DefaultMirrorSelector.matchPattern(getRepo("c", "http://somehost"), "!a,external:*")); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("c", "http://localhost"), "!a,external:*")).isFalse(); + assertThat(DefaultMirrorSelector.matchPattern(getRepo("c", "http://somehost"), "!a,external:*")).isTrue(); } @Test - void testLayoutPattern() { - assertTrue(DefaultMirrorSelector.matchesLayout("default", null)); - assertTrue(DefaultMirrorSelector.matchesLayout("default", "")); - assertTrue(DefaultMirrorSelector.matchesLayout("default", "*")); + void layoutPattern() { + assertThat(DefaultMirrorSelector.matchesLayout("default", null)).isTrue(); + assertThat(DefaultMirrorSelector.matchesLayout("default", "")).isTrue(); + assertThat(DefaultMirrorSelector.matchesLayout("default", "*")).isTrue(); - assertTrue(DefaultMirrorSelector.matchesLayout("default", "default")); - assertFalse(DefaultMirrorSelector.matchesLayout("default", "legacy")); + assertThat(DefaultMirrorSelector.matchesLayout("default", "default")).isTrue(); + assertThat(DefaultMirrorSelector.matchesLayout("default", "legacy")).isFalse(); - assertTrue(DefaultMirrorSelector.matchesLayout("default", "legacy,default")); - assertTrue(DefaultMirrorSelector.matchesLayout("default", "default,legacy")); + assertThat(DefaultMirrorSelector.matchesLayout("default", "legacy,default")).isTrue(); + assertThat(DefaultMirrorSelector.matchesLayout("default", "default,legacy")).isTrue(); - assertFalse(DefaultMirrorSelector.matchesLayout("default", "legacy,!default")); - assertFalse(DefaultMirrorSelector.matchesLayout("default", "!default,legacy")); + assertThat(DefaultMirrorSelector.matchesLayout("default", "legacy,!default")).isFalse(); + assertThat(DefaultMirrorSelector.matchesLayout("default", "!default,legacy")).isFalse(); - assertFalse(DefaultMirrorSelector.matchesLayout("default", "*,!default")); - assertFalse(DefaultMirrorSelector.matchesLayout("default", "!default,*")); + assertThat(DefaultMirrorSelector.matchesLayout("default", "*,!default")).isFalse(); + assertThat(DefaultMirrorSelector.matchesLayout("default", "!default,*")).isFalse(); } @Test - void testMirrorLayoutConsideredForMatching() { + void mirrorLayoutConsideredForMatching() { ArtifactRepository repo = getRepo("a"); Mirror mirrorA = newMirror("a", "a", null, "http://a"); @@ -202,11 +199,11 @@ void testMirrorLayoutConsideredForMatching() { Mirror mirrorC = newMirror("c", "*", null, "http://c"); Mirror mirrorD = newMirror("d", "*", "p2", "http://d"); - assertSame(mirrorA, mirrorSelector.getMirror(repo, Arrays.asList(mirrorA))); - assertNull(mirrorSelector.getMirror(repo, Arrays.asList(mirrorB))); + assertThat(mirrorSelector.getMirror(repo, Arrays.asList(mirrorA))).isSameAs(mirrorA); + assertThat(mirrorSelector.getMirror(repo, Arrays.asList(mirrorB))).isNull(); - assertSame(mirrorC, mirrorSelector.getMirror(repo, Arrays.asList(mirrorC))); - assertNull(mirrorSelector.getMirror(repo, Arrays.asList(mirrorD))); + assertThat(mirrorSelector.getMirror(repo, Arrays.asList(mirrorC))).isSameAs(mirrorC); + assertThat(mirrorSelector.getMirror(repo, Arrays.asList(mirrorD))).isNull(); } /** diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManagerTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManagerTest.java index e06318c1db31..381efada1966 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManagerTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManagerTest.java @@ -33,11 +33,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; @Deprecated class DefaultUpdateCheckManagerTest extends AbstractArtifactComponentTestCase { @@ -61,7 +57,7 @@ public void setUp() throws Exception { } @Test - void testArtifact() throws Exception { + void artifact() throws Exception { ArtifactRepository remoteRepository = remoteRepository(); ArtifactRepository localRepository = localRepository(); @@ -74,22 +70,21 @@ void testArtifact() throws Exception { File touchFile = updateCheckManager.getTouchfile(a); touchFile.delete(); - assertTrue(updateCheckManager.isUpdateRequired(a, remoteRepository)); + assertThat(updateCheckManager.isUpdateRequired(a, remoteRepository)).isTrue(); file.getParentFile().mkdirs(); file.createNewFile(); updateCheckManager.touch(a, remoteRepository, null); - assertFalse(updateCheckManager.isUpdateRequired(a, remoteRepository)); + assertThat(updateCheckManager.isUpdateRequired(a, remoteRepository)).isFalse(); - assertNull( - updateCheckManager.readLastUpdated(touchFile, updateCheckManager.getRepositoryKey(remoteRepository))); + assertThat(updateCheckManager.readLastUpdated(touchFile, updateCheckManager.getRepositoryKey(remoteRepository))).isNull(); - assertFalse(updateCheckManager.getTouchfile(a).exists()); + assertThat(updateCheckManager.getTouchfile(a).exists()).isFalse(); } @Test - void testMissingArtifact() throws Exception { + void missingArtifact() throws Exception { ArtifactRepository remoteRepository = remoteRepository(); ArtifactRepository localRepository = localRepository(); @@ -102,19 +97,18 @@ void testMissingArtifact() throws Exception { File touchFile = updateCheckManager.getTouchfile(a); touchFile.delete(); - assertTrue(updateCheckManager.isUpdateRequired(a, remoteRepository)); + assertThat(updateCheckManager.isUpdateRequired(a, remoteRepository)).isTrue(); updateCheckManager.touch(a, remoteRepository, null); - assertFalse(updateCheckManager.isUpdateRequired(a, remoteRepository)); + assertThat(updateCheckManager.isUpdateRequired(a, remoteRepository)).isFalse(); - assertFalse(file.exists()); - assertNotNull( - updateCheckManager.readLastUpdated(touchFile, updateCheckManager.getRepositoryKey(remoteRepository))); + assertThat(file.exists()).isFalse(); + assertThat(updateCheckManager.readLastUpdated(touchFile, updateCheckManager.getRepositoryKey(remoteRepository))).isNotNull(); } @Test - void testPom() throws Exception { + void pom() throws Exception { ArtifactRepository remoteRepository = remoteRepository(); ArtifactRepository localRepository = localRepository(); @@ -127,22 +121,21 @@ void testPom() throws Exception { File touchFile = updateCheckManager.getTouchfile(a); touchFile.delete(); - assertTrue(updateCheckManager.isUpdateRequired(a, remoteRepository)); + assertThat(updateCheckManager.isUpdateRequired(a, remoteRepository)).isTrue(); file.getParentFile().mkdirs(); file.createNewFile(); updateCheckManager.touch(a, remoteRepository, null); - assertFalse(updateCheckManager.isUpdateRequired(a, remoteRepository)); + assertThat(updateCheckManager.isUpdateRequired(a, remoteRepository)).isFalse(); - assertNull( - updateCheckManager.readLastUpdated(touchFile, updateCheckManager.getRepositoryKey(remoteRepository))); + assertThat(updateCheckManager.readLastUpdated(touchFile, updateCheckManager.getRepositoryKey(remoteRepository))).isNull(); - assertFalse(updateCheckManager.getTouchfile(a).exists()); + assertThat(updateCheckManager.getTouchfile(a).exists()).isFalse(); } @Test - void testMissingPom() throws Exception { + void missingPom() throws Exception { ArtifactRepository remoteRepository = remoteRepository(); ArtifactRepository localRepository = localRepository(); @@ -155,19 +148,18 @@ void testMissingPom() throws Exception { File touchFile = updateCheckManager.getTouchfile(a); touchFile.delete(); - assertTrue(updateCheckManager.isUpdateRequired(a, remoteRepository)); + assertThat(updateCheckManager.isUpdateRequired(a, remoteRepository)).isTrue(); updateCheckManager.touch(a, remoteRepository, null); - assertFalse(updateCheckManager.isUpdateRequired(a, remoteRepository)); + assertThat(updateCheckManager.isUpdateRequired(a, remoteRepository)).isFalse(); - assertFalse(file.exists()); - assertNotNull( - updateCheckManager.readLastUpdated(touchFile, updateCheckManager.getRepositoryKey(remoteRepository))); + assertThat(file.exists()).isFalse(); + assertThat(updateCheckManager.readLastUpdated(touchFile, updateCheckManager.getRepositoryKey(remoteRepository))).isNotNull(); } @Test - void testMetadata() throws Exception { + void metadata() throws Exception { ArtifactRepository remoteRepository = remoteRepository(); ArtifactRepository localRepository = localRepository(); @@ -182,20 +174,20 @@ void testMetadata() throws Exception { File touchFile = updateCheckManager.getTouchfile(metadata, file); touchFile.delete(); - assertTrue(updateCheckManager.isUpdateRequired(metadata, remoteRepository, file)); + assertThat(updateCheckManager.isUpdateRequired(metadata, remoteRepository, file)).isTrue(); file.getParentFile().mkdirs(); file.createNewFile(); updateCheckManager.touch(metadata, remoteRepository, file); - assertFalse(updateCheckManager.isUpdateRequired(metadata, remoteRepository, file)); + assertThat(updateCheckManager.isUpdateRequired(metadata, remoteRepository, file)).isFalse(); - assertNotNull(updateCheckManager.readLastUpdated( - touchFile, updateCheckManager.getMetadataKey(remoteRepository, file))); + assertThat(updateCheckManager.readLastUpdated( + touchFile, updateCheckManager.getMetadataKey(remoteRepository, file))).isNotNull(); } @Test - void testMissingMetadata() throws Exception { + void missingMetadata() throws Exception { ArtifactRepository remoteRepository = remoteRepository(); ArtifactRepository localRepository = localRepository(); @@ -210,34 +202,30 @@ void testMissingMetadata() throws Exception { File touchFile = updateCheckManager.getTouchfile(metadata, file); touchFile.delete(); - assertTrue(updateCheckManager.isUpdateRequired(metadata, remoteRepository, file)); + assertThat(updateCheckManager.isUpdateRequired(metadata, remoteRepository, file)).isTrue(); updateCheckManager.touch(metadata, remoteRepository, file); - assertFalse(updateCheckManager.isUpdateRequired(metadata, remoteRepository, file)); + assertThat(updateCheckManager.isUpdateRequired(metadata, remoteRepository, file)).isFalse(); - assertNotNull(updateCheckManager.readLastUpdated( - touchFile, updateCheckManager.getMetadataKey(remoteRepository, file))); + assertThat(updateCheckManager.readLastUpdated( + touchFile, updateCheckManager.getMetadataKey(remoteRepository, file))).isNotNull(); } @Test - void testArtifactTouchFileName() throws Exception { + void artifactTouchFileName() throws Exception { ArtifactRepository localRepository = localRepository(); Artifact a = artifactFactory.createArtifactWithClassifier("groupId", "a", "0.0.1-SNAPSHOT", "jar", null); File file = new File(localRepository.getBasedir(), localRepository.pathOf(a)); a.setFile(file); - assertEquals( - "a-0.0.1-SNAPSHOT.jar.lastUpdated", - updateCheckManager.getTouchfile(a).getName()); + assertThat(updateCheckManager.getTouchfile(a).getName()).isEqualTo("a-0.0.1-SNAPSHOT.jar.lastUpdated"); a = artifactFactory.createArtifactWithClassifier("groupId", "a", "0.0.1-SNAPSHOT", "jar", "classifier"); file = new File(localRepository.getBasedir(), localRepository.pathOf(a)); a.setFile(file); - assertEquals( - "a-0.0.1-SNAPSHOT-classifier.jar.lastUpdated", - updateCheckManager.getTouchfile(a).getName()); + assertThat(updateCheckManager.getTouchfile(a).getName()).isEqualTo("a-0.0.1-SNAPSHOT-classifier.jar.lastUpdated"); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java index bc3d21540236..6bc623fa8e3b 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java @@ -48,13 +48,10 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.codehaus.plexus.testing.PlexusExtension.getTestFile; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; /** */ @@ -73,7 +70,7 @@ class DefaultWagonManagerTest { private ArtifactRepositoryFactory artifactRepositoryFactory; @Test - void testUnnecessaryRepositoryLookup() throws Exception { + void unnecessaryRepositoryLookup() throws Exception { Artifact artifact = createTestPomArtifact("target/test-data/get-missing-pom"); List repos = new ArrayList<>(); @@ -101,33 +98,33 @@ public void transferInitiated(TransferEvent transferEvent) { TransferListener listener = new TransferListener(); wagonManager.getArtifact(artifact, repos, listener, false); - assertEquals(1, listener.events.size()); + assertThat(listener.events.size()).isEqualTo(1); } @Test - void testGetMissingJar() throws TransferFailedException, UnsupportedProtocolException, IOException { + void getMissingJar() throws TransferFailedException, UnsupportedProtocolException, IOException { Artifact artifact = createTestArtifact("target/test-data/get-missing-jar", "jar"); ArtifactRepository repo = createStringRepo(); - assertThrows(ResourceDoesNotExistException.class, () -> wagonManager.getArtifact(artifact, repo, null, false)); + assertThatExceptionOfType(ResourceDoesNotExistException.class).isThrownBy(() -> wagonManager.getArtifact(artifact, repo, null, false)); - assertFalse(artifact.getFile().exists()); + assertThat(artifact.getFile().exists()).isFalse(); } @Test - void testGetMissingJarForced() throws TransferFailedException, UnsupportedProtocolException, IOException { + void getMissingJarForced() throws TransferFailedException, UnsupportedProtocolException, IOException { Artifact artifact = createTestArtifact("target/test-data/get-missing-jar", "jar"); ArtifactRepository repo = createStringRepo(); - assertThrows(ResourceDoesNotExistException.class, () -> wagonManager.getArtifact(artifact, repo, null, true)); + assertThatExceptionOfType(ResourceDoesNotExistException.class).isThrownBy(() -> wagonManager.getArtifact(artifact, repo, null, true)); - assertFalse(artifact.getFile().exists()); + assertThat(artifact.getFile().exists()).isFalse(); } @Test - void testGetRemoteJar() + void getRemoteJar() throws TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException, IOException { Artifact artifact = createTestArtifact("target/test-data/get-remote-jar", "jar"); @@ -139,8 +136,8 @@ void testGetRemoteJar() wagonManager.getArtifact(artifact, repo, null, false); - assertTrue(artifact.getFile().exists()); - assertEquals("expected", FileUtils.fileRead(artifact.getFile(), "UTF-8")); + assertThat(artifact.getFile().exists()).isTrue(); + assertThat(FileUtils.fileRead(artifact.getFile(), "UTF-8")).isEqualTo("expected"); } private Artifact createTestPomArtifact(String directory) throws IOException { @@ -150,7 +147,7 @@ private Artifact createTestPomArtifact(String directory) throws IOException { Artifact artifact = artifactFactory.createProjectArtifact("test", "test", "1.0"); artifact.setFile(new File(testData, "test-1.0.pom")); - assertFalse(artifact.getFile().exists()); + assertThat(artifact.getFile().exists()).isFalse(); return artifact; } @@ -167,7 +164,7 @@ private Artifact createTestArtifact(String directory, String version, String typ artifact.setFile(new File( testData, "test-" + version + "." + artifact.getArtifactHandler().getExtension())); - assertFalse(artifact.getFile().exists()); + assertThat(artifact.getFile().exists()).isFalse(); return artifact; } @@ -198,7 +195,7 @@ private ArtifactRepository getRepo(String id) { } @Test - void testDefaultWagonManager() throws Exception { + void defaultWagonManager() throws Exception { assertWagon("a"); assertWagon("b"); @@ -207,14 +204,14 @@ void testDefaultWagonManager() throws Exception { assertWagon("string"); - assertThrows(UnsupportedProtocolException.class, () -> assertWagon("d")); + assertThatExceptionOfType(UnsupportedProtocolException.class).isThrownBy(() -> assertWagon("d")); } /** * Check that transfer listeners are properly removed after getArtifact and putArtifact */ @Test - void testWagonTransferListenerRemovedAfterGetArtifactAndPutArtifact() throws Exception { + void wagonTransferListenerRemovedAfterGetArtifactAndPutArtifact() throws Exception { Artifact artifact = createTestArtifact("target/test-data/transfer-listener", "jar"); ArtifactRepository repo = createStringRepo(); StringWagon wagon = (StringWagon) wagonManager.getWagon("string"); @@ -222,25 +219,17 @@ void testWagonTransferListenerRemovedAfterGetArtifactAndPutArtifact() throws Exc wagon.addExpectedContent(repo.getLayout().pathOf(artifact) + ".md5", "cd26d9e10ce691cc69aa2b90dcebbdac"); /* getArtifact */ - assertFalse( - wagon.getTransferEventSupport().hasTransferListener(transferListener), - "Transfer listener is registered before test"); + assertThat(wagon.getTransferEventSupport().hasTransferListener(transferListener)).as("Transfer listener is registered before test").isFalse(); wagonManager.getArtifact(artifact, repo, transferListener, false); - assertFalse( - wagon.getTransferEventSupport().hasTransferListener(transferListener), - "Transfer listener still registered after getArtifact"); + assertThat(wagon.getTransferEventSupport().hasTransferListener(transferListener)).as("Transfer listener still registered after getArtifact").isFalse(); /* putArtifact */ File sampleFile = getTestFile("target/test-file"); FileUtils.fileWrite(sampleFile.getAbsolutePath(), "sample file"); - assertFalse( - wagon.getTransferEventSupport().hasTransferListener(transferListener), - "Transfer listener is registered before test"); + assertThat(wagon.getTransferEventSupport().hasTransferListener(transferListener)).as("Transfer listener is registered before test").isFalse(); wagonManager.putArtifact(sampleFile, artifact, repo, transferListener); - assertFalse( - wagon.getTransferEventSupport().hasTransferListener(transferListener), - "Transfer listener still registered after putArtifact"); + assertThat(wagon.getTransferEventSupport().hasTransferListener(transferListener)).as("Transfer listener still registered after putArtifact").isFalse(); } /** @@ -248,7 +237,7 @@ void testWagonTransferListenerRemovedAfterGetArtifactAndPutArtifact() throws Exc */ @Disabled @Test - void testChecksumVerification() throws Exception { + void checksumVerification() throws Exception { ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL); @@ -280,10 +269,7 @@ void testChecksumVerification() throws Exception { wagon.clearExpectedContent(); wagon.addExpectedContent("path", "expected-failure"); wagon.addExpectedContent("path.sha1", "b7bb97d7d0b9244398d9b47296907f73313663e6"); - assertThrows( - ChecksumFailedException.class, - () -> wagonManager.getArtifact(artifact, repo, null, false), - "Checksum verification did not fail"); + assertThatExceptionOfType(ChecksumFailedException.class).as("Checksum verification did not fail").isThrownBy(() -> wagonManager.getArtifact(artifact, repo, null, false)); wagon.clearExpectedContent(); wagon.addExpectedContent("path", "lower-case-checksum"); @@ -298,14 +284,11 @@ void testChecksumVerification() throws Exception { wagon.clearExpectedContent(); wagon.addExpectedContent("path", "expected-failure"); wagon.addExpectedContent("path.md5", "b7bb97d7d0b9244398d9b47296907f73313663e6"); - assertThrows( - ChecksumFailedException.class, - () -> wagonManager.getArtifact(artifact, repo, null, false), - "Checksum verification did not fail"); + assertThatExceptionOfType(ChecksumFailedException.class).as("Checksum verification did not fail").isThrownBy(() -> wagonManager.getArtifact(artifact, repo, null, false)); } @Test - void testPerLookupInstantiation() throws Exception { + void perLookupInstantiation() throws Exception { String protocol = "perlookup"; Wagon one = wagonManager.getWagon(protocol); @@ -317,7 +300,7 @@ void testPerLookupInstantiation() throws Exception { private void assertWagon(String protocol) throws Exception { Wagon wagon = wagonManager.getWagon(protocol); - assertNotNull(wagon, "Check wagon, protocol=" + protocol); + assertThat(wagon).as("Check wagon, protocol=" + protocol).isNotNull(); } private final class ArtifactRepositoryLayoutStub implements ArtifactRepositoryLayout { diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java index 82554ea83ac7..498ce2cef3f4 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java @@ -29,8 +29,7 @@ import org.codehaus.plexus.testing.PlexusTest; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@link LegacyRepositorySystem}. @@ -43,14 +42,14 @@ class LegacyRepositorySystemTest { private LegacyRepositorySystem repositorySystem; @Test - void testThatLocalRepositoryWithSpacesIsProperlyHandled() throws Exception { + void thatLocalRepositoryWithSpacesIsProperlyHandled() throws Exception { File basedir = new File("target/spacy path").getAbsoluteFile(); ArtifactRepository repo = repositorySystem.createLocalRepository(basedir); - assertEquals(basedir, new File(repo.getBasedir())); + assertThat(new File(repo.getBasedir())).isEqualTo(basedir); } @Test - void testAuthenticationHandling() { + void authenticationHandling() { Server server = new Server(); server.setId("repository"); server.setUsername("jason"); @@ -60,8 +59,8 @@ void testAuthenticationHandling() { repositorySystem.createArtifactRepository("repository", "http://foo", null, null, null); repositorySystem.injectAuthentication(Arrays.asList(repository), Arrays.asList(server)); Authentication authentication = repository.getAuthentication(); - assertNotNull(authentication); - assertEquals("jason", authentication.getUsername()); - assertEquals("abc123", authentication.getPassword()); + assertThat(authentication).isNotNull(); + assertThat(authentication.getUsername()).isEqualTo("jason"); + assertThat(authentication.getPassword()).isEqualTo("abc123"); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java index f3cf58135349..70f89fd97097 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java @@ -53,10 +53,8 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; /** * Test the default artifact collector. @@ -86,32 +84,26 @@ void setUp() throws Exception { @Test @Disabled("works, but we don't fail on cycles presently") - void testCircularDependencyNotIncludingCurrentProject() + void circularDependencyNotIncludingCurrentProject() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = a.addDependency("b", "1.0"); b.addDependency("a", "1.0"); - assertThrows( - CyclicDependencyException.class, - () -> collect(a), - "Should have failed on cyclic dependency not involving project"); + assertThatExceptionOfType(CyclicDependencyException.class).as("Should have failed on cyclic dependency not involving project").isThrownBy(() -> collect(a)); } @Test @Disabled("works, but we don't fail on cycles presently") - void testCircularDependencyIncludingCurrentProject() + void circularDependencyIncludingCurrentProject() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = a.addDependency("b", "1.0"); b.addDependency("project", "1.0"); - assertThrows( - CyclicDependencyException.class, - () -> collect(a), - "Should have failed on cyclic dependency not involving project"); + assertThatExceptionOfType(CyclicDependencyException.class).as("Should have failed on cyclic dependency not involving project").isThrownBy(() -> collect(a)); } @Test - void testResolveWithFilter() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void resolveWithFilter() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = a.addDependency("b", "1.0"); ArtifactSpec c = a.addDependency("c", "3.0"); @@ -120,18 +112,15 @@ void testResolveWithFilter() throws ArtifactResolutionException, InvalidVersionS ArtifactSpec d = b.addDependency("d", "4.0"); ArtifactResolutionResult res = collect(a); - assertEquals( - createSet(new Object[] {a.artifact, b.artifact, c.artifact, d.artifact}), - res.getArtifacts(), - "Check artifact list"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact, c.artifact, d.artifact})); ArtifactFilter filter = new ExclusionSetFilter(new String[] {"b"}); res = collect(a, filter); - assertEquals(createSet(new Object[] {a.artifact, c.artifact}), res.getArtifacts(), "Check artifact list"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, c.artifact})); } @Test - void testResolveCorrectDependenciesWhenDifferentDependenciesOnNearest() + void resolveCorrectDependenciesWhenDifferentDependenciesOnNearest() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = a.addDependency("b", "1.0"); @@ -143,16 +132,13 @@ void testResolveCorrectDependenciesWhenDifferentDependenciesOnNearest() ArtifactSpec f = c1.addDependency("f", "1.0"); ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, e.artifact})); - assertEquals( - createSet(new Object[] {a.artifact, b.artifact, e.artifact, c1.artifact, f.artifact}), - res.getArtifacts(), - "Check artifact list"); - assertEquals("1.0", getArtifact("c", res.getArtifacts()).getVersion(), "Check version"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact, e.artifact, c1.artifact, f.artifact})); + assertThat(getArtifact("c", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("1.0"); } @Test @Disabled - void testResolveCorrectDependenciesWhenDifferentDependenciesOnNewest() + void resolveCorrectDependenciesWhenDifferentDependenciesOnNewest() throws ArtifactResolutionException, InvalidVersionSpecificationException { // TODO use newest conflict resolver ArtifactSpec a = createArtifactSpec("a", "1.0"); @@ -165,16 +151,13 @@ void testResolveCorrectDependenciesWhenDifferentDependenciesOnNewest() c1.addDependency("f", "1.0"); ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, e.artifact})); - assertEquals( - createSet(new Object[] {a.artifact, b.artifact, e.artifact, c2.artifact, d.artifact}), - res.getArtifacts(), - "Check artifact list"); - assertEquals("2.0", getArtifact("c", res.getArtifacts()).getVersion(), "Check version"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact, e.artifact, c2.artifact, d.artifact})); + assertThat(getArtifact("c", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("2.0"); } @Test @Disabled - void testResolveCorrectDependenciesWhenDifferentDependenciesOnNewestVersionReplaced() + void resolveCorrectDependenciesWhenDifferentDependenciesOnNewestVersionReplaced() throws ArtifactResolutionException, InvalidVersionSpecificationException { // TODO use newest conflict resolver ArtifactSpec a = createArtifactSpec("a", "1.0"); @@ -189,13 +172,13 @@ void testResolveCorrectDependenciesWhenDifferentDependenciesOnNewestVersionRepla ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact})); Object[] artifacts = new Object[] {a.artifact, c.artifact, d1.artifact, b2.artifact, e.artifact, g.artifact}; - assertEquals(createSet(artifacts), res.getArtifacts(), "Check artifact list"); - assertEquals("1.0", getArtifact("d", res.getArtifacts()).getVersion(), "Check version"); - assertEquals("2.0", getArtifact("b", res.getArtifacts()).getVersion(), "Check version"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(artifacts)); + assertThat(getArtifact("d", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("1.0"); + assertThat(getArtifact("b", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("2.0"); } @Test - void testResolveNearestNewestIsNearest() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void resolveNearestNewestIsNearest() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = a.addDependency("b", "1.0"); ArtifactSpec c = a.addDependency("c", "3.0"); @@ -203,15 +186,12 @@ void testResolveNearestNewestIsNearest() throws ArtifactResolutionException, Inv b.addDependency("c", "2.0"); ArtifactResolutionResult res = collect(a); - assertEquals( - createSet(new Object[] {a.artifact, b.artifact, c.artifact}), - res.getArtifacts(), - "Check artifact list"); - assertEquals("3.0", getArtifact("c", res.getArtifacts()).getVersion(), "Check version"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact, c.artifact})); + assertThat(getArtifact("c", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("3.0"); } @Test - void testResolveNearestOldestIsNearest() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void resolveNearestOldestIsNearest() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = a.addDependency("b", "1.0"); ArtifactSpec c = a.addDependency("c", "2.0"); @@ -219,65 +199,60 @@ void testResolveNearestOldestIsNearest() throws ArtifactResolutionException, Inv b.addDependency("c", "3.0"); ArtifactResolutionResult res = collect(a); - assertEquals( - createSet(new Object[] {a.artifact, b.artifact, c.artifact}), - res.getArtifacts(), - "Check artifact list"); - assertEquals("2.0", getArtifact("c", res.getArtifacts()).getVersion(), "Check version"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact, c.artifact})); + assertThat(getArtifact("c", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("2.0"); } @Test - void testResolveLocalNewestIsLocal() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void resolveLocalNewestIsLocal() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); a.addDependency("b", "2.0"); ArtifactSpec b = createArtifactSpec("b", "3.0"); ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, b.artifact})); - assertEquals(createSet(new Object[] {a.artifact, b.artifact}), res.getArtifacts(), "Check artifact list"); - assertEquals("3.0", getArtifact("b", res.getArtifacts()).getVersion(), "Check version"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact})); + assertThat(getArtifact("b", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("3.0"); } @Test - void testResolveLocalOldestIsLocal() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void resolveLocalOldestIsLocal() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); a.addDependency("b", "3.0"); ArtifactSpec b = createArtifactSpec("b", "2.0"); ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, b.artifact})); - assertEquals(createSet(new Object[] {a.artifact, b.artifact}), res.getArtifacts(), "Check artifact list"); - assertEquals("2.0", getArtifact("b", res.getArtifacts()).getVersion(), "Check version"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact})); + assertThat(getArtifact("b", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("2.0"); } @Test - void testResolveLocalWithNewerVersionButLesserScope() + void resolveLocalWithNewerVersionButLesserScope() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("commons-logging", "1.0"); a.addDependency("junit", "3.7"); ArtifactSpec b = createArtifactSpec("junit", "3.8.1", Artifact.SCOPE_TEST); ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, b.artifact})); - assertEquals(createSet(new Object[] {a.artifact, b.artifact}), res.getArtifacts(), "Check artifact list"); - assertEquals("3.8.1", getArtifact("junit", res.getArtifacts()).getVersion(), "Check version"); - assertEquals( - Artifact.SCOPE_TEST, getArtifact("junit", res.getArtifacts()).getScope(), "Check artifactScope"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact})); + assertThat(getArtifact("junit", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("3.8.1"); + assertThat(getArtifact("junit", res.getArtifacts()).getScope()).as("Check artifactScope").isEqualTo(Artifact.SCOPE_TEST); } @Test - void testResolveLocalWithNewerVersionButLesserScopeResolvedFirst() + void resolveLocalWithNewerVersionButLesserScopeResolvedFirst() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec b = createArtifactSpec("junit", "3.8.1", Artifact.SCOPE_TEST); ArtifactSpec a = createArtifactSpec("commons-logging", "1.0"); a.addDependency("junit", "3.7"); ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, b.artifact})); - assertEquals(createSet(new Object[] {a.artifact, b.artifact}), res.getArtifacts(), "Check artifact list"); - assertEquals("3.8.1", getArtifact("junit", res.getArtifacts()).getVersion(), "Check version"); - assertEquals( - Artifact.SCOPE_TEST, getArtifact("junit", res.getArtifacts()).getScope(), "Check artifactScope"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact})); + assertThat(getArtifact("junit", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("3.8.1"); + assertThat(getArtifact("junit", res.getArtifacts()).getScope()).as("Check artifactScope").isEqualTo(Artifact.SCOPE_TEST); } @Test - void testResolveNearestWithRanges() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void resolveNearestWithRanges() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = a.addDependency("b", "1.0"); ArtifactSpec c = a.addDependency("c", "2.0"); @@ -285,29 +260,25 @@ void testResolveNearestWithRanges() throws ArtifactResolutionException, InvalidV b.addDependency("c", "[1.0,3.0]"); ArtifactResolutionResult res = collect(a); - assertEquals( - createSet(new Object[] {a.artifact, b.artifact, c.artifact}), - res.getArtifacts(), - "Check artifact list"); - assertEquals("2.0", getArtifact("c", res.getArtifacts()).getVersion(), "Check version"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact, c.artifact})); + assertThat(getArtifact("c", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("2.0"); } @Test @SuppressWarnings("checkstyle:UnusedLocalVariable") - void testResolveRangeWithManagedVersion() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void resolveRangeWithManagedVersion() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = a.addDependency("b", "[1.0,3.0]"); ArtifactSpec managedB = createArtifactSpec("b", "5.0"); ArtifactResolutionResult res = collect(a, managedB.artifact); - assertEquals( - createSet(new Object[] {a.artifact, managedB.artifact}), res.getArtifacts(), "Check artifact list"); - assertEquals("5.0", getArtifact("b", res.getArtifacts()).getVersion(), "Check version"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, managedB.artifact})); + assertThat(getArtifact("b", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("5.0"); } @Test - void testCompatibleRanges() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void compatibleRanges() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = a.addDependency("b", "1.0"); a.addDependency("c", "[2.0,2.5]"); @@ -316,15 +287,12 @@ void testCompatibleRanges() throws ArtifactResolutionException, InvalidVersionSp ArtifactResolutionResult res = collect(a); - assertEquals( - createSet(new Object[] {a.artifact, b.artifact, c.artifact}), - res.getArtifacts(), - "Check artifact list"); - assertEquals("2.5", getArtifact("c", res.getArtifacts()).getVersion(), "Check version"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact, c.artifact})); + assertThat(getArtifact("c", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("2.5"); } @Test - void testIncompatibleRanges() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void incompatibleRanges() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = a.addDependency("b", "1.0"); a.addDependency("c", "[2.4,3.0]"); @@ -333,11 +301,11 @@ void testIncompatibleRanges() throws ArtifactResolutionException, InvalidVersion ArtifactResolutionResult res = collect(a); - assertTrue(res.hasVersionRangeViolations()); + assertThat(res.hasVersionRangeViolations()).isTrue(); } @Test - void testUnboundedRangeWhenVersionUnavailable() + void unboundedRangeWhenVersionUnavailable() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = a.addDependency("b", "1.0"); @@ -346,11 +314,11 @@ void testUnboundedRangeWhenVersionUnavailable() ArtifactResolutionResult res = collect(a); - assertTrue(res.hasVersionRangeViolations()); + assertThat(res.hasVersionRangeViolations()).isTrue(); } @Test - void testUnboundedRangeBelowLastRelease() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void unboundedRangeBelowLastRelease() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); createArtifactSpec("c", "1.5"); ArtifactSpec c = createArtifactSpec("c", "2.0"); @@ -359,23 +327,23 @@ void testUnboundedRangeBelowLastRelease() throws ArtifactResolutionException, In ArtifactResolutionResult res = collect(a); - assertEquals(createSet(new Object[] {a.artifact, c.artifact}), res.getArtifacts(), "Check artifact list"); - assertEquals("2.0", getArtifact("c", res.getArtifacts()).getVersion(), "Check version"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, c.artifact})); + assertThat(getArtifact("c", res.getArtifacts()).getVersion()).as("Check version").isEqualTo("2.0"); } @Test - void testUnboundedRangeAboveLastRelease() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void unboundedRangeAboveLastRelease() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); createArtifactSpec("c", "2.0"); a.addDependency("c", "[10.0,)"); ArtifactResolutionResult res = collect(a); - assertTrue(res.hasVersionRangeViolations()); + assertThat(res.hasVersionRangeViolations()).isTrue(); } @Test - void testResolveManagedVersion() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void resolveManagedVersion() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); a.addDependency("b", "3.0", Artifact.SCOPE_RUNTIME); @@ -383,11 +351,11 @@ void testResolveManagedVersion() throws ArtifactResolutionException, InvalidVers Artifact modifiedB = createArtifactSpec("b", "5.0", Artifact.SCOPE_RUNTIME).artifact; ArtifactResolutionResult res = collect(a, managedVersion); - assertEquals(createSet(new Object[] {a.artifact, modifiedB}), res.getArtifacts(), "Check artifact list"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, modifiedB})); } @Test - void testCollectChangesVersionOfOriginatingArtifactIfInDependencyManagementHasDifferentVersion() + void collectChangesVersionOfOriginatingArtifactIfInDependencyManagementHasDifferentVersion() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); @@ -396,15 +364,15 @@ void testCollectChangesVersionOfOriginatingArtifactIfInDependencyManagementHasDi ArtifactResolutionResult result = collect(a, managedVersion); - assertEquals("1.0", artifact.getVersion(), "collect has modified version in originating artifact"); + assertThat(artifact.getVersion()).as("collect has modified version in originating artifact").isEqualTo("1.0"); Artifact resolvedArtifact = result.getArtifacts().iterator().next(); - assertEquals("1.0", resolvedArtifact.getVersion(), "Resolved version don't match original artifact version"); + assertThat(resolvedArtifact.getVersion()).as("Resolved version don't match original artifact version").isEqualTo("1.0"); } @Test - void testResolveCompileScopeOverTestScope() + void resolveCompileScopeOverTestScope() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec c = createArtifactSpec("c", "3.0", Artifact.SCOPE_TEST); @@ -414,15 +382,15 @@ void testResolveCompileScopeOverTestScope() Artifact modifiedC = createArtifactSpec("c", "3.0", Artifact.SCOPE_COMPILE).artifact; ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, c.artifact})); - assertEquals(createSet(new Object[] {a.artifact, modifiedC}), res.getArtifacts(), "Check artifact list"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, modifiedC})); Artifact artifact = getArtifact("c", res.getArtifacts()); // local wins now, and irrelevant if not local as test/provided aren't transitive // assertEquals( Artifact.SCOPE_COMPILE, artifact.getArtifactScope(), "Check artifactScope" ); - assertEquals(Artifact.SCOPE_TEST, artifact.getScope(), "Check artifactScope"); + assertThat(artifact.getScope()).as("Check artifactScope").isEqualTo(Artifact.SCOPE_TEST); } @Test - void testResolveRuntimeScopeOverTestScope() + void resolveRuntimeScopeOverTestScope() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec c = createArtifactSpec("c", "3.0", Artifact.SCOPE_TEST); @@ -432,15 +400,15 @@ void testResolveRuntimeScopeOverTestScope() Artifact modifiedC = createArtifactSpec("c", "3.0", Artifact.SCOPE_RUNTIME).artifact; ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, c.artifact})); - assertEquals(createSet(new Object[] {a.artifact, modifiedC}), res.getArtifacts(), "Check artifact list"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, modifiedC})); Artifact artifact = getArtifact("c", res.getArtifacts()); // local wins now, and irrelevant if not local as test/provided aren't transitive // assertEquals( Artifact.SCOPE_RUNTIME, artifact.getArtifactScope(), "Check artifactScope" ); - assertEquals(Artifact.SCOPE_TEST, artifact.getScope(), "Check artifactScope"); + assertThat(artifact.getScope()).as("Check artifactScope").isEqualTo(Artifact.SCOPE_TEST); } @Test - void testResolveCompileScopeOverRuntimeScope() + void resolveCompileScopeOverRuntimeScope() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec root = createArtifactSpec("root", "1.0"); ArtifactSpec a = root.addDependency("a", "1.0"); @@ -451,16 +419,13 @@ void testResolveCompileScopeOverRuntimeScope() Artifact modifiedC = createArtifactSpec("c", "3.0", Artifact.SCOPE_COMPILE).artifact; ArtifactResolutionResult res = collect(createSet(new Object[] {root.artifact})); - assertEquals( - createSet(new Object[] {a.artifact, root.artifact, modifiedC}), - res.getArtifacts(), - "Check artifact list"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, root.artifact, modifiedC})); Artifact artifact = getArtifact("c", res.getArtifacts()); - assertEquals(Artifact.SCOPE_COMPILE, artifact.getScope(), "Check artifactScope"); + assertThat(artifact.getScope()).as("Check artifactScope").isEqualTo(Artifact.SCOPE_COMPILE); } @Test - void testResolveCompileScopeOverProvidedScope() + void resolveCompileScopeOverProvidedScope() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec c = createArtifactSpec("c", "3.0", Artifact.SCOPE_PROVIDED); @@ -470,15 +435,15 @@ void testResolveCompileScopeOverProvidedScope() Artifact modifiedC = createArtifactSpec("c", "3.0", Artifact.SCOPE_COMPILE).artifact; ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, c.artifact})); - assertEquals(createSet(new Object[] {a.artifact, modifiedC}), res.getArtifacts(), "Check artifact list"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, modifiedC})); Artifact artifact = getArtifact("c", res.getArtifacts()); // local wins now, and irrelevant if not local as test/provided aren't transitive // assertEquals( Artifact.SCOPE_COMPILE, artifact.getArtifactScope(), "Check artifactScope" ); - assertEquals(Artifact.SCOPE_PROVIDED, artifact.getScope(), "Check artifactScope"); + assertThat(artifact.getScope()).as("Check artifactScope").isEqualTo(Artifact.SCOPE_PROVIDED); } @Test - void testResolveRuntimeScopeOverProvidedScope() + void resolveRuntimeScopeOverProvidedScope() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec c = createArtifactSpec("c", "3.0", Artifact.SCOPE_PROVIDED); @@ -488,45 +453,45 @@ void testResolveRuntimeScopeOverProvidedScope() Artifact modifiedC = createArtifactSpec("c", "3.0", Artifact.SCOPE_RUNTIME).artifact; ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, c.artifact})); - assertEquals(createSet(new Object[] {a.artifact, modifiedC}), res.getArtifacts(), "Check artifact list"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, modifiedC})); Artifact artifact = getArtifact("c", res.getArtifacts()); // local wins now, and irrelevant if not local as test/provided aren't transitive // assertEquals( Artifact.SCOPE_RUNTIME, artifact.getArtifactScope(), "Check artifactScope" ); - assertEquals(Artifact.SCOPE_PROVIDED, artifact.getScope(), "Check artifactScope"); + assertThat(artifact.getScope()).as("Check artifactScope").isEqualTo(Artifact.SCOPE_PROVIDED); } @Test - void testProvidedScopeNotTransitive() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void providedScopeNotTransitive() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0", Artifact.SCOPE_PROVIDED); ArtifactSpec b = createArtifactSpec("b", "1.0"); b.addDependency("c", "3.0", Artifact.SCOPE_PROVIDED); ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, b.artifact})); - assertEquals(createSet(new Object[] {a.artifact, b.artifact}), res.getArtifacts(), "Check artifact list"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact})); } @Test - void testOptionalNotTransitive() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void optionalNotTransitive() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = createArtifactSpec("b", "1.0"); b.addDependency("c", "3.0", true); ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, b.artifact})); - assertEquals(createSet(new Object[] {a.artifact, b.artifact}), res.getArtifacts(), "Check artifact list"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact})); } @Test - void testOptionalIncludedAtRoot() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void optionalIncludedAtRoot() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = createArtifactSpec("b", "1.0", true); ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, b.artifact})); - assertEquals(createSet(new Object[] {a.artifact, b.artifact}), res.getArtifacts(), "Check artifact list"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact})); } @Test - void testScopeUpdate() throws InvalidVersionSpecificationException, ArtifactResolutionException { + void scopeUpdate() throws InvalidVersionSpecificationException, ArtifactResolutionException { /* farthest = compile */ checkScopeUpdate(Artifact.SCOPE_COMPILE, Artifact.SCOPE_COMPILE, Artifact.SCOPE_COMPILE); checkScopeUpdate(Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_COMPILE); @@ -613,21 +578,21 @@ private void checkScopeUpdate(ArtifactSpec a, ArtifactSpec b, String expectedSco ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, b.artifact}), filter); Artifact artifact = getArtifact("d", res.getArtifacts()); - assertNotNull(artifact, "MNG-1895 Dependency was not added to resolution"); - assertEquals(expectedScope, artifact.getScope(), "Check artifactScope"); - assertEquals(expectedVersion, artifact.getVersion(), "Check version"); + assertThat(artifact).as("MNG-1895 Dependency was not added to resolution").isNotNull(); + assertThat(artifact.getScope()).as("Check artifactScope").isEqualTo(expectedScope); + assertThat(artifact.getVersion()).as("Check version").isEqualTo(expectedVersion); ArtifactSpec d = createArtifactSpec("d", "1.0"); res = collect(createSet(new Object[] {a.artifact, b.artifact, d.artifact}), filter); artifact = getArtifact("d", res.getArtifacts()); - assertNotNull(artifact, "MNG-1895 Dependency was not added to resolution"); - assertEquals(d.artifact.getScope(), artifact.getScope(), "Check artifactScope"); - assertEquals("1.0", artifact.getVersion(), "Check version"); + assertThat(artifact).as("MNG-1895 Dependency was not added to resolution").isNotNull(); + assertThat(artifact.getScope()).as("Check artifactScope").isEqualTo(d.artifact.getScope()); + assertThat(artifact.getVersion()).as("Check version").isEqualTo("1.0"); } @Test @Disabled - void testOptionalNotTransitiveButVersionIsInfluential() + void optionalNotTransitiveButVersionIsInfluential() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); ArtifactSpec b = createArtifactSpec("b", "1.0"); @@ -639,33 +604,30 @@ void testOptionalNotTransitiveButVersionIsInfluential() ArtifactSpec c = createArtifactSpec("c", "3.0"); ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, b.artifact})); - assertEquals( - createSet(new Object[] {a.artifact, b.artifact, c.artifact, d.artifact, e.artifact}), - res.getArtifacts(), - "Check artifact list"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact, c.artifact, d.artifact, e.artifact})); Artifact artifact = getArtifact("c", res.getArtifacts()); - assertEquals("3.0", artifact.getVersion(), "Check version"); + assertThat(artifact.getVersion()).as("Check version").isEqualTo("3.0"); } @Test - void testTestScopeNotTransitive() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void testScopeNotTransitive() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0", Artifact.SCOPE_TEST); ArtifactSpec b = createArtifactSpec("b", "1.0"); b.addDependency("c", "3.0", Artifact.SCOPE_TEST); ArtifactResolutionResult res = collect(createSet(new Object[] {a.artifact, b.artifact})); - assertEquals(createSet(new Object[] {a.artifact, b.artifact}), res.getArtifacts(), "Check artifact list"); + assertThat(res.getArtifacts()).as("Check artifact list").isEqualTo(createSet(new Object[]{a.artifact, b.artifact})); } @Test - void testSnapshotNotIncluded() throws ArtifactResolutionException, InvalidVersionSpecificationException { + void snapshotNotIncluded() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); a.addDependency("b", "[1.0,)"); createArtifactSpec("b", "1.0-SNAPSHOT"); ArtifactResolutionResult res = collect(a); - assertTrue(res.hasVersionRangeViolations()); + assertThat(res.hasVersionRangeViolations()).isTrue(); /* * try { ArtifactResolutionResult res = collect( a ); fail( "Expected b not to resolve: " + res ); } catch ( @@ -677,7 +639,7 @@ void testSnapshotNotIncluded() throws ArtifactResolutionException, InvalidVersio @Test @Disabled("that one does not work") @SuppressWarnings("checkstyle:UnusedLocalVariable") - void testOverConstrainedVersionException() + void overConstrainedVersionException() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec("a", "1.0"); a.addDependency("b", "[1.0, 2.0)"); @@ -688,10 +650,9 @@ void testOverConstrainedVersionException() ArtifactSpec c = createArtifactSpec("c", "3.2.1-v3235e"); - OverConstrainedVersionException e = assertThrows( - OverConstrainedVersionException.class, () -> collect(createSet(new Object[] {a.artifact}))); - assertTrue(e.getMessage().contains("[3.2.1-v3235e, 3.3.0-v3346]"), "Versions unordered"); - assertTrue(e.getMessage().contains("Path to dependency:"), "DependencyTrail unresolved"); + OverConstrainedVersionException e = assertThatExceptionOfType(OverConstrainedVersionException.class).isThrownBy(() -> collect(createSet(new Object[]{a.artifact}))).actual(); + assertThat(e.getMessage().contains("[3.2.1-v3235e, 3.3.0-v3346]")).as("Versions unordered").isTrue(); + assertThat(e.getMessage().contains("Path to dependency:")).as("DependencyTrail unresolved").isTrue(); } private Artifact getArtifact(String id, Set artifacts) { diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java index 2bbfc00915fd..55a83ce28c86 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java @@ -31,8 +31,7 @@ import org.codehaus.plexus.testing.PlexusTest; import org.junit.jupiter.api.BeforeEach; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Provides a basis for testing conflict resolvers. @@ -93,8 +92,8 @@ protected void assertResolveConflict( ResolutionNode expectedNode, ResolutionNode actualNode1, ResolutionNode actualNode2) { ResolutionNode resolvedNode = getConflictResolver().resolveConflict(actualNode1, actualNode2); - assertNotNull(resolvedNode, "Expected resolvable"); - assertEquals(expectedNode, resolvedNode, "Resolution node"); + assertThat(resolvedNode).as("Expected resolvable").isNotNull(); + assertThat(resolvedNode).as("Resolution node").isEqualTo(expectedNode); } protected Artifact createArtifact(String id, String version) throws InvalidVersionSpecificationException { diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/FarthestConflictResolverTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/FarthestConflictResolverTest.java index 25aa5124f9da..ff8c62f0921a 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/FarthestConflictResolverTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/FarthestConflictResolverTest.java @@ -44,7 +44,7 @@ class FarthestConflictResolverTest extends AbstractConflictResolverTest { * */ @Test - void testDepth() { + void depth() { ResolutionNode a1n = createResolutionNode(a1); ResolutionNode b1n = createResolutionNode(b1); ResolutionNode a2n = createResolutionNode(a2, b1n); @@ -60,7 +60,7 @@ void testDepth() { * */ @Test - void testDepthReversed() { + void depthReversed() { ResolutionNode b1n = createResolutionNode(b1); ResolutionNode a2n = createResolutionNode(a2, b1n); ResolutionNode a1n = createResolutionNode(a1); @@ -76,7 +76,7 @@ void testDepthReversed() { * */ @Test - void testEqual() { + void equal() { ResolutionNode a1n = createResolutionNode(a1); ResolutionNode a2n = createResolutionNode(a2); @@ -91,7 +91,7 @@ void testEqual() { * */ @Test - void testEqualReversed() { + void equalReversed() { ResolutionNode a2n = createResolutionNode(a2); ResolutionNode a1n = createResolutionNode(a1); diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NearestConflictResolverTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NearestConflictResolverTest.java index 605d2aca0858..a25f51b7838b 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NearestConflictResolverTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NearestConflictResolverTest.java @@ -44,7 +44,7 @@ class NearestConflictResolverTest extends AbstractConflictResolverTest { * */ @Test - void testDepth() { + void depth() { ResolutionNode a1n = createResolutionNode(a1); ResolutionNode b1n = createResolutionNode(b1); ResolutionNode a2n = createResolutionNode(a2, b1n); @@ -60,7 +60,7 @@ void testDepth() { * */ @Test - void testDepthReversed() { + void depthReversed() { ResolutionNode b1n = createResolutionNode(b1); ResolutionNode a2n = createResolutionNode(a2, b1n); ResolutionNode a1n = createResolutionNode(a1); @@ -76,7 +76,7 @@ void testDepthReversed() { * */ @Test - void testEqual() { + void equal() { ResolutionNode a1n = createResolutionNode(a1); ResolutionNode a2n = createResolutionNode(a2); @@ -91,7 +91,7 @@ void testEqual() { * */ @Test - void testEqualReversed() { + void equalReversed() { ResolutionNode a2n = createResolutionNode(a2); ResolutionNode a1n = createResolutionNode(a1); diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NewestConflictResolverTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NewestConflictResolverTest.java index c8b46637f7ac..10dcf530bbe0 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NewestConflictResolverTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NewestConflictResolverTest.java @@ -44,7 +44,7 @@ class NewestConflictResolverTest extends AbstractConflictResolverTest { * */ @Test - void testDepth() { + void depth() { ResolutionNode a1n = createResolutionNode(a1); ResolutionNode b1n = createResolutionNode(b1); ResolutionNode a2n = createResolutionNode(a2, b1n); @@ -60,7 +60,7 @@ void testDepth() { * */ @Test - void testDepthReversed() { + void depthReversed() { ResolutionNode b1n = createResolutionNode(b1); ResolutionNode a2n = createResolutionNode(a2, b1n); ResolutionNode a1n = createResolutionNode(a1); @@ -76,7 +76,7 @@ void testDepthReversed() { * */ @Test - void testEqual() { + void equal() { ResolutionNode a1n = createResolutionNode(a1); ResolutionNode a2n = createResolutionNode(a2); @@ -91,7 +91,7 @@ void testEqual() { * */ @Test - void testEqualReversed() { + void equalReversed() { ResolutionNode a2n = createResolutionNode(a2); ResolutionNode a1n = createResolutionNode(a1); diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/OldestConflictResolverTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/OldestConflictResolverTest.java index 153f00c8ceed..a6b47e738d81 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/OldestConflictResolverTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/OldestConflictResolverTest.java @@ -44,7 +44,7 @@ class OldestConflictResolverTest extends AbstractConflictResolverTest { * */ @Test - void testDepth() { + void depth() { ResolutionNode a1n = createResolutionNode(a1); ResolutionNode b1n = createResolutionNode(b1); ResolutionNode a2n = createResolutionNode(a2, b1n); @@ -60,7 +60,7 @@ void testDepth() { * */ @Test - void testDepthReversed() { + void depthReversed() { ResolutionNode b1n = createResolutionNode(b1); ResolutionNode a2n = createResolutionNode(a2, b1n); ResolutionNode a1n = createResolutionNode(a1); @@ -76,7 +76,7 @@ void testDepthReversed() { * */ @Test - void testEqual() { + void equal() { ResolutionNode a1n = createResolutionNode(a1); ResolutionNode a2n = createResolutionNode(a2); @@ -91,7 +91,7 @@ void testEqual() { * */ @Test - void testEqualReversed() { + void equalReversed() { ResolutionNode a2n = createResolutionNode(a2); ResolutionNode a1n = createResolutionNode(a1); diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTestType.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTestType.java index 495db2d21528..b2aa870b22a5 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTestType.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTestType.java @@ -25,8 +25,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -76,44 +75,44 @@ void setUp() throws Exception { // ------------------------------------------------------------------------------------------ @Test - void testCompileClasspathTransform() throws Exception { + void compileClasspathTransform() throws Exception { ClasspathContainer res; res = transform.transform(graph, ArtifactScopeEnum.compile, false); - assertNotNull(res, "null classpath container after compile transform"); - assertNotNull(res.getClasspath(), "null classpath after compile transform"); - assertEquals(3, res.getClasspath().size(), "compile classpath should have 3 entries"); + assertThat(res).as("null classpath container after compile transform").isNotNull(); + assertThat(res.getClasspath()).as("null classpath after compile transform").isNotNull(); + assertThat(res.getClasspath().size()).as("compile classpath should have 3 entries").isEqualTo(3); } // ------------------------------------------------------------------------------------------ @Test - void testRuntimeClasspathTransform() throws Exception { + void runtimeClasspathTransform() throws Exception { ClasspathContainer res; res = transform.transform(graph, ArtifactScopeEnum.runtime, false); - assertNotNull(res, "null classpath container after runtime transform"); - assertNotNull(res.getClasspath(), "null classpath after runtime transform"); - assertEquals(4, res.getClasspath().size(), "runtime classpath should have 4 entries"); + assertThat(res).as("null classpath container after runtime transform").isNotNull(); + assertThat(res.getClasspath()).as("null classpath after runtime transform").isNotNull(); + assertThat(res.getClasspath().size()).as("runtime classpath should have 4 entries").isEqualTo(4); ArtifactMetadata md = res.getClasspath().get(3); - assertEquals("1.1", md.getVersion(), "runtime artifact version should be 1.1"); + assertThat(md.getVersion()).as("runtime artifact version should be 1.1").isEqualTo("1.1"); } // ------------------------------------------------------------------------------------------ @Test - void testTestClasspathTransform() throws Exception { + void testClasspathTransform() throws Exception { ClasspathContainer res; res = transform.transform(graph, ArtifactScopeEnum.test, false); - assertNotNull(res, "null classpath container after test transform"); - assertNotNull(res.getClasspath(), "null classpath after test transform"); - assertEquals(4, res.getClasspath().size(), "test classpath should have 4 entries"); + assertThat(res).as("null classpath container after test transform").isNotNull(); + assertThat(res.getClasspath()).as("null classpath after test transform").isNotNull(); + assertThat(res.getClasspath().size()).as("test classpath should have 4 entries").isEqualTo(4); ArtifactMetadata md = res.getClasspath().get(3); - assertEquals("1.2", md.getVersion(), "test artifact version should be 1.2"); + assertThat(md.getVersion()).as("test artifact version should be 1.2").isEqualTo("1.2"); } // ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------ diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicyTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicyTest.java index 15da1b3315ab..5de728f6c09d 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicyTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicyTest.java @@ -21,7 +21,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -45,14 +45,14 @@ void setUp() throws Exception { // ------------------------------------------------------------------------------------------ @Test - void testDefaultPolicy() throws Exception { + void defaultPolicy() throws Exception { MetadataGraphEdge res; res = policy.apply(e1, e2); - assertEquals("1.1", res.getVersion(), "Wrong depth edge selected"); + assertThat(res.getVersion()).as("Wrong depth edge selected").isEqualTo("1.1"); res = policy.apply(e1, e3); - assertEquals("1.2", res.getVersion(), "Wrong version edge selected"); + assertThat(res.getVersion()).as("Wrong version edge selected").isEqualTo("1.2"); } // ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------ diff --git a/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java b/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java index 94625d1fc0e9..9d27fb096989 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java @@ -25,8 +25,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -76,126 +75,75 @@ void setUp() throws Exception { // ------------------------------------------------------------------------------------------ @Test - void testCompileResolution() throws Exception { + void compileResolution() throws Exception { MetadataGraph res; res = resolver.resolveConflicts(graph, ArtifactScopeEnum.compile); - assertNotNull(res, "null graph after resolver"); - assertNotNull(res.getVertices(), "no vertices in the resulting graph after resolver"); - - assertNotNull(res.getExcidentEdges(v1), "no edges in the resulting graph after resolver"); - - assertEquals(4, res.getVertices().size(), "wrong # of vertices in the resulting graph after resolver"); - assertEquals( - 2, - res.getExcidentEdges(v1).size(), - "wrong # of excident edges in the resulting graph entry after resolver"); - - assertEquals( - 1, - res.getIncidentEdges(v2).size(), - "wrong # of v2 incident edges in the resulting graph after resolver"); - assertEquals( - "1.2", - res.getIncidentEdges(v2).get(0).getVersion(), - "wrong edge v1-v2 in the resulting graph after resolver"); - - assertEquals( - 1, res.getIncidentEdges(v3).size(), "wrong # of edges v1-v3 in the resulting graph after resolver"); - assertEquals( - "1.1", - res.getIncidentEdges(v3).get(0).getVersion(), - "wrong edge v1-v3 in the resulting graph after resolver"); - - assertEquals( - 1, res.getIncidentEdges(v4).size(), "wrong # of edges v3-v4 in the resulting graph after resolver"); - assertEquals( - "1.2", - res.getIncidentEdges(v4).get(0).getVersion(), - "wrong edge v3-v4 in the resulting graph after resolver"); + assertThat(res).as("null graph after resolver").isNotNull(); + assertThat(res.getVertices()).as("no vertices in the resulting graph after resolver").isNotNull(); + + assertThat(res.getExcidentEdges(v1)).as("no edges in the resulting graph after resolver").isNotNull(); + + assertThat(res.getVertices().size()).as("wrong # of vertices in the resulting graph after resolver").isEqualTo(4); + assertThat(res.getExcidentEdges(v1).size()).as("wrong # of excident edges in the resulting graph entry after resolver").isEqualTo(2); + + assertThat(res.getIncidentEdges(v2).size()).as("wrong # of v2 incident edges in the resulting graph after resolver").isEqualTo(1); + assertThat(res.getIncidentEdges(v2).get(0).getVersion()).as("wrong edge v1-v2 in the resulting graph after resolver").isEqualTo("1.2"); + + assertThat(res.getIncidentEdges(v3).size()).as("wrong # of edges v1-v3 in the resulting graph after resolver").isEqualTo(1); + assertThat(res.getIncidentEdges(v3).get(0).getVersion()).as("wrong edge v1-v3 in the resulting graph after resolver").isEqualTo("1.1"); + + assertThat(res.getIncidentEdges(v4).size()).as("wrong # of edges v3-v4 in the resulting graph after resolver").isEqualTo(1); + assertThat(res.getIncidentEdges(v4).get(0).getVersion()).as("wrong edge v3-v4 in the resulting graph after resolver").isEqualTo("1.2"); } // ------------------------------------------------------------------------------------------ @Test - void testRuntimeResolution() throws Exception { + void runtimeResolution() throws Exception { MetadataGraph res; res = resolver.resolveConflicts(graph, ArtifactScopeEnum.runtime); - assertNotNull(res, "null graph after resolver"); - assertNotNull(res.getVertices(), "no vertices in the resulting graph after resolver"); - assertNotNull(res.getExcidentEdges(v1), "no edges in the resulting graph after resolver"); - - assertEquals(4, res.getVertices().size(), "wrong # of vertices in the resulting graph after resolver"); - assertEquals( - 2, - res.getExcidentEdges(v1).size(), - "wrong # of excident edges in the resulting graph entry after resolver"); - - assertEquals( - 1, - res.getIncidentEdges(v2).size(), - "wrong # of v2 incident edges in the resulting graph after resolver"); - assertEquals( - "1.2", - res.getIncidentEdges(v2).get(0).getVersion(), - "wrong edge v1-v2 in the resulting graph after resolver"); - - assertEquals( - 1, res.getIncidentEdges(v3).size(), "wrong # of edges v1-v3 in the resulting graph after resolver"); - assertEquals( - "1.1", - res.getIncidentEdges(v3).get(0).getVersion(), - "wrong edge v1-v3 in the resulting graph after resolver"); - - assertEquals( - 1, res.getIncidentEdges(v4).size(), "wrong # of edges v3-v4 in the resulting graph after resolver"); - assertEquals( - "1.1", - res.getIncidentEdges(v4).get(0).getVersion(), - "wrong edge v3-v4 in the resulting graph after resolver"); + assertThat(res).as("null graph after resolver").isNotNull(); + assertThat(res.getVertices()).as("no vertices in the resulting graph after resolver").isNotNull(); + assertThat(res.getExcidentEdges(v1)).as("no edges in the resulting graph after resolver").isNotNull(); + + assertThat(res.getVertices().size()).as("wrong # of vertices in the resulting graph after resolver").isEqualTo(4); + assertThat(res.getExcidentEdges(v1).size()).as("wrong # of excident edges in the resulting graph entry after resolver").isEqualTo(2); + + assertThat(res.getIncidentEdges(v2).size()).as("wrong # of v2 incident edges in the resulting graph after resolver").isEqualTo(1); + assertThat(res.getIncidentEdges(v2).get(0).getVersion()).as("wrong edge v1-v2 in the resulting graph after resolver").isEqualTo("1.2"); + + assertThat(res.getIncidentEdges(v3).size()).as("wrong # of edges v1-v3 in the resulting graph after resolver").isEqualTo(1); + assertThat(res.getIncidentEdges(v3).get(0).getVersion()).as("wrong edge v1-v3 in the resulting graph after resolver").isEqualTo("1.1"); + + assertThat(res.getIncidentEdges(v4).size()).as("wrong # of edges v3-v4 in the resulting graph after resolver").isEqualTo(1); + assertThat(res.getIncidentEdges(v4).get(0).getVersion()).as("wrong edge v3-v4 in the resulting graph after resolver").isEqualTo("1.1"); } // ------------------------------------------------------------------------------------------ @Test - void testTestResolution() throws Exception { + void testResolution() throws Exception { MetadataGraph res; res = resolver.resolveConflicts(graph, ArtifactScopeEnum.test); - assertNotNull(res, "null graph after resolver"); - assertNotNull(res.getVertices(), "no vertices in the resulting graph after resolver"); - assertNotNull(res.getExcidentEdges(v1), "no edges in the resulting graph after resolver"); - - assertEquals(4, res.getVertices().size(), "wrong # of vertices in the resulting graph after resolver"); - assertEquals( - 2, - res.getExcidentEdges(v1).size(), - "wrong # of excident edges in the resulting graph entry after resolver"); - - assertEquals( - 1, - res.getIncidentEdges(v2).size(), - "wrong # of v2 incident edges in the resulting graph after resolver"); - assertEquals( - "1.2", - res.getIncidentEdges(v2).get(0).getVersion(), - "wrong edge v1-v2 in the resulting graph after resolver"); - - assertEquals( - 1, res.getIncidentEdges(v3).size(), "wrong # of edges v1-v3 in the resulting graph after resolver"); - assertEquals( - "1.1", - res.getIncidentEdges(v3).get(0).getVersion(), - "wrong edge v1-v3 in the resulting graph after resolver"); - - assertEquals( - 1, res.getIncidentEdges(v4).size(), "wrong # of edges v3-v4 in the resulting graph after resolver"); - assertEquals( - "1.2", - res.getIncidentEdges(v4).get(0).getVersion(), - "wrong edge v3-v4 in the resulting graph after resolver"); + assertThat(res).as("null graph after resolver").isNotNull(); + assertThat(res.getVertices()).as("no vertices in the resulting graph after resolver").isNotNull(); + assertThat(res.getExcidentEdges(v1)).as("no edges in the resulting graph after resolver").isNotNull(); + + assertThat(res.getVertices().size()).as("wrong # of vertices in the resulting graph after resolver").isEqualTo(4); + assertThat(res.getExcidentEdges(v1).size()).as("wrong # of excident edges in the resulting graph entry after resolver").isEqualTo(2); + + assertThat(res.getIncidentEdges(v2).size()).as("wrong # of v2 incident edges in the resulting graph after resolver").isEqualTo(1); + assertThat(res.getIncidentEdges(v2).get(0).getVersion()).as("wrong edge v1-v2 in the resulting graph after resolver").isEqualTo("1.2"); + + assertThat(res.getIncidentEdges(v3).size()).as("wrong # of edges v1-v3 in the resulting graph after resolver").isEqualTo(1); + assertThat(res.getIncidentEdges(v3).get(0).getVersion()).as("wrong edge v1-v3 in the resulting graph after resolver").isEqualTo("1.1"); + + assertThat(res.getIncidentEdges(v4).size()).as("wrong # of edges v3-v4 in the resulting graph after resolver").isEqualTo(1); + assertThat(res.getIncidentEdges(v4).get(0).getVersion()).as("wrong edge v3-v4 in the resulting graph after resolver").isEqualTo("1.2"); } // ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------ diff --git a/compat/maven-compat/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerTest.java b/compat/maven-compat/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerTest.java index 18de14738221..0ab4d2193f69 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerTest.java @@ -32,6 +32,7 @@ import org.apache.maven.execution.DefaultMavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; @@ -39,7 +40,7 @@ import org.mockito.MockitoAnnotations; import org.slf4j.Logger; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.ArgumentMatchers.anyString; @@ -50,6 +51,7 @@ import static org.mockito.Mockito.when; class DefaultToolchainManagerTest { + private AutoCloseable mocks; // Mocks to inject into toolchainManager @Mock private Logger logger; @@ -67,7 +69,7 @@ class DefaultToolchainManagerTest { @BeforeEach void onSetup() throws Exception { - MockitoAnnotations.initMocks(this); + mocks = MockitoAnnotations.openMocks(this); Map factories = new HashMap<>(); factories.put("basic", toolchainFactoryBasicType); @@ -81,18 +83,18 @@ void onSetup() throws Exception { } @Test - void testNoModels() { + void noModels() { MavenSession session = mock(MavenSession.class); MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); when(session.getRequest()).thenReturn(executionRequest); List toolchains = toolchainManager.getToolchains(session, "unknown", null); - assertEquals(0, toolchains.size()); + assertThat(toolchains.size()).isEqualTo(0); } @Test - void testModelNoFactory() { + void modelNoFactory() { MavenSession session = mock(MavenSession.class); MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); List toolchainModels = new ArrayList<>(); @@ -104,12 +106,12 @@ void testModelNoFactory() { List toolchains = toolchainManager.getToolchains(session, "unknown", null); - assertEquals(0, toolchains.size()); + assertThat(toolchains.size()).isEqualTo(0); verify(logger).error("Missing toolchain factory for type: unknown. Possibly caused by misconfigured project."); } @Test - void testModelAndFactory() { + void modelAndFactory() { MavenSession session = mock(MavenSession.class); List toolchainModels = List.of( ToolchainModel.newBuilder().type("basic").build(), @@ -124,11 +126,11 @@ void testModelAndFactory() { List toolchains = toolchainManager.getToolchains(session, "rare", null); - assertEquals(1, toolchains.size()); + assertThat(toolchains.size()).isEqualTo(1); } @Test - void testModelsAndFactory() { + void modelsAndFactory() { MavenSession session = mock(MavenSession.class); Session sessionv4 = mock(Session.class); when(session.getSession()).thenReturn(sessionv4); @@ -145,11 +147,11 @@ void testModelsAndFactory() { List toolchains = toolchainManager.getToolchains(session, "basic", null); - assertEquals(2, toolchains.size()); + assertThat(toolchains.size()).isEqualTo(2); } @Test - void testRequirements() throws Exception { + void requirements() throws Exception { MavenSession session = mock(MavenSession.class); MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); when(session.getRequest()).thenReturn(executionRequest); @@ -170,11 +172,11 @@ void testRequirements() throws Exception { List toolchains = toolchainManager.getToolchains(session, "basic", Collections.singletonMap("key", "value")); - assertEquals(1, toolchains.size()); + assertThat(toolchains.size()).isEqualTo(1); } @Test - void testToolchainsForAvailableType() throws Exception { + void toolchainsForAvailableType() throws Exception { // prepare MavenSession session = mock(MavenSession.class); MavenExecutionRequest req = new DefaultMavenExecutionRequest(); @@ -192,11 +194,11 @@ void testToolchainsForAvailableType() throws Exception { // verify verify(logger, never()).error(anyString()); - assertEquals(1, toolchains.length); + assertThat(toolchains.length).isEqualTo(1); } @Test - void testToolchainsForUnknownType() throws Exception { + void toolchainsForUnknownType() throws Exception { // prepare MavenSession session = mock(MavenSession.class); MavenExecutionRequest req = new DefaultMavenExecutionRequest(); @@ -212,11 +214,11 @@ void testToolchainsForUnknownType() throws Exception { // verify verify(logger).error("Missing toolchain factory for type: unknown. Possibly caused by misconfigured project."); - assertEquals(0, toolchains.length); + assertThat(toolchains.length).isEqualTo(0); } @Test - void testToolchainsForConfiguredType() throws Exception { + void toolchainsForConfiguredType() throws Exception { // prepare MavenSession session = mock(MavenSession.class); MavenExecutionRequest req = new DefaultMavenExecutionRequest(); @@ -243,11 +245,11 @@ void testToolchainsForConfiguredType() throws Exception { // verify verify(logger, never()).error(anyString()); - assertEquals(2, toolchains.length); + assertThat(toolchains.length).isEqualTo(2); } @Test - void testMisconfiguredToolchain() throws Exception { + void misconfiguredToolchain() throws Exception { // prepare MavenSession session = mock(MavenSession.class); MavenExecutionRequest req = new DefaultMavenExecutionRequest(); @@ -259,6 +261,11 @@ void testMisconfiguredToolchain() throws Exception { ToolchainPrivate[] basics = toolchainManager.getToolchainsForType("basic", session); // verify - assertEquals(0, basics.length); + assertThat(basics.length).isEqualTo(0); + } + + @AfterEach + void tearDown() throws Exception { + mocks.close(); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java b/compat/maven-compat/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java index d6efd846dfac..831111c0b0c3 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java @@ -23,23 +23,23 @@ import org.apache.maven.toolchain.java.DefaultJavaToolChain; import org.apache.maven.toolchain.model.ToolchainModel; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.MockitoAnnotations; import org.slf4j.Logger; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; class DefaultToolchainTest { + private AutoCloseable mocks; private final Logger logger = mock(Logger.class); @BeforeEach void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + mocks = MockitoAnnotations.openMocks(this); } private DefaultToolchain newDefaultToolchain(ToolchainModel model) { @@ -61,53 +61,53 @@ public String findTool(String toolName) { } @Test - void testGetModel() { + void getModel() { ToolchainModel model = new ToolchainModel(); DefaultToolchain toolchain = newDefaultToolchain(model); - assertEquals(model, toolchain.getModel()); + assertThat(toolchain.getModel()).isEqualTo(model); } @Test - void testGetType() { + void getType() { ToolchainModel model = new ToolchainModel(); DefaultToolchain toolchain = newDefaultToolchain(model, "TYPE"); - assertEquals("TYPE", toolchain.getType()); + assertThat(toolchain.getType()).isEqualTo("TYPE"); model.setType("MODEL_TYPE"); toolchain = newDefaultToolchain(model); - assertEquals("MODEL_TYPE", toolchain.getType()); + assertThat(toolchain.getType()).isEqualTo("MODEL_TYPE"); } @Test - void testGetLogger() { + void getLogger() { ToolchainModel model = new ToolchainModel(); DefaultToolchain toolchain = newDefaultToolchain(model); - assertEquals(logger, toolchain.getLog()); + assertThat(toolchain.getLog()).isEqualTo(logger); } @Test - void testMissingRequirementProperty() { + void missingRequirementProperty() { ToolchainModel model = new ToolchainModel(); model.setType("TYPE"); DefaultToolchain toolchain = newDefaultToolchain(model); - assertFalse(toolchain.matchesRequirements(Collections.singletonMap("name", "John Doe"))); + assertThat(toolchain.matchesRequirements(Collections.singletonMap("name", "John Doe"))).isFalse(); verify(logger).debug("Toolchain {} is missing required property: {}", toolchain, "name"); } @Test - void testNonMatchingRequirementProperty() { + void nonMatchingRequirementProperty() { ToolchainModel model = new ToolchainModel(); model.setType("TYPE"); DefaultToolchain toolchain = newDefaultToolchain(model); toolchain.addProvideToken("name", RequirementMatcherFactory.createExactMatcher("Jane Doe")); - assertFalse(toolchain.matchesRequirements(Collections.singletonMap("name", "John Doe"))); + assertThat(toolchain.matchesRequirements(Collections.singletonMap("name", "John Doe"))).isFalse(); verify(logger).debug("Toolchain {} doesn't match required property: {}", toolchain, "name"); } @Test - void testEquals() { + void equals() { ToolchainModel tm1 = new ToolchainModel(); tm1.setType("jdk"); tm1.addProvide("version", "1.5"); @@ -131,9 +131,14 @@ void testEquals() { DefaultToolchain tc1 = new DefaultJavaToolChain(tm1, null); DefaultToolchain tc2 = new DefaultJavaToolChain(tm2, null); - assertEquals(tc1, tc1); - assertNotEquals(tc1, tc2); - assertNotEquals(tc2, tc1); - assertEquals(tc2, tc2); + assertThat(tc1).isEqualTo(tc1); + assertThat(tc2).isNotEqualTo(tc1); + assertThat(tc1).isNotEqualTo(tc2); + assertThat(tc2).isEqualTo(tc2); + } + + @AfterEach + void tearDown() throws Exception { + mocks.close(); } } diff --git a/compat/maven-compat/src/test/java/org/apache/maven/toolchain/RequirementMatcherFactoryTest.java b/compat/maven-compat/src/test/java/org/apache/maven/toolchain/RequirementMatcherFactoryTest.java index 7cb3b23ca0bb..d670e36a1ccf 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/toolchain/RequirementMatcherFactoryTest.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/toolchain/RequirementMatcherFactoryTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -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.assertj.core.api.Assertions.assertThat; /** * @@ -33,33 +31,33 @@ class RequirementMatcherFactoryTest { * Test of createExactMatcher method, of class RequirementMatcherFactory. */ @Test - void testCreateExactMatcher() { + void createExactMatcher() { RequirementMatcher matcher; matcher = RequirementMatcherFactory.createExactMatcher("foo"); - assertFalse(matcher.matches("bar")); - assertFalse(matcher.matches("foobar")); - assertFalse(matcher.matches("foob")); - assertTrue(matcher.matches("foo")); + assertThat(matcher.matches("bar")).isFalse(); + assertThat(matcher.matches("foobar")).isFalse(); + assertThat(matcher.matches("foob")).isFalse(); + assertThat(matcher.matches("foo")).isTrue(); } /** * Test of createVersionMatcher method, of class RequirementMatcherFactory. */ @Test - void testCreateVersionMatcher() { + void createVersionMatcher() { RequirementMatcher matcher; matcher = RequirementMatcherFactory.createVersionMatcher("1.5.2"); - assertFalse(matcher.matches("1.5")); - assertTrue(matcher.matches("1.5.2")); - assertFalse(matcher.matches("[1.4,1.5)")); - assertFalse(matcher.matches("[1.5,1.5.2)")); - assertFalse(matcher.matches("(1.5.2,1.6)")); - assertTrue(matcher.matches("(1.4,1.5.2]")); - assertTrue(matcher.matches("(1.5,)")); - assertEquals("1.5.2", matcher.toString()); + assertThat(matcher.matches("1.5")).isFalse(); + assertThat(matcher.matches("1.5.2")).isTrue(); + assertThat(matcher.matches("[1.4,1.5)")).isFalse(); + assertThat(matcher.matches("[1.5,1.5.2)")).isFalse(); + assertThat(matcher.matches("(1.5.2,1.6)")).isFalse(); + assertThat(matcher.matches("(1.4,1.5.2]")).isTrue(); + assertThat(matcher.matches("(1.5,)")).isTrue(); + assertThat(matcher.toString()).isEqualTo("1.5.2"); // Ensure it is not printed as 1.5.0 matcher = RequirementMatcherFactory.createVersionMatcher("1.5"); - assertEquals("1.5", matcher.toString()); + assertThat(matcher.toString()).isEqualTo("1.5"); } } diff --git a/compat/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java b/compat/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java index 1a531085cf02..f5d6d6e8ac86 100644 --- a/compat/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java +++ b/compat/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java @@ -113,7 +113,7 @@ String getOptionsAsHtml() { } @Test - void testOptionsAsHtml() throws IOException { + void optionsAsHtml() throws IOException { Path options = Paths.get("target/test-classes/options.html"); Files.writeString(options, getOptionsAsHtml(), StandardCharsets.UTF_8); } diff --git a/compat/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java b/compat/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java index 3f5e70b7f59a..40604ee70df4 100644 --- a/compat/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java +++ b/compat/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java @@ -20,21 +20,21 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; @Deprecated class CLIReportingUtilsTest { @Test - void testFormatDuration() { - assertEquals("0.001 s", CLIReportingUtils.formatDuration(1)); - assertEquals("0.999 s", CLIReportingUtils.formatDuration(1000 - 1)); - assertEquals("1.000 s", CLIReportingUtils.formatDuration(1000)); - assertEquals("59.999 s", CLIReportingUtils.formatDuration(60 * 1000 - 1)); - assertEquals("01:00 min", CLIReportingUtils.formatDuration(60 * 1000)); - assertEquals("59:59 min", CLIReportingUtils.formatDuration(60 * 60 * 1000 - 1)); - assertEquals("01:00 h", CLIReportingUtils.formatDuration(60 * 60 * 1000)); - assertEquals("23:59 h", CLIReportingUtils.formatDuration(24 * 60 * 60 * 1000 - 1)); - assertEquals("1 d 00:00 h", CLIReportingUtils.formatDuration(24 * 60 * 60 * 1000)); + void formatDuration() { + assertThat(CLIReportingUtils.formatDuration(1)).isEqualTo("0.001 s"); + assertThat(CLIReportingUtils.formatDuration(1000 - 1)).isEqualTo("0.999 s"); + assertThat(CLIReportingUtils.formatDuration(1000)).isEqualTo("1.000 s"); + assertThat(CLIReportingUtils.formatDuration(60 * 1000 - 1)).isEqualTo("59.999 s"); + assertThat(CLIReportingUtils.formatDuration(60 * 1000)).isEqualTo("01:00 min"); + assertThat(CLIReportingUtils.formatDuration(60 * 60 * 1000 - 1)).isEqualTo("59:59 min"); + assertThat(CLIReportingUtils.formatDuration(60 * 60 * 1000)).isEqualTo("01:00 h"); + assertThat(CLIReportingUtils.formatDuration(24 * 60 * 60 * 1000 - 1)).isEqualTo("23:59 h"); + assertThat(CLIReportingUtils.formatDuration(24 * 60 * 60 * 1000)).isEqualTo("1 d 00:00 h"); } } diff --git a/compat/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java b/compat/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java index 396cab4bb80a..6d5c8e803122 100644 --- a/compat/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java +++ b/compat/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java @@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** */ @@ -39,26 +39,26 @@ void cleanArgs() { void cleanArgsShouldRemoveWrongSurroundingQuotes() { String[] args = {"\"-Dfoo=bar", "\"-Dfoo2=bar two\""}; String[] cleanArgs = CleanArgument.cleanArgs(args); - assertEquals(args.length, cleanArgs.length); - assertEquals("-Dfoo=bar", cleanArgs[0]); - assertEquals("-Dfoo2=bar two", cleanArgs[1]); + assertThat(cleanArgs.length).isEqualTo(args.length); + assertThat(cleanArgs[0]).isEqualTo("-Dfoo=bar"); + assertThat(cleanArgs[1]).isEqualTo("-Dfoo2=bar two"); } @Test - void testCleanArgsShouldNotTouchCorrectlyQuotedArgumentsUsingDoubleQuotes() { + void cleanArgsShouldNotTouchCorrectlyQuotedArgumentsUsingDoubleQuotes() { String information = "-Dinformation=\"The Information is important.\""; String[] args = {information}; String[] cleanArgs = CleanArgument.cleanArgs(args); - assertEquals(args.length, cleanArgs.length); - assertEquals(information, cleanArgs[0]); + assertThat(cleanArgs.length).isEqualTo(args.length); + assertThat(cleanArgs[0]).isEqualTo(information); } @Test - void testCleanArgsShouldNotTouchCorrectlyQuotedArgumentsUsingSingleQuotes() { + void cleanArgsShouldNotTouchCorrectlyQuotedArgumentsUsingSingleQuotes() { String information = "-Dinformation='The Information is important.'"; String[] args = {information}; String[] cleanArgs = CleanArgument.cleanArgs(args); - assertEquals(args.length, cleanArgs.length); - assertEquals(information, cleanArgs[0]); + assertThat(cleanArgs.length).isEqualTo(args.length); + assertThat(cleanArgs[0]).isEqualTo(information); } } diff --git a/compat/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java b/compat/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java index ae1f439dc751..65e849eb28ed 100644 --- a/compat/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java +++ b/compat/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java @@ -68,16 +68,14 @@ import static java.util.Arrays.asList; import static org.apache.maven.cli.MavenCli.performProfileActivation; import static org.apache.maven.cli.MavenCli.performProjectActivation; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.inOrder; @@ -134,7 +132,7 @@ void testPerformProfileActivation() throws ParseException { } @Test - void testDetermineProjectActivation() throws ParseException { + void determineProjectActivation() throws ParseException { final CommandLineParser parser = new DefaultParser(); final Options options = new Options(); @@ -161,29 +159,29 @@ void testDetermineProjectActivation() throws ParseException { } @Test - void testCalculateDegreeOfConcurrency() { - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("0")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("-1")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("0x4")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("1.0")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("1.")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("AA")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("C")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("C2.2C")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("C2.2")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("2C2")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("CXXX")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("XXXC")); + void calculateDegreeOfConcurrency() { + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("0")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("-1")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("0x4")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("1.0")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("1.")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("AA")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("C")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("C2.2C")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("C2.2")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("2C2")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("CXXX")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("XXXC")); int cpus = Runtime.getRuntime().availableProcessors(); - assertEquals((int) (cpus * 2.2), cli.calculateDegreeOfConcurrency("2.2C")); - assertEquals(1, cli.calculateDegreeOfConcurrency("0.0001C")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("-2.2C")); - assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("0C")); + assertThat(cli.calculateDegreeOfConcurrency("2.2C")).isEqualTo((int) (cpus * 2.2)); + assertThat(cli.calculateDegreeOfConcurrency("0.0001C")).isEqualTo(1); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("-2.2C")); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> cli.calculateDegreeOfConcurrency("0C")); } @Test - void testMavenConfig() throws Exception { + void mavenConfig() throws Exception { System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY, new File("src/test/projects/config").getCanonicalPath()); CliRequest request = new CliRequest(new String[0], null); @@ -191,24 +189,24 @@ void testMavenConfig() throws Exception { // read .mvn/maven.config cli.initialize(request); cli.cli(request); - assertEquals("multithreaded", request.commandLine.getOptionValue(CLIManager.BUILDER)); - assertEquals("8", request.commandLine.getOptionValue(CLIManager.THREADS)); + assertThat(request.commandLine.getOptionValue(CLIManager.BUILDER)).isEqualTo("multithreaded"); + assertThat(request.commandLine.getOptionValue(CLIManager.THREADS)).isEqualTo("8"); // override from command line request = new CliRequest(new String[] {"--builder", "foobar"}, null); cli.cli(request); - assertEquals("foobar", request.commandLine.getOptionValue("builder")); + assertThat(request.commandLine.getOptionValue("builder")).isEqualTo("foobar"); } @Test - void testMavenConfigInvalid() throws Exception { + void mavenConfigInvalid() throws Exception { System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY, new File("src/test/projects/config-illegal").getCanonicalPath()); CliRequest request = new CliRequest(new String[0], null); cli.initialize(request); - assertThrows(ParseException.class, () -> cli.cli(request)); + assertThatExceptionOfType(ParseException.class).isThrownBy(() -> cli.cli(request)); } /** @@ -225,7 +223,7 @@ void testMavenConfigInvalid() throws Exception { * @throws Exception in case of failure. */ @Test - void testMVNConfigurationThreadCanBeOverwrittenViaCommandLine() throws Exception { + void mvnConfigurationThreadCanBeOverwrittenViaCommandLine() throws Exception { System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY, new File("src/test/projects/mavenConfigProperties").getCanonicalPath()); @@ -235,7 +233,7 @@ void testMVNConfigurationThreadCanBeOverwrittenViaCommandLine() throws Exception // read .mvn/maven.config cli.cli(request); - assertEquals("5", request.commandLine.getOptionValue(CLIManager.THREADS)); + assertThat(request.commandLine.getOptionValue(CLIManager.THREADS)).isEqualTo("5"); } /** @@ -252,7 +250,7 @@ void testMVNConfigurationThreadCanBeOverwrittenViaCommandLine() throws Exception * @throws Exception */ @Test - void testMVNConfigurationDefinedPropertiesCanBeOverwrittenViaCommandLine() throws Exception { + void mvnConfigurationDefinedPropertiesCanBeOverwrittenViaCommandLine() throws Exception { System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY, new File("src/test/projects/mavenConfigProperties").getCanonicalPath()); @@ -264,7 +262,7 @@ void testMVNConfigurationDefinedPropertiesCanBeOverwrittenViaCommandLine() throw cli.properties(request); String revision = request.getUserProperties().getProperty("revision"); - assertEquals("8.1.0", revision); + assertThat(revision).isEqualTo("8.1.0"); } /** @@ -281,7 +279,7 @@ void testMVNConfigurationDefinedPropertiesCanBeOverwrittenViaCommandLine() throw * @throws Exception */ @Test - void testMVNConfigurationCLIRepeatedPropertiesLastWins() throws Exception { + void mvnConfigurationCLIRepeatedPropertiesLastWins() throws Exception { System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY, new File("src/test/projects/mavenConfigProperties").getCanonicalPath()); @@ -293,7 +291,7 @@ void testMVNConfigurationCLIRepeatedPropertiesLastWins() throws Exception { cli.properties(request); String revision = request.getUserProperties().getProperty("revision"); - assertEquals("8.2.0", revision); + assertThat(revision).isEqualTo("8.2.0"); } /** @@ -310,7 +308,7 @@ void testMVNConfigurationCLIRepeatedPropertiesLastWins() throws Exception { * @throws Exception */ @Test - void testMVNConfigurationFunkyArguments() throws Exception { + void mvnConfigurationFunkyArguments() throws Exception { System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY, new File("src/test/projects/mavenConfigProperties").getCanonicalPath()); @@ -325,20 +323,20 @@ void testMVNConfigurationFunkyArguments() throws Exception { cli.cli(request); cli.properties(request); - assertEquals("3", request.commandLine.getOptionValue(CLIManager.THREADS)); + assertThat(request.commandLine.getOptionValue(CLIManager.THREADS)).isEqualTo("3"); String revision = request.getUserProperties().getProperty("revision"); - assertEquals("8.2.0", revision); + assertThat(revision).isEqualTo("8.2.0"); - assertEquals("bar ", request.getUserProperties().getProperty("foo")); - assertEquals("bar two", request.getUserProperties().getProperty("foo2")); - assertEquals("Apache Maven", request.getUserProperties().getProperty("label")); + assertThat(request.getUserProperties().getProperty("foo")).isEqualTo("bar "); + assertThat(request.getUserProperties().getProperty("foo2")).isEqualTo("bar two"); + assertThat(request.getUserProperties().getProperty("label")).isEqualTo("Apache Maven"); - assertEquals("-Dpom.xml", request.getCommandLine().getOptionValue(CLIManager.ALTERNATE_POM_FILE)); + assertThat(request.getCommandLine().getOptionValue(CLIManager.ALTERNATE_POM_FILE)).isEqualTo("-Dpom.xml"); } @Test - void testStyleColors() throws Exception { + void styleColors() throws Exception { assumeTrue(MessageUtils.isColorEnabled(), "ANSI not supported"); CliRequest request; @@ -347,21 +345,21 @@ void testStyleColors() throws Exception { cli.cli(request); cli.properties(request); cli.logging(request); - assertFalse(MessageUtils.isColorEnabled()); + assertThat(MessageUtils.isColorEnabled()).isFalse(); MessageUtils.setColorEnabled(true); request = new CliRequest(new String[] {"--non-interactive"}, null); cli.cli(request); cli.properties(request); cli.logging(request); - assertFalse(MessageUtils.isColorEnabled()); + assertThat(MessageUtils.isColorEnabled()).isFalse(); MessageUtils.setColorEnabled(true); request = new CliRequest(new String[] {"--force-interactive", "--non-interactive"}, null); cli.cli(request); cli.properties(request); cli.logging(request); - assertTrue(MessageUtils.isColorEnabled()); + assertThat(MessageUtils.isColorEnabled()).isTrue(); MessageUtils.setColorEnabled(true); request = new CliRequest(new String[] {"-l", "target/temp/mvn.log"}, null); @@ -369,21 +367,21 @@ void testStyleColors() throws Exception { cli.cli(request); cli.properties(request); cli.logging(request); - assertFalse(MessageUtils.isColorEnabled()); + assertThat(MessageUtils.isColorEnabled()).isFalse(); MessageUtils.setColorEnabled(false); request = new CliRequest(new String[] {"-Dstyle.color=always"}, null); cli.cli(request); cli.properties(request); cli.logging(request); - assertTrue(MessageUtils.isColorEnabled()); + assertThat(MessageUtils.isColorEnabled()).isTrue(); MessageUtils.setColorEnabled(true); request = new CliRequest(new String[] {"-Dstyle.color=never"}, null); cli.cli(request); cli.properties(request); cli.logging(request); - assertFalse(MessageUtils.isColorEnabled()); + assertThat(MessageUtils.isColorEnabled()).isFalse(); MessageUtils.setColorEnabled(false); request = new CliRequest(new String[] {"-Dstyle.color=always", "-B", "-l", "target/temp/mvn.log"}, null); @@ -391,7 +389,7 @@ void testStyleColors() throws Exception { cli.cli(request); cli.properties(request); cli.logging(request); - assertTrue(MessageUtils.isColorEnabled()); + assertThat(MessageUtils.isColorEnabled()).isTrue(); MessageUtils.setColorEnabled(false); CliRequest maybeColorRequest = @@ -399,15 +397,14 @@ void testStyleColors() throws Exception { request.workingDirectory = "target/temp"; cli.cli(maybeColorRequest); cli.properties(maybeColorRequest); - assertThrows( - IllegalArgumentException.class, () -> cli.logging(maybeColorRequest), "maybe is not a valid option"); + assertThatExceptionOfType(IllegalArgumentException.class).as("maybe is not a valid option").isThrownBy(() -> cli.logging(maybeColorRequest)); } /** * Verifies MNG-6558 */ @Test - void testToolchainsBuildingEvents() throws Exception { + void toolchainsBuildingEvents() throws Exception { final EventSpyDispatcher eventSpyDispatcherMock = mock(EventSpyDispatcher.class); MavenCli customizedMavenCli = new MavenCli() { @Override @@ -489,7 +486,7 @@ void verifyLocalRepositoryPath() throws Exception { * @throws Exception cli invocation. */ @Test - void testVersionStringWithoutAnsi() throws Exception { + void versionStringWithoutAnsi() throws Exception { // given // - request with version and batch mode CliRequest cliRequest = new CliRequest(new String[] {"--version", "--batch-mode"}, null); @@ -509,7 +506,7 @@ void testVersionStringWithoutAnsi() throws Exception { String versionOut = new String(systemOut.toByteArray(), StandardCharsets.UTF_8); // then - assertEquals(stripAnsiCodes(versionOut), versionOut); + assertThat(versionOut).isEqualTo(stripAnsiCodes(versionOut)); } @Test @@ -579,13 +576,13 @@ void populatePropertiesOverwrite() throws Exception { } @Test - public void findRootProjectWithAttribute() { + void findRootProjectWithAttribute() { Path test = Paths.get("src/test/projects/root-attribute"); - assertEquals(test, new DefaultRootLocator().findRoot(test.resolve("child"))); + assertThat(new DefaultRootLocator().findRoot(test.resolve("child"))).isEqualTo(test); } @Test - public void testPropertiesInterpolation() throws Exception { + void propertiesInterpolation() throws Exception { FileSystem fs = Jimfs.newFileSystem(Configuration.windows()); Path mavenHome = fs.getPath("C:\\maven"); @@ -643,14 +640,14 @@ public void testPropertiesInterpolation() throws Exception { } @Test - public void testEmptyProfile() throws Exception { + void emptyProfile() throws Exception { CliRequest request = new CliRequest(new String[] {"-P", ""}, null); cli.cli(request); cli.populateRequest(request); } @Test - public void testEmptyProject() throws Exception { + void emptyProject() throws Exception { CliRequest request = new CliRequest(new String[] {"-pl", ""}, null); cli.cli(request); cli.populateRequest(request); @@ -658,7 +655,7 @@ public void testEmptyProject() throws Exception { @ParameterizedTest @MethodSource("activateBatchModeArguments") - public void activateBatchMode(boolean ciEnv, String[] cliArgs, boolean isBatchMode) throws Exception { + void activateBatchMode(boolean ciEnv, String[] cliArgs, boolean isBatchMode) throws Exception { CliRequest request = new CliRequest(cliArgs, null); if (ciEnv) { request.getSystemProperties().put("env.CI", "true"); @@ -685,7 +682,7 @@ public static Stream activateBatchModeArguments() { @ParameterizedTest @MethodSource("calculateTransferListenerArguments") - public void calculateTransferListener(boolean ciEnv, String[] cliArgs, Class expectedSubClass) + void calculateTransferListener(boolean ciEnv, String[] cliArgs, Class expectedSubClass) throws Exception { CliRequest request = new CliRequest(cliArgs, null); if (ciEnv) { diff --git a/compat/maven-embedder/src/test/java/org/apache/maven/cli/event/ExecutionEventLoggerTest.java b/compat/maven-embedder/src/test/java/org/apache/maven/cli/event/ExecutionEventLoggerTest.java index 9d9a8f19c061..b2f935721e1d 100644 --- a/compat/maven-embedder/src/test/java/org/apache/maven/cli/event/ExecutionEventLoggerTest.java +++ b/compat/maven-embedder/src/test/java/org/apache/maven/cli/event/ExecutionEventLoggerTest.java @@ -65,7 +65,7 @@ void beforeEach() { } @Test - void testProjectStarted() { + void projectStarted() { // prepare File basedir = new File("").getAbsoluteFile(); ExecutionEvent event = mock(ExecutionEvent.class); @@ -98,7 +98,7 @@ void testProjectStarted() { } @Test - void testProjectStartedOverflow() { + void projectStartedOverflow() { // prepare File basedir = new File("").getAbsoluteFile(); ExecutionEvent event = mock(ExecutionEvent.class); @@ -130,7 +130,7 @@ void testProjectStartedOverflow() { } @Test - void testTerminalWidth() { + void terminalWidth() { // prepare Logger logger = mock(Logger.class); when(logger.isInfoEnabled()).thenReturn(true); @@ -170,7 +170,7 @@ void testTerminalWidth() { } @Test - void testProjectStartedNoPom() { + void projectStartedNoPom() { // prepare File basedir = new File("").getAbsoluteFile(); ExecutionEvent event = mock(ExecutionEvent.class); @@ -196,7 +196,7 @@ void testProjectStartedNoPom() { } @Test - void testMultiModuleProjectProgress() { + void multiModuleProjectProgress() { // prepare MavenProject project1 = generateMavenProject("Apache Maven Embedder 1"); MavenProject project2 = generateMavenProject("Apache Maven Embedder 2"); @@ -229,7 +229,7 @@ void testMultiModuleProjectProgress() { } @Test - void testMultiModuleProjectResumeFromProgress() { + void multiModuleProjectResumeFromProgress() { // prepare MavenProject project1 = generateMavenProject("Apache Maven Embedder 1"); MavenProject project2 = generateMavenProject("Apache Maven Embedder 2"); diff --git a/compat/maven-embedder/src/test/java/org/apache/maven/cli/props/MavenPropertiesLoaderTest.java b/compat/maven-embedder/src/test/java/org/apache/maven/cli/props/MavenPropertiesLoaderTest.java index c54dd22d9f25..8664b5bb86b3 100644 --- a/compat/maven-embedder/src/test/java/org/apache/maven/cli/props/MavenPropertiesLoaderTest.java +++ b/compat/maven-embedder/src/test/java/org/apache/maven/cli/props/MavenPropertiesLoaderTest.java @@ -28,15 +28,14 @@ import com.google.common.jimfs.Jimfs; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; @Deprecated class MavenPropertiesLoaderTest { @Test - void testIncludes() throws Exception { + void includes() throws Exception { FileSystem fs = Jimfs.newFileSystem(Configuration.unix()); Path mavenHome = fs.getPath("/maven"); @@ -52,17 +51,16 @@ void testIncludes() throws Exception { Properties p = new Properties(); p.put("java.version", "11"); - assertThrows( - NoSuchFileException.class, () -> MavenPropertiesLoader.loadProperties(p, mavenUserProps, null, false)); + assertThatExceptionOfType(NoSuchFileException.class).isThrownBy(() -> MavenPropertiesLoader.loadProperties(p, mavenUserProps, null, false)); Path another = propsPath.resolveSibling("another.properties"); Files.writeString(another, "bar = chti${java.version}\n"); MavenPropertiesLoader.loadProperties(p, mavenUserProps, null, false); - assertEquals("chti11z", p.getProperty("fro")); + assertThat(p.getProperty("fro")).isEqualTo("chti11z"); } @Test - void testIncludes3() throws Exception { + void includes3() throws Exception { FileSystem fs = Jimfs.newFileSystem(Configuration.unix()); Path mavenHome = fs.getPath("/maven"); @@ -83,14 +81,14 @@ void testIncludes3() throws Exception { Properties p = new Properties(); p.put("user.home", userDirectory.toString()); MavenPropertiesLoader.loadProperties(p, mavenUserProps, p::getProperty, false); - assertEquals("bar", p.getProperty("foo")); - assertNull(p.getProperty("foo-env")); + assertThat(p.getProperty("foo")).isEqualTo("bar"); + assertThat(p.getProperty("foo-env")).isNull(); p = new Properties(); p.put("user.home", userDirectory.toString()); p.put("env.envName", "ci"); MavenPropertiesLoader.loadProperties(p, mavenUserProps, p::getProperty, false); - assertEquals("bar-env", p.getProperty("foo")); - assertEquals("bar", p.getProperty("foo-env")); + assertThat(p.getProperty("foo")).isEqualTo("bar-env"); + assertThat(p.getProperty("foo-env")).isEqualTo("bar"); } } diff --git a/compat/maven-embedder/src/test/java/org/apache/maven/cli/props/MavenPropertiesTest.java b/compat/maven-embedder/src/test/java/org/apache/maven/cli/props/MavenPropertiesTest.java index 07aa1e8ba664..b664de6e61a7 100644 --- a/compat/maven-embedder/src/test/java/org/apache/maven/cli/props/MavenPropertiesTest.java +++ b/compat/maven-embedder/src/test/java/org/apache/maven/cli/props/MavenPropertiesTest.java @@ -31,15 +31,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Unit tests on MavenProperties. */ @Deprecated -public class MavenPropertiesTest { +class MavenPropertiesTest { private static final String LINE_SEPARATOR = System.getProperty("line.separator"); private static final String COMMENT = "# comment"; @@ -65,13 +63,13 @@ public class MavenPropertiesTest { * @see junit.framework.TestCase#setUp() */ @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { properties = new MavenProperties(); properties.load(new StringReader(TEST_PROPERTIES)); } @Test - public void testSpaces() throws Exception { + void spaces() throws Exception { String config = "\n" + "\n" + " \n" + " \n" @@ -108,74 +106,74 @@ public void testSpaces() throws Exception { props2.load(new StringReader(config)); String s325 = props1.getProperty(" \r"); - assertEquals("\n \t \f", s325, "1"); + assertThat(s325).as("1").isEqualTo("\n \t \f"); String s324 = props1.getProperty("a"); - assertEquals("a", s324, "2"); + assertThat(s324).as("2").isEqualTo("a"); String s323 = props1.getProperty("b"); - assertEquals("bb as,dn ", s323, "3"); + assertThat(s323).as("3").isEqualTo("bb as,dn "); String s322 = props1.getProperty("c\r \t\nu"); - assertEquals(":: cu", s322, "4"); + assertThat(s322).as("4").isEqualTo(":: cu"); String s321 = props1.getProperty("bu"); - assertEquals("bu", s321, "5"); + assertThat(s321).as("5").isEqualTo("bu"); String s320 = props1.getProperty("d"); - assertEquals("d\r\ne=e", s320, "6"); + assertThat(s320).as("6").isEqualTo("d\r\ne=e"); String s319 = props1.getProperty("f"); - assertEquals("fff", s319, "7"); + assertThat(s319).as("7").isEqualTo("fff"); String s318 = props1.getProperty("g"); - assertEquals("g", s318, "8"); + assertThat(s318).as("8").isEqualTo("g"); String s317 = props1.getProperty("h h"); - assertEquals("", s317, "9"); + assertThat(s317).as("9").isEqualTo(""); String s316 = props1.getProperty(" "); - assertEquals("i=i", s316, "10"); + assertThat(s316).as("10").isEqualTo("i=i"); String s315 = props1.getProperty("j"); - assertEquals(" j", s315, "11"); + assertThat(s315).as("11").isEqualTo(" j"); String s314 = props1.getProperty("space"); - assertEquals(" c", s314, "12"); + assertThat(s314).as("12").isEqualTo(" c"); String s313 = props1.getProperty("dblbackslash"); - assertEquals("\\", s313, "13"); + assertThat(s313).as("13").isEqualTo("\\"); String s312 = props2.getProperty(" \r"); - assertEquals("\n \t \f", s312, "1"); + assertThat(s312).as("1").isEqualTo("\n \t \f"); String s311 = props2.getProperty("a"); - assertEquals("a", s311, "2"); + assertThat(s311).as("2").isEqualTo("a"); String s310 = props2.getProperty("b"); - assertEquals("bb as,dn ", s310, "3"); + assertThat(s310).as("3").isEqualTo("bb as,dn "); String s39 = props2.getProperty("c\r \t\nu"); - assertEquals(":: cu", s39, "4"); + assertThat(s39).as("4").isEqualTo(":: cu"); String s38 = props2.getProperty("bu"); - assertEquals("bu", s38, "5"); + assertThat(s38).as("5").isEqualTo("bu"); String s37 = props2.getProperty("d"); - assertEquals("d\r\ne=e", s37, "6"); + assertThat(s37).as("6").isEqualTo("d\r\ne=e"); String s36 = props2.getProperty("f"); - assertEquals("fff", s36, "7"); + assertThat(s36).as("7").isEqualTo("fff"); String s35 = props2.getProperty("g"); - assertEquals("g", s35, "8"); + assertThat(s35).as("8").isEqualTo("g"); String s34 = props2.getProperty("h h"); - assertEquals("", s34, "9"); + assertThat(s34).as("9").isEqualTo(""); String s33 = props2.getProperty(" "); - assertEquals("i=i", s33, "10"); + assertThat(s33).as("10").isEqualTo("i=i"); String s32 = props2.getProperty("j"); - assertEquals(" j", s32, "11"); + assertThat(s32).as("11").isEqualTo(" j"); String s31 = props2.getProperty("space"); - assertEquals(" c", s31, "12"); + assertThat(s31).as("12").isEqualTo(" c"); String s3 = props2.getProperty("dblbackslash"); - assertEquals("\\", s3, "13"); - assertEquals(props1, props2); + assertThat(s3).as("13").isEqualTo("\\"); + assertThat(props2).isEqualTo(props1); } @Test - public void testConfigInterpolation() throws IOException { + void configInterpolation() throws IOException { String config = "a=$\\\\\\\\{var}\n" + "ab=${a}b\n" + "abc=${ab}c"; Map expected = Map.of("a", "$\\{var}", "ab", "$\\{var}b", "abc", "$\\{var}bc"); java.util.Properties props1 = new java.util.Properties(); props1.load(new StringReader(config)); new DefaultInterpolator().performSubstitution((Map) props1, null, true); - assertEquals(expected, props1); + assertThat(props1).isEqualTo(expected); MavenProperties props2 = new MavenProperties(); props2.load(new StringReader(config)); - assertEquals(expected, props2); + assertThat(props2).isEqualTo(expected); } /** @@ -186,13 +184,13 @@ public void testConfigInterpolation() throws IOException { * @throws Exception */ @Test - public void testGettingProperty() throws Exception { + void gettingProperty() throws Exception { Object o2 = properties.get("test"); - assertEquals("test", o2); + assertThat(o2).isEqualTo("test"); } @Test - public void testLoadSave() throws IOException { + void loadSave() throws IOException { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("# "); @@ -225,19 +223,19 @@ public void testLoadSave() throws IOException { } @Test - public void testJavaUtilPropertiesCompatibility() throws Exception { + void javaUtilPropertiesCompatibility() throws Exception { MavenProperties properties = new MavenProperties(); properties.load(new StringReader(TEST_PROPERTIES)); String test = properties.getProperty("test"); - assertEquals("test", test); + assertThat(test).isEqualTo("test"); String defaultValue = properties.getProperty("notfound", "default"); - assertEquals("default", defaultValue); + assertThat(defaultValue).isEqualTo("default"); properties.setProperty("another", "another"); Object o1 = properties.getProperty("another"); - assertEquals("another", o1); + assertThat(o1).isEqualTo("another"); properties.store(System.err, null); System.err.println("===="); @@ -246,55 +244,55 @@ public void testJavaUtilPropertiesCompatibility() throws Exception { private static final String RESULT1 = COMMENT + LINE_SEPARATOR + KEY1A + " = " + VALUE1 + LINE_SEPARATOR; @Test - public void testSaveComment1() throws Exception { + void saveComment1() throws Exception { properties.put(KEY1, COMMENT, VALUE1); StringWriter sw = new StringWriter(); properties.save(sw); String msg = sw.toString(); - assertTrue(sw.toString().endsWith(RESULT1), msg); + assertThat(sw.toString().endsWith(RESULT1)).as(msg).isTrue(); } private static final String RESULT1A = COMMENT + LINE_SEPARATOR + KEY2A + " = " + VALUE1 + LINE_SEPARATOR; @Test - public void testSaveComment1a() throws Exception { + void saveComment1a() throws Exception { properties.put(KEY2, COMMENT, VALUE1); StringWriter sw = new StringWriter(); properties.save(sw); String msg = sw.toString(); - assertTrue(sw.toString().endsWith(RESULT1A), msg); + assertThat(sw.toString().endsWith(RESULT1A)).as(msg).isTrue(); } private static final String RESULT2 = COMMENT + LINE_SEPARATOR + COMMENT + LINE_SEPARATOR + KEY1A + " = " + VALUE1 + LINE_SEPARATOR; @Test - public void testSaveComment2() throws Exception { + void saveComment2() throws Exception { properties.put(KEY1, List.of(new String[] {COMMENT, COMMENT}), VALUE1); StringWriter sw = new StringWriter(); properties.save(sw); String msg = sw.toString(); - assertTrue(sw.toString().endsWith(RESULT2), msg); + assertThat(sw.toString().endsWith(RESULT2)).as(msg).isTrue(); } private static final String RESULT3 = COMMENT + LINE_SEPARATOR + COMMENT + LINE_SEPARATOR + KEY1A + " = " + VALUE1 + "\\" + LINE_SEPARATOR + VALUE1 + LINE_SEPARATOR; @Test - public void testSaveComment3() throws Exception { + void saveComment3() throws Exception { properties.put(KEY1, List.of(new String[] {COMMENT, COMMENT}), List.of(new String[] {VALUE1, VALUE1})); StringWriter sw = new StringWriter(); properties.save(sw); String msg = sw.toString(); - assertTrue(sw.toString().endsWith(RESULT3), msg); + assertThat(sw.toString().endsWith(RESULT3)).as(msg).isTrue(); List rawValue = properties.getRaw(KEY1); - assertEquals(2, (Object) rawValue.size()); - assertEquals(KEY1A + " = " + VALUE1, rawValue.get(0)); - assertEquals(VALUE1, rawValue.get(1)); + assertThat((Object) rawValue.size()).isEqualTo(2); + assertThat(rawValue.get(0)).isEqualTo(KEY1A + " = " + VALUE1); + assertThat(rawValue.get(1)).isEqualTo(VALUE1); } @Test - public void testEntrySetValue() throws Exception { + void entrySetValue() throws Exception { properties.put(KEY1, VALUE1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -303,12 +301,12 @@ public void testEntrySetValue() throws Exception { properties = new MavenProperties(); properties.load(new ByteArrayInputStream(baos.toByteArray())); Object o22 = properties.get(KEY1); - assertEquals(VALUE1, o22); + assertThat(o22).isEqualTo(VALUE1); for (Map.Entry entry : properties.entrySet()) { entry.setValue(entry.getValue() + "x"); } Object o21 = properties.get(KEY1); - assertEquals(VALUE1 + "x", o21); + assertThat(o21).isEqualTo(VALUE1 + "x"); baos = new ByteArrayOutputStream(); properties.save(baos); @@ -316,11 +314,11 @@ public void testEntrySetValue() throws Exception { properties = new MavenProperties(); properties.load(new ByteArrayInputStream(baos.toByteArray())); Object o2 = properties.get(KEY1); - assertEquals(VALUE1 + "x", o2); + assertThat(o2).isEqualTo(VALUE1 + "x"); } @Test - public void testMultiValueEscaping() throws IOException { + void multiValueEscaping() throws IOException { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("fruits apple, banana, pear, \\"); @@ -330,16 +328,16 @@ public void testMultiValueEscaping() throws IOException { java.util.Properties p = new java.util.Properties(); p.load(new StringReader(sw.toString())); Object o24 = p.getProperty("fruits"); - assertEquals("apple, banana, pear, cantaloupe, watermelon, kiwi, mango", o24); + assertThat(o24).isEqualTo("apple, banana, pear, cantaloupe, watermelon, kiwi, mango"); MavenProperties props = new MavenProperties(); props.load(new StringReader(sw.toString())); Object o23 = props.getProperty("fruits"); - assertEquals("apple, banana, pear, cantaloupe, watermelon, kiwi, mango", o23); + assertThat(o23).isEqualTo("apple, banana, pear, cantaloupe, watermelon, kiwi, mango"); List raw = props.getRaw("fruits"); - assertNotNull(raw); - assertEquals(3, (Object) raw.size()); - assertEquals("fruits apple, banana, pear, ", raw.get(0)); + assertThat(raw).isNotNull(); + assertThat((Object) raw.size()).isEqualTo(3); + assertThat(raw.get(0)).isEqualTo("fruits apple, banana, pear, "); props = new MavenProperties(); props.put( @@ -350,22 +348,22 @@ public void testMultiValueEscaping() throws IOException { " cantaloupe, watermelon, ", " kiwi, mango")); Object o22 = props.getProperty("fruits"); - assertEquals("apple, banana, pear, cantaloupe, watermelon, kiwi, mango", o22); + assertThat(o22).isEqualTo("apple, banana, pear, cantaloupe, watermelon, kiwi, mango"); raw = props.getRaw("fruits"); - assertNotNull(raw); - assertEquals(3, (Object) raw.size()); - assertEquals("fruits apple, banana, pear, ", raw.get(0)); + assertThat(raw).isNotNull(); + assertThat((Object) raw.size()).isEqualTo(3); + assertThat(raw.get(0)).isEqualTo("fruits apple, banana, pear, "); sw = new StringWriter(); props.save(sw); props = new MavenProperties(); props.load(new StringReader(sw.toString())); Object o21 = props.getProperty("fruits"); - assertEquals("apple, banana, pear, cantaloupe, watermelon, kiwi, mango", o21); + assertThat(o21).isEqualTo("apple, banana, pear, cantaloupe, watermelon, kiwi, mango"); raw = props.getRaw("fruits"); - assertNotNull(raw); - assertEquals(3, (Object) raw.size()); - assertEquals("fruits apple, banana, pear, ", raw.get(0)); + assertThat(raw).isNotNull(); + assertThat((Object) raw.size()).isEqualTo(3); + assertThat(raw.get(0)).isEqualTo("fruits apple, banana, pear, "); props = new MavenProperties(); props.put( @@ -376,15 +374,15 @@ public void testMultiValueEscaping() throws IOException { " cantaloupe, watermelon, ", " kiwi, mango")); Object o2 = props.getProperty("fruits"); - assertEquals("apple, banana, pear, cantaloupe, watermelon, kiwi, mango", o2); + assertThat(o2).isEqualTo("apple, banana, pear, cantaloupe, watermelon, kiwi, mango"); raw = props.getRaw("fruits"); - assertNotNull(raw); - assertEquals(3, (Object) raw.size()); - assertEquals("fruits = apple, banana, pear, ", raw.get(0)); + assertThat(raw).isNotNull(); + assertThat((Object) raw.size()).isEqualTo(3); + assertThat(raw.get(0)).isEqualTo("fruits = apple, banana, pear, "); } @Test - public void testUpdate() throws Exception { + void update() throws Exception { MavenProperties p1 = new MavenProperties(); p1.put( "fruits", @@ -404,19 +402,19 @@ public void testUpdate() throws Exception { p2.put("trees", "fir, oak, maple"); p1.update(p2); - assertEquals(2, (Object) p1.size()); + assertThat((Object) p1.size()).isEqualTo(2); Object o23 = p1.getComments("trees"); - assertEquals(List.of("#", "# List of trees", "#"), o23); + assertThat(o23).isEqualTo(List.of("#", "# List of trees", "#")); Object o22 = p1.getProperty("trees"); - assertEquals("fir, oak, maple", o22); + assertThat(o22).isEqualTo("fir, oak, maple"); Object o21 = p1.getComments("fruits"); - assertEquals(List.of("#", "# List of good fruits", "#"), o21); + assertThat(o21).isEqualTo(List.of("#", "# List of good fruits", "#")); Object o2 = p1.getProperty("fruits"); - assertEquals("apple, banana, pear", o2); + assertThat(o2).isEqualTo("apple, banana, pear"); } @Test - public void testSubstitution() throws IOException { + void substitution() throws IOException { String str = "port = 4141" + LINE_SEPARATOR + "host = localhost" + LINE_SEPARATOR + "url = https://${host}:${port}/service" + LINE_SEPARATOR; @@ -426,6 +424,6 @@ public void testSubstitution() throws IOException { StringWriter sw = new StringWriter(); properties.save(sw); Object o2 = sw.toString(); - assertEquals(str, o2); + assertThat(o2).isEqualTo(str); } } diff --git a/compat/maven-embedder/src/test/java/org/apache/maven/cli/transfer/FileSizeFormatTest.java b/compat/maven-embedder/src/test/java/org/apache/maven/cli/transfer/FileSizeFormatTest.java index f13aa48c1294..d4b7fb0db757 100644 --- a/compat/maven-embedder/src/test/java/org/apache/maven/cli/transfer/FileSizeFormatTest.java +++ b/compat/maven-embedder/src/test/java/org/apache/maven/cli/transfer/FileSizeFormatTest.java @@ -21,194 +21,194 @@ import org.apache.maven.cli.transfer.FileSizeFormat.ScaleUnit; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; @Deprecated class FileSizeFormatTest { @Test - void testNegativeSize() { + void negativeSize() { FileSizeFormat format = new FileSizeFormat(); long negativeSize = -100L; - assertThrows(IllegalArgumentException.class, () -> format.format(negativeSize)); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> format.format(negativeSize)); } @Test - void testSize() { + void size() { FileSizeFormat format = new FileSizeFormat(); - assertEquals("0 B", format.format(0L)); - assertEquals("5 B", format.format(5L)); - assertEquals("10 B", format.format(10L)); - assertEquals("15 B", format.format(15L)); - assertEquals("999 B", format.format(999L)); - assertEquals("1.0 kB", format.format(1000L)); - assertEquals("5.5 kB", format.format(5500L)); - assertEquals("10 kB", format.format(10L * 1000L)); - assertEquals("15 kB", format.format(15L * 1000L)); - assertEquals("999 kB", format.format(999L * 1000L)); - assertEquals("1.0 MB", format.format(1000L * 1000L)); - assertEquals("5.5 MB", format.format(5500L * 1000L)); - assertEquals("10 MB", format.format(10L * 1000L * 1000L)); - assertEquals("15 MB", format.format(15L * 1000L * 1000L)); - assertEquals("999 MB", format.format(999L * 1000L * 1000L)); - assertEquals("1.0 GB", format.format(1000L * 1000L * 1000L)); - assertEquals("5.5 GB", format.format(5500L * 1000L * 1000L)); - assertEquals("10 GB", format.format(10L * 1000L * 1000L * 1000L)); - assertEquals("15 GB", format.format(15L * 1000L * 1000L * 1000L)); - assertEquals("1000 GB", format.format(1000L * 1000L * 1000L * 1000L)); + assertThat(format.format(0L)).isEqualTo("0 B"); + assertThat(format.format(5L)).isEqualTo("5 B"); + assertThat(format.format(10L)).isEqualTo("10 B"); + assertThat(format.format(15L)).isEqualTo("15 B"); + assertThat(format.format(999L)).isEqualTo("999 B"); + assertThat(format.format(1000L)).isEqualTo("1.0 kB"); + assertThat(format.format(5500L)).isEqualTo("5.5 kB"); + assertThat(format.format(10L * 1000L)).isEqualTo("10 kB"); + assertThat(format.format(15L * 1000L)).isEqualTo("15 kB"); + assertThat(format.format(999L * 1000L)).isEqualTo("999 kB"); + assertThat(format.format(1000L * 1000L)).isEqualTo("1.0 MB"); + assertThat(format.format(5500L * 1000L)).isEqualTo("5.5 MB"); + assertThat(format.format(10L * 1000L * 1000L)).isEqualTo("10 MB"); + assertThat(format.format(15L * 1000L * 1000L)).isEqualTo("15 MB"); + assertThat(format.format(999L * 1000L * 1000L)).isEqualTo("999 MB"); + assertThat(format.format(1000L * 1000L * 1000L)).isEqualTo("1.0 GB"); + assertThat(format.format(5500L * 1000L * 1000L)).isEqualTo("5.5 GB"); + assertThat(format.format(10L * 1000L * 1000L * 1000L)).isEqualTo("10 GB"); + assertThat(format.format(15L * 1000L * 1000L * 1000L)).isEqualTo("15 GB"); + assertThat(format.format(1000L * 1000L * 1000L * 1000L)).isEqualTo("1000 GB"); } @Test - void testSizeWithSelectedScaleUnit() { + void sizeWithSelectedScaleUnit() { FileSizeFormat format = new FileSizeFormat(); - assertEquals("0 B", format.format(0L)); - assertEquals("0 B", format.format(0L, ScaleUnit.BYTE)); - assertEquals("0 kB", format.format(0L, ScaleUnit.KILOBYTE)); - assertEquals("0 MB", format.format(0L, ScaleUnit.MEGABYTE)); - assertEquals("0 GB", format.format(0L, ScaleUnit.GIGABYTE)); - - assertEquals("5 B", format.format(5L)); - assertEquals("5 B", format.format(5L, ScaleUnit.BYTE)); - assertEquals("0 kB", format.format(5L, ScaleUnit.KILOBYTE)); - assertEquals("0 MB", format.format(5L, ScaleUnit.MEGABYTE)); - assertEquals("0 GB", format.format(5L, ScaleUnit.GIGABYTE)); - - assertEquals("49 B", format.format(49L)); - assertEquals("49 B", format.format(49L, ScaleUnit.BYTE)); - assertEquals("0 kB", format.format(49L, ScaleUnit.KILOBYTE)); - assertEquals("0 MB", format.format(49L, ScaleUnit.MEGABYTE)); - assertEquals("0 GB", format.format(49L, ScaleUnit.GIGABYTE)); - - assertEquals("50 B", format.format(50L)); - assertEquals("50 B", format.format(50L, ScaleUnit.BYTE)); - assertEquals("0.1 kB", format.format(50L, ScaleUnit.KILOBYTE)); - assertEquals("0 MB", format.format(50L, ScaleUnit.MEGABYTE)); - assertEquals("0 GB", format.format(50L, ScaleUnit.GIGABYTE)); - - assertEquals("999 B", format.format(999L)); - assertEquals("999 B", format.format(999L, ScaleUnit.BYTE)); - assertEquals("1.0 kB", format.format(999L, ScaleUnit.KILOBYTE)); - assertEquals("0 MB", format.format(999L, ScaleUnit.MEGABYTE)); - assertEquals("0 GB", format.format(999L, ScaleUnit.GIGABYTE)); - - assertEquals("1.0 kB", format.format(1000L)); - assertEquals("1000 B", format.format(1000L, ScaleUnit.BYTE)); - assertEquals("1.0 kB", format.format(1000L, ScaleUnit.KILOBYTE)); - assertEquals("0 MB", format.format(1000L, ScaleUnit.MEGABYTE)); - assertEquals("0 GB", format.format(1000L, ScaleUnit.GIGABYTE)); - - assertEquals("49 kB", format.format(49L * 1000L)); - assertEquals("49000 B", format.format(49L * 1000L, ScaleUnit.BYTE)); - assertEquals("49 kB", format.format(49L * 1000L, ScaleUnit.KILOBYTE)); - assertEquals("0 MB", format.format(49L * 1000L, ScaleUnit.MEGABYTE)); - assertEquals("0 GB", format.format(49L * 1000L, ScaleUnit.GIGABYTE)); - - assertEquals("50 kB", format.format(50L * 1000L)); - assertEquals("50000 B", format.format(50L * 1000L, ScaleUnit.BYTE)); - assertEquals("50 kB", format.format(50L * 1000L, ScaleUnit.KILOBYTE)); - assertEquals("0.1 MB", format.format(50L * 1000L, ScaleUnit.MEGABYTE)); - assertEquals("0 GB", format.format(50L * 1000L, ScaleUnit.GIGABYTE)); - - assertEquals("999 kB", format.format(999L * 1000L)); - assertEquals("999000 B", format.format(999L * 1000L, ScaleUnit.BYTE)); - assertEquals("999 kB", format.format(999L * 1000L, ScaleUnit.KILOBYTE)); - assertEquals("1.0 MB", format.format(999L * 1000L, ScaleUnit.MEGABYTE)); - assertEquals("0 GB", format.format(999L * 1000L, ScaleUnit.GIGABYTE)); - - assertEquals("1.0 MB", format.format(1000L * 1000L)); - assertEquals("1000000 B", format.format(1000L * 1000L, ScaleUnit.BYTE)); - assertEquals("1000 kB", format.format(1000L * 1000L, ScaleUnit.KILOBYTE)); - assertEquals("1.0 MB", format.format(1000L * 1000L, ScaleUnit.MEGABYTE)); - assertEquals("0 GB", format.format(1000L * 1000L, ScaleUnit.GIGABYTE)); - - assertEquals("49 MB", format.format(49L * 1000L * 1000L)); - assertEquals("49000000 B", format.format(49L * 1000L * 1000L, ScaleUnit.BYTE)); - assertEquals("49000 kB", format.format(49L * 1000L * 1000L, ScaleUnit.KILOBYTE)); - assertEquals("49 MB", format.format(49L * 1000L * 1000L, ScaleUnit.MEGABYTE)); - assertEquals("0 GB", format.format(49L * 1000L * 1000L, ScaleUnit.GIGABYTE)); - - assertEquals("50 MB", format.format(50L * 1000L * 1000L)); - assertEquals("50000000 B", format.format(50L * 1000L * 1000L, ScaleUnit.BYTE)); - assertEquals("50000 kB", format.format(50L * 1000L * 1000L, ScaleUnit.KILOBYTE)); - assertEquals("50 MB", format.format(50L * 1000L * 1000L, ScaleUnit.MEGABYTE)); - assertEquals("0.1 GB", format.format(50L * 1000L * 1000L, ScaleUnit.GIGABYTE)); - - assertEquals("999 MB", format.format(999L * 1000L * 1000L)); - assertEquals("999000000 B", format.format(999L * 1000L * 1000L, ScaleUnit.BYTE)); - assertEquals("999000 kB", format.format(999L * 1000L * 1000L, ScaleUnit.KILOBYTE)); - assertEquals("999 MB", format.format(999L * 1000L * 1000L, ScaleUnit.MEGABYTE)); - assertEquals("1.0 GB", format.format(999L * 1000L * 1000L, ScaleUnit.GIGABYTE)); - - assertEquals("1.0 GB", format.format(1000L * 1000L * 1000L)); - assertEquals("1000000000 B", format.format(1000L * 1000L * 1000L, ScaleUnit.BYTE)); - assertEquals("1000000 kB", format.format(1000L * 1000L * 1000L, ScaleUnit.KILOBYTE)); - assertEquals("1000 MB", format.format(1000L * 1000L * 1000L, ScaleUnit.MEGABYTE)); - assertEquals("1.0 GB", format.format(1000L * 1000L * 1000L, ScaleUnit.GIGABYTE)); + assertThat(format.format(0L)).isEqualTo("0 B"); + assertThat(format.format(0L, ScaleUnit.BYTE)).isEqualTo("0 B"); + assertThat(format.format(0L, ScaleUnit.KILOBYTE)).isEqualTo("0 kB"); + assertThat(format.format(0L, ScaleUnit.MEGABYTE)).isEqualTo("0 MB"); + assertThat(format.format(0L, ScaleUnit.GIGABYTE)).isEqualTo("0 GB"); + + assertThat(format.format(5L)).isEqualTo("5 B"); + assertThat(format.format(5L, ScaleUnit.BYTE)).isEqualTo("5 B"); + assertThat(format.format(5L, ScaleUnit.KILOBYTE)).isEqualTo("0 kB"); + assertThat(format.format(5L, ScaleUnit.MEGABYTE)).isEqualTo("0 MB"); + assertThat(format.format(5L, ScaleUnit.GIGABYTE)).isEqualTo("0 GB"); + + assertThat(format.format(49L)).isEqualTo("49 B"); + assertThat(format.format(49L, ScaleUnit.BYTE)).isEqualTo("49 B"); + assertThat(format.format(49L, ScaleUnit.KILOBYTE)).isEqualTo("0 kB"); + assertThat(format.format(49L, ScaleUnit.MEGABYTE)).isEqualTo("0 MB"); + assertThat(format.format(49L, ScaleUnit.GIGABYTE)).isEqualTo("0 GB"); + + assertThat(format.format(50L)).isEqualTo("50 B"); + assertThat(format.format(50L, ScaleUnit.BYTE)).isEqualTo("50 B"); + assertThat(format.format(50L, ScaleUnit.KILOBYTE)).isEqualTo("0.1 kB"); + assertThat(format.format(50L, ScaleUnit.MEGABYTE)).isEqualTo("0 MB"); + assertThat(format.format(50L, ScaleUnit.GIGABYTE)).isEqualTo("0 GB"); + + assertThat(format.format(999L)).isEqualTo("999 B"); + assertThat(format.format(999L, ScaleUnit.BYTE)).isEqualTo("999 B"); + assertThat(format.format(999L, ScaleUnit.KILOBYTE)).isEqualTo("1.0 kB"); + assertThat(format.format(999L, ScaleUnit.MEGABYTE)).isEqualTo("0 MB"); + assertThat(format.format(999L, ScaleUnit.GIGABYTE)).isEqualTo("0 GB"); + + assertThat(format.format(1000L)).isEqualTo("1.0 kB"); + assertThat(format.format(1000L, ScaleUnit.BYTE)).isEqualTo("1000 B"); + assertThat(format.format(1000L, ScaleUnit.KILOBYTE)).isEqualTo("1.0 kB"); + assertThat(format.format(1000L, ScaleUnit.MEGABYTE)).isEqualTo("0 MB"); + assertThat(format.format(1000L, ScaleUnit.GIGABYTE)).isEqualTo("0 GB"); + + assertThat(format.format(49L * 1000L)).isEqualTo("49 kB"); + assertThat(format.format(49L * 1000L, ScaleUnit.BYTE)).isEqualTo("49000 B"); + assertThat(format.format(49L * 1000L, ScaleUnit.KILOBYTE)).isEqualTo("49 kB"); + assertThat(format.format(49L * 1000L, ScaleUnit.MEGABYTE)).isEqualTo("0 MB"); + assertThat(format.format(49L * 1000L, ScaleUnit.GIGABYTE)).isEqualTo("0 GB"); + + assertThat(format.format(50L * 1000L)).isEqualTo("50 kB"); + assertThat(format.format(50L * 1000L, ScaleUnit.BYTE)).isEqualTo("50000 B"); + assertThat(format.format(50L * 1000L, ScaleUnit.KILOBYTE)).isEqualTo("50 kB"); + assertThat(format.format(50L * 1000L, ScaleUnit.MEGABYTE)).isEqualTo("0.1 MB"); + assertThat(format.format(50L * 1000L, ScaleUnit.GIGABYTE)).isEqualTo("0 GB"); + + assertThat(format.format(999L * 1000L)).isEqualTo("999 kB"); + assertThat(format.format(999L * 1000L, ScaleUnit.BYTE)).isEqualTo("999000 B"); + assertThat(format.format(999L * 1000L, ScaleUnit.KILOBYTE)).isEqualTo("999 kB"); + assertThat(format.format(999L * 1000L, ScaleUnit.MEGABYTE)).isEqualTo("1.0 MB"); + assertThat(format.format(999L * 1000L, ScaleUnit.GIGABYTE)).isEqualTo("0 GB"); + + assertThat(format.format(1000L * 1000L)).isEqualTo("1.0 MB"); + assertThat(format.format(1000L * 1000L, ScaleUnit.BYTE)).isEqualTo("1000000 B"); + assertThat(format.format(1000L * 1000L, ScaleUnit.KILOBYTE)).isEqualTo("1000 kB"); + assertThat(format.format(1000L * 1000L, ScaleUnit.MEGABYTE)).isEqualTo("1.0 MB"); + assertThat(format.format(1000L * 1000L, ScaleUnit.GIGABYTE)).isEqualTo("0 GB"); + + assertThat(format.format(49L * 1000L * 1000L)).isEqualTo("49 MB"); + assertThat(format.format(49L * 1000L * 1000L, ScaleUnit.BYTE)).isEqualTo("49000000 B"); + assertThat(format.format(49L * 1000L * 1000L, ScaleUnit.KILOBYTE)).isEqualTo("49000 kB"); + assertThat(format.format(49L * 1000L * 1000L, ScaleUnit.MEGABYTE)).isEqualTo("49 MB"); + assertThat(format.format(49L * 1000L * 1000L, ScaleUnit.GIGABYTE)).isEqualTo("0 GB"); + + assertThat(format.format(50L * 1000L * 1000L)).isEqualTo("50 MB"); + assertThat(format.format(50L * 1000L * 1000L, ScaleUnit.BYTE)).isEqualTo("50000000 B"); + assertThat(format.format(50L * 1000L * 1000L, ScaleUnit.KILOBYTE)).isEqualTo("50000 kB"); + assertThat(format.format(50L * 1000L * 1000L, ScaleUnit.MEGABYTE)).isEqualTo("50 MB"); + assertThat(format.format(50L * 1000L * 1000L, ScaleUnit.GIGABYTE)).isEqualTo("0.1 GB"); + + assertThat(format.format(999L * 1000L * 1000L)).isEqualTo("999 MB"); + assertThat(format.format(999L * 1000L * 1000L, ScaleUnit.BYTE)).isEqualTo("999000000 B"); + assertThat(format.format(999L * 1000L * 1000L, ScaleUnit.KILOBYTE)).isEqualTo("999000 kB"); + assertThat(format.format(999L * 1000L * 1000L, ScaleUnit.MEGABYTE)).isEqualTo("999 MB"); + assertThat(format.format(999L * 1000L * 1000L, ScaleUnit.GIGABYTE)).isEqualTo("1.0 GB"); + + assertThat(format.format(1000L * 1000L * 1000L)).isEqualTo("1.0 GB"); + assertThat(format.format(1000L * 1000L * 1000L, ScaleUnit.BYTE)).isEqualTo("1000000000 B"); + assertThat(format.format(1000L * 1000L * 1000L, ScaleUnit.KILOBYTE)).isEqualTo("1000000 kB"); + assertThat(format.format(1000L * 1000L * 1000L, ScaleUnit.MEGABYTE)).isEqualTo("1000 MB"); + assertThat(format.format(1000L * 1000L * 1000L, ScaleUnit.GIGABYTE)).isEqualTo("1.0 GB"); } @Test - void testNegativeProgressedSize() { + void negativeProgressedSize() { FileSizeFormat format = new FileSizeFormat(); long negativeProgressedSize = -100L; - assertThrows(IllegalArgumentException.class, () -> format.formatProgress(negativeProgressedSize, 10L)); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> format.formatProgress(negativeProgressedSize, 10L)); } @Test - void testNegativeProgressedSizeBiggerThanSize() { + void negativeProgressedSizeBiggerThanSize() { FileSizeFormat format = new FileSizeFormat(); - assertThrows(IllegalArgumentException.class, () -> format.formatProgress(100L, 10L)); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> format.formatProgress(100L, 10L)); } @Test - void testProgressedSizeWithoutSize() { + void progressedSizeWithoutSize() { FileSizeFormat format = new FileSizeFormat(); - assertEquals("0 B", format.formatProgress(0L, -1L)); - assertEquals("1.0 kB", format.formatProgress(1000L, -1L)); - assertEquals("1.0 MB", format.formatProgress(1000L * 1000L, -1L)); - assertEquals("1.0 GB", format.formatProgress(1000L * 1000L * 1000L, -1L)); + assertThat(format.formatProgress(0L, -1L)).isEqualTo("0 B"); + assertThat(format.formatProgress(1000L, -1L)).isEqualTo("1.0 kB"); + assertThat(format.formatProgress(1000L * 1000L, -1L)).isEqualTo("1.0 MB"); + assertThat(format.formatProgress(1000L * 1000L * 1000L, -1L)).isEqualTo("1.0 GB"); } @Test - void testProgressedBothZero() { + void progressedBothZero() { FileSizeFormat format = new FileSizeFormat(); - assertEquals("0 B", format.formatProgress(0L, 0L)); + assertThat(format.formatProgress(0L, 0L)).isEqualTo("0 B"); } @Test - void testProgressedSizeWithSize() { + void progressedSizeWithSize() { FileSizeFormat format = new FileSizeFormat(); - assertEquals("0/800 B", format.formatProgress(0L, 800L)); - assertEquals("400/800 B", format.formatProgress(400L, 800L)); - assertEquals("800 B", format.formatProgress(800L, 800L)); - - assertEquals("0/8.0 kB", format.formatProgress(0L, 8000L)); - assertEquals("0.4/8.0 kB", format.formatProgress(400L, 8000L)); - assertEquals("4.0/8.0 kB", format.formatProgress(4000L, 8000L)); - assertEquals("8.0 kB", format.formatProgress(8000L, 8000L)); - assertEquals("8.0/50 kB", format.formatProgress(8000L, 50000L)); - assertEquals("16/50 kB", format.formatProgress(16000L, 50000L)); - assertEquals("50 kB", format.formatProgress(50000L, 50000L)); - - assertEquals("0/5.0 MB", format.formatProgress(0L, 5000000L)); - assertEquals("0.5/5.0 MB", format.formatProgress(500000L, 5000000L)); - assertEquals("1.0/5.0 MB", format.formatProgress(1000000L, 5000000L)); - assertEquals("5.0 MB", format.formatProgress(5000000L, 5000000L)); - assertEquals("5.0/15 MB", format.formatProgress(5000000L, 15000000L)); - assertEquals("15 MB", format.formatProgress(15000000L, 15000000L)); - - assertEquals("0/500 MB", format.formatProgress(0L, 500000000L)); - assertEquals("1.0/5.0 GB", format.formatProgress(1000000000L, 5000000000L)); - assertEquals("5.0 GB", format.formatProgress(5000000000L, 5000000000L)); - assertEquals("5.0/15 GB", format.formatProgress(5000000000L, 15000000000L)); - assertEquals("15 GB", format.formatProgress(15000000000L, 15000000000L)); + assertThat(format.formatProgress(0L, 800L)).isEqualTo("0/800 B"); + assertThat(format.formatProgress(400L, 800L)).isEqualTo("400/800 B"); + assertThat(format.formatProgress(800L, 800L)).isEqualTo("800 B"); + + assertThat(format.formatProgress(0L, 8000L)).isEqualTo("0/8.0 kB"); + assertThat(format.formatProgress(400L, 8000L)).isEqualTo("0.4/8.0 kB"); + assertThat(format.formatProgress(4000L, 8000L)).isEqualTo("4.0/8.0 kB"); + assertThat(format.formatProgress(8000L, 8000L)).isEqualTo("8.0 kB"); + assertThat(format.formatProgress(8000L, 50000L)).isEqualTo("8.0/50 kB"); + assertThat(format.formatProgress(16000L, 50000L)).isEqualTo("16/50 kB"); + assertThat(format.formatProgress(50000L, 50000L)).isEqualTo("50 kB"); + + assertThat(format.formatProgress(0L, 5000000L)).isEqualTo("0/5.0 MB"); + assertThat(format.formatProgress(500000L, 5000000L)).isEqualTo("0.5/5.0 MB"); + assertThat(format.formatProgress(1000000L, 5000000L)).isEqualTo("1.0/5.0 MB"); + assertThat(format.formatProgress(5000000L, 5000000L)).isEqualTo("5.0 MB"); + assertThat(format.formatProgress(5000000L, 15000000L)).isEqualTo("5.0/15 MB"); + assertThat(format.formatProgress(15000000L, 15000000L)).isEqualTo("15 MB"); + + assertThat(format.formatProgress(0L, 500000000L)).isEqualTo("0/500 MB"); + assertThat(format.formatProgress(1000000000L, 5000000000L)).isEqualTo("1.0/5.0 GB"); + assertThat(format.formatProgress(5000000000L, 5000000000L)).isEqualTo("5.0 GB"); + assertThat(format.formatProgress(5000000000L, 15000000000L)).isEqualTo("5.0/15 GB"); + assertThat(format.formatProgress(15000000000L, 15000000000L)).isEqualTo("15 GB"); } } diff --git a/compat/maven-embedder/src/test/java/org/apache/maven/cli/transfer/SimplexTransferListenerTest.java b/compat/maven-embedder/src/test/java/org/apache/maven/cli/transfer/SimplexTransferListenerTest.java index 4484be95e9aa..1b3c441af701 100644 --- a/compat/maven-embedder/src/test/java/org/apache/maven/cli/transfer/SimplexTransferListenerTest.java +++ b/compat/maven-embedder/src/test/java/org/apache/maven/cli/transfer/SimplexTransferListenerTest.java @@ -29,7 +29,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; @Deprecated class SimplexTransferListenerTest { @@ -75,9 +75,7 @@ public void transferFailed(TransferEvent event) {} Thread.sleep(500); // to make sure queue is processed, cancellation applied // subsequent call will cancel - assertThrows( - TransferCancelledException.class, - () -> listener.transferStarted(event(session, resource, TransferEvent.EventType.STARTED))); + assertThatExceptionOfType(TransferCancelledException.class).isThrownBy(() -> listener.transferStarted(event(session, resource, TransferEvent.EventType.STARTED))); } @Test diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java index da43f0ca33d5..cccd192253cc 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java @@ -23,9 +23,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; /** */ @@ -37,12 +35,12 @@ private File getPom(String name) { } @Test - void testAndConditionInActivation() throws Exception { + void andConditionInActivation() throws Exception { Properties sysProperties = new Properties(); sysProperties.setProperty("myproperty", "test"); ModelBuilder builder = new DefaultModelBuilderFactory().newInstance(); - assertNotNull(builder); + assertThat(builder).isNotNull(); DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); request.setProcessPlugins(true); @@ -50,9 +48,9 @@ void testAndConditionInActivation() throws Exception { request.setSystemProperties(sysProperties); ModelBuildingResult result = builder.build(request); - assertNotNull(result); - assertNotNull(result.getEffectiveModel()); - assertEquals("activated-1", result.getEffectiveModel().getProperties().get("profile.file")); - assertNull(result.getEffectiveModel().getProperties().get("profile.miss")); + assertThat(result).isNotNull(); + assertThat(result.getEffectiveModel()).isNotNull(); + assertThat(result.getEffectiveModel().getProperties().get("profile.file")).isEqualTo("activated-1"); + assertThat(result.getEffectiveModel().getProperties().get("profile.miss")).isNull(); } } diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderFactoryTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderFactoryTest.java index ecb73cc02955..c0eb8f152755 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderFactoryTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderFactoryTest.java @@ -28,9 +28,7 @@ import org.codehaus.plexus.util.xml.Xpp3Dom; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** */ @@ -45,29 +43,29 @@ private File getPom(String name) { } @Test - void testCompleteWiring() throws Exception { + void completeWiring() throws Exception { ModelBuilder builder = new DefaultModelBuilderFactory().newInstance(); - assertNotNull(builder); + assertThat(builder).isNotNull(); DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); request.setProcessPlugins(true); request.setPomFile(getPom("simple")); ModelBuildingResult result = builder.build(request); - assertNotNull(result); - assertNotNull(result.getEffectiveModel()); - assertEquals("activated", result.getEffectiveModel().getProperties().get("profile.file")); + assertThat(result).isNotNull(); + assertThat(result.getEffectiveModel()).isNotNull(); + assertThat(result.getEffectiveModel().getProperties().get("profile.file")).isEqualTo("activated"); Xpp3Dom conf = (Xpp3Dom) result.getEffectiveModel().getBuild().getPlugins().get(0).getConfiguration(); - assertNotNull(conf); - assertEquals("1.5", conf.getChild("source").getValue()); - assertEquals(" 1.5 ", conf.getChild("target").getValue()); + assertThat(conf).isNotNull(); + assertThat(conf.getChild("source").getValue()).isEqualTo("1.5"); + assertThat(conf.getChild("target").getValue()).isEqualTo(" 1.5 "); } @Test - void testPomChanges() throws Exception { + void pomChanges() throws Exception { ModelBuilder builder = new DefaultModelBuilderFactory().newInstance(); - assertNotNull(builder); + assertThat(builder).isNotNull(); File pom = getPom("simple"); String originalExists = @@ -84,14 +82,14 @@ void testPomChanges() throws Exception { .getFile() .getExists(); - assertEquals(originalExists, resultExists); - assertTrue(result.getEffectiveModel() + assertThat(resultExists).isEqualTo(originalExists); + assertThat(result.getEffectiveModel() .getProfiles() .get(1) .getActivation() .getFile() .getExists() - .contains(BASE_DIR)); + .contains(BASE_DIR)).isTrue(); } private static Model readPom(File file) throws Exception { diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java index 92b45cf465b5..f29977f63bb7 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java @@ -26,13 +26,13 @@ import org.apache.maven.model.resolution.UnresolvableModelException; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; /** */ @Deprecated -public class DefaultModelBuilderTest { +class DefaultModelBuilderTest { private static final String BASE1_ID = "thegroup:base1:pom"; private static final String BASE1_ID2 = "thegroup:base1:1"; @@ -77,15 +77,15 @@ public class DefaultModelBuilderTest { + "\n"; @Test - public void testCycleInImports() throws Exception { + void cycleInImports() throws Exception { ModelBuilder builder = new DefaultModelBuilderFactory().newInstance(); - assertNotNull(builder); + assertThat(builder).isNotNull(); DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); request.setModelSource(new StringModelSource(BASE1)); request.setModelResolver(new CycleInImportsResolver()); - assertThrows(ModelBuildingException.class, () -> builder.build(request)); + assertThatExceptionOfType(ModelBuildingException.class).isThrownBy(() -> builder.build(request)); } static class CycleInImportsResolver extends BaseModelResolver { diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java index a03184de6b83..d2d28d70f92e 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java @@ -24,8 +24,7 @@ import org.codehaus.plexus.util.Os; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assumptions.assumeTrue; /** @@ -39,18 +38,18 @@ class FileModelSourceTest { * Test of equals method, of class FileModelSource. */ @Test - void testEquals() throws Exception { + void equals() throws Exception { File tempFile = createTempFile("pomTest"); FileModelSource instance = new FileModelSource(tempFile); - assertFalse(instance.equals(null)); - assertFalse(instance.equals(new Object())); - assertTrue(instance.equals(instance)); - assertTrue(instance.equals(new FileModelSource(tempFile))); + assertThat(instance).isNotEqualTo(null); + assertThat(new Object()).isNotEqualTo(instance); + assertThat(instance).isEqualTo(instance); + assertThat(new FileModelSource(tempFile)).isEqualTo(instance); } @Test - void testWindowsPaths() throws Exception { + void windowsPaths() throws Exception { assumeTrue(Os.isFamily("Windows")); File upperCaseFile = createTempFile("TESTE"); @@ -60,7 +59,7 @@ void testWindowsPaths() throws Exception { FileModelSource upperCaseFileSource = new FileModelSource(upperCaseFile); FileModelSource lowerCaseFileSource = new FileModelSource(lowerCaseFile); - assertTrue(upperCaseFileSource.equals(lowerCaseFileSource)); + assertThat(lowerCaseFileSource).isEqualTo(upperCaseFileSource); } private File createTempFile(String name) throws IOException { diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/FileToRawModelMergerTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/FileToRawModelMergerTest.java index e5ad5b01d348..3229962b9c89 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/FileToRawModelMergerTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/FileToRawModelMergerTest.java @@ -38,7 +38,7 @@ class FileToRawModelMergerTest { * Ensures that all list-merge methods are overridden */ @Test - void testOverriddenMergeMethods() { + void overriddenMergeMethods() { List methodNames = Stream.of(MavenMerger.class.getDeclaredMethods()) .filter(m -> m.getName().startsWith("merge")) .filter(m -> { diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/GraphTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/GraphTest.java index 6b5178ac2714..58ff1518b922 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/GraphTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/building/GraphTest.java @@ -27,20 +27,20 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; @Deprecated -public class GraphTest { +class GraphTest { @Test - void testCycle() throws Graph.CycleDetectedException { + void cycle() throws Graph.CycleDetectedException { Graph graph = new Graph(); graph.addEdge("a1", "a2"); - assertThrows(Graph.CycleDetectedException.class, () -> graph.addEdge("a2", "a1")); + assertThatExceptionOfType(Graph.CycleDetectedException.class).isThrownBy(() -> graph.addEdge("a2", "a1")); } @Test - public void testPerf() throws IOException { + void perf() throws IOException { List data = new ArrayList<>(); String k = null; for (String line : Files.readAllLines(Paths.get("src/test/resources/dag.txt"))) { diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java index 72d742a13664..30c8b18589bc 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java @@ -30,9 +30,9 @@ import org.junit.jupiter.api.Test; import org.xmlunit.matchers.CompareMatcher; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; /** */ @@ -60,7 +60,7 @@ private Model getModel(String name) throws IOException { } @Test - void testPluginConfiguration() throws Exception { + void pluginConfiguration() throws Exception { testInheritance("plugin-configuration"); } @@ -70,7 +70,7 @@ void testPluginConfiguration() throws Exception { * @throws IOException Model read problem */ @Test - void testUrls() throws Exception { + void urls() throws Exception { testInheritance("urls"); } @@ -79,7 +79,7 @@ void testUrls() throws Exception { * @throws IOException Model read problem */ @Test - void testFlatUrls() throws IOException { + void flatUrls() throws IOException { testInheritance("flat-urls"); } @@ -88,7 +88,7 @@ void testFlatUrls() throws IOException { * @throws Exception */ @Test - void testNoAppendUrls() throws Exception { + void noAppendUrls() throws Exception { testInheritance("no-append-urls"); } @@ -97,7 +97,7 @@ void testNoAppendUrls() throws Exception { * @throws Exception */ @Test - void testNoAppendUrls2() throws Exception { + void noAppendUrls2() throws Exception { testInheritance("no-append-urls2"); } @@ -106,7 +106,7 @@ void testNoAppendUrls2() throws Exception { * @throws Exception */ @Test - void testNoAppendUrls3() throws Exception { + void noAppendUrls3() throws Exception { testInheritance("no-append-urls3"); } @@ -117,7 +117,7 @@ void testNoAppendUrls3() throws Exception { * @throws IOException Model read problem */ @Test - void testFlatTrickyUrls() throws IOException { + void flatTrickyUrls() throws IOException { // parent references child with artifactId (which is not directory name) // then relative path calculation will fail during build from disk but success when calculated from repo try { @@ -126,12 +126,10 @@ void testFlatTrickyUrls() throws IOException { // fail( "should have failed since module reference == artifactId != directory name" ); } catch (AssertionError afe) { // expected failure: wrong relative path calculation - assertTrue( - afe.getMessage() - .contains( - "Expected text value 'http://www.apache.org/path/to/parent/child-artifact-id/' but was " - + "'http://www.apache.org/path/to/parent/../child-artifact-id/'"), - afe.getMessage()); + assertThat(afe.getMessage() + .contains( + "Expected text value 'http://www.apache.org/path/to/parent/child-artifact-id/' but was " + + "'http://www.apache.org/path/to/parent/../child-artifact-id/'")).as(afe.getMessage()).isTrue(); } // but ok from repo: local disk is ignored testInheritance("tricky-flat-artifactId-urls", true); @@ -140,21 +138,16 @@ void testFlatTrickyUrls() throws IOException { // then relative path calculation will success during build from disk but fail when calculated from repo testInheritance("tricky-flat-directory-urls", false); - AssertionError afe = assertThrows( - AssertionError.class, - () -> testInheritance("tricky-flat-directory-urls", true), - "should have failed since module reference == directory name != artifactId"); + AssertionError afe = assertThatExceptionOfType(AssertionError.class).as("should have failed since module reference == directory name != artifactId").isThrownBy(() -> testInheritance("tricky-flat-directory-urls", true)).actual(); // expected failure - assertTrue( - afe.getMessage() - .contains( - "Expected text value 'http://www.apache.org/path/to/parent/../child-artifact-id/' but was " - + "'http://www.apache.org/path/to/parent/child-artifact-id/'"), - afe.getMessage()); + assertThat(afe.getMessage() + .contains( + "Expected text value 'http://www.apache.org/path/to/parent/../child-artifact-id/' but was " + + "'http://www.apache.org/path/to/parent/child-artifact-id/'")).as(afe.getMessage()).isTrue(); } @Test - void testWithEmptyUrl() throws IOException { + void withEmptyUrl() throws IOException { testInheritance("empty-urls", false); } @@ -195,7 +188,7 @@ public void testInheritance(String baseName, boolean fromRepo) throws IOExceptio } @Test - void testModulePathNotArtifactId() throws IOException { + void modulePathNotArtifactId() throws IOException { Model parent = getModel("module-path-not-artifactId-parent"); Model child = getModel("module-path-not-artifactId-child"); diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java index 6d0fa698f193..7c272802273f 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java @@ -39,9 +39,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** */ @@ -57,17 +55,17 @@ public void setUp() { } protected void assertProblemFree(SimpleProblemCollector collector) { - assertEquals(0, collector.getErrors().size(), "Expected no errors"); - assertEquals(0, collector.getWarnings().size(), "Expected no warnings"); - assertEquals(0, collector.getFatals().size(), "Expected no fatals"); + assertThat(collector.getErrors().size()).as("Expected no errors").isEqualTo(0); + assertThat(collector.getWarnings().size()).as("Expected no warnings").isEqualTo(0); + assertThat(collector.getFatals().size()).as("Expected no fatals").isEqualTo(0); } @SuppressWarnings("SameParameterValue") protected void assertCollectorState( int numFatals, int numErrors, int numWarnings, SimpleProblemCollector collector) { - assertEquals(numErrors, collector.getErrors().size(), "Errors"); - assertEquals(numWarnings, collector.getWarnings().size(), "Warnings"); - assertEquals(numFatals, collector.getFatals().size(), "Fatals"); + assertThat(collector.getErrors().size()).as("Errors").isEqualTo(numErrors); + assertThat(collector.getWarnings().size()).as("Warnings").isEqualTo(numWarnings); + assertThat(collector.getFatals().size()).as("Fatals").isEqualTo(numFatals); } private ModelBuildingRequest createModelBuildingRequest(Properties p) { @@ -79,7 +77,7 @@ private ModelBuildingRequest createModelBuildingRequest(Properties p) { } @Test - public void testDefaultBuildTimestampFormatShouldFormatTimeIn24HourFormat() { + public void defaultBuildTimestampFormatShouldFormatTimeIn24HourFormat() { Calendar cal = Calendar.getInstance(); cal.setTimeZone(MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE); cal.set(Calendar.HOUR, 12); @@ -105,12 +103,12 @@ public void testDefaultBuildTimestampFormatShouldFormatTimeIn24HourFormat() { SimpleDateFormat format = new SimpleDateFormat(MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT); format.setTimeZone(MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE); - assertEquals("1976-11-11T00:16:00Z", format.format(firstTestDate)); - assertEquals("1976-11-11T23:16:00Z", format.format(secondTestDate)); + assertThat(format.format(firstTestDate)).isEqualTo("1976-11-11T00:16:00Z"); + assertThat(format.format(secondTestDate)).isEqualTo("1976-11-11T23:16:00Z"); } @Test - public void testDefaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover() { + public void defaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover() { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("Europe/Berlin")); @@ -129,12 +127,12 @@ public void testDefaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover() { SimpleDateFormat format = new SimpleDateFormat(MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT); format.setTimeZone(MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE); - assertEquals("2014-06-15T23:16:00Z", format.format(firstTestDate)); - assertEquals("2014-11-16T00:16:00Z", format.format(secondTestDate)); + assertThat(format.format(firstTestDate)).isEqualTo("2014-06-15T23:16:00Z"); + assertThat(format.format(secondTestDate)).isEqualTo("2014-11-16T00:16:00Z"); } @Test - public void testShouldNotThrowExceptionOnReferenceToNonExistentValue() throws Exception { + public void shouldNotThrowExceptionOnReferenceToNonExistentValue() throws Exception { Model model = new Model(org.apache.maven.api.model.Model.newBuilder() .scm(org.apache.maven.api.model.Scm.newBuilder() .connection("${test}/somepath") @@ -147,11 +145,11 @@ public void testShouldNotThrowExceptionOnReferenceToNonExistentValue() throws Ex Model out = interpolator.interpolateModel(model, new File("."), createModelBuildingRequest(context), collector); assertProblemFree(collector); - assertEquals("${test}/somepath", out.getScm().getConnection()); + assertThat(out.getScm().getConnection()).isEqualTo("${test}/somepath"); } @Test - public void testShouldThrowExceptionOnRecursiveScmConnectionReference() throws Exception { + public void shouldThrowExceptionOnRecursiveScmConnectionReference() throws Exception { var model = new Model(org.apache.maven.api.model.Model.newBuilder() .scm(org.apache.maven.api.model.Scm.newBuilder() .connection("${project.scm.connection}/somepath") @@ -166,7 +164,7 @@ public void testShouldThrowExceptionOnRecursiveScmConnectionReference() throws E } @Test - public void testShouldNotThrowExceptionOnReferenceToValueContainingNakedExpression() throws Exception { + public void shouldNotThrowExceptionOnReferenceToValueContainingNakedExpression() throws Exception { Map props = new HashMap<>(); props.put("test", "test"); Model model = new Model(org.apache.maven.api.model.Model.newBuilder() @@ -183,7 +181,7 @@ public void testShouldNotThrowExceptionOnReferenceToValueContainingNakedExpressi assertProblemFree(collector); - assertEquals("test/somepath", out.getScm().getConnection()); + assertThat(out.getScm().getConnection()).isEqualTo("test/somepath"); } @Test @@ -202,7 +200,7 @@ public void shouldInterpolateOrganizationNameCorrectly() throws Exception { Model out = interpolator.interpolateModel( model, new File("."), createModelBuildingRequest(context), new SimpleProblemCollector()); - assertEquals(orgName + " Tools", out.getName()); + assertThat(out.getName()).isEqualTo(orgName + " Tools"); } @Test @@ -220,11 +218,11 @@ public void shouldInterpolateDependencyVersionToSetSameAsProjectVersion() throws Model out = interpolator.interpolateModel(model, new File("."), createModelBuildingRequest(context), collector); assertCollectorState(0, 0, 0, collector); - assertEquals("3.8.1", (out.getDependencies().get(0)).getVersion()); + assertThat((out.getDependencies().get(0)).getVersion()).isEqualTo("3.8.1"); } @Test - public void testShouldNotInterpolateDependencyVersionWithInvalidReference() throws Exception { + public void shouldNotInterpolateDependencyVersionWithInvalidReference() throws Exception { Model model = new Model(org.apache.maven.api.model.Model.newBuilder() .version("3.8.1") .dependencies(Collections.singletonList(org.apache.maven.api.model.Dependency.newBuilder() @@ -238,11 +236,11 @@ public void testShouldNotInterpolateDependencyVersionWithInvalidReference() thro Model out = interpolator.interpolateModel(model, new File("."), createModelBuildingRequest(context), collector); assertProblemFree(collector); - assertEquals("${something}", (out.getDependencies().get(0)).getVersion()); + assertThat((out.getDependencies().get(0)).getVersion()).isEqualTo("${something}"); } @Test - public void testTwoReferences() throws Exception { + public void twoReferences() throws Exception { Model model = new Model(org.apache.maven.api.model.Model.newBuilder() .version("3.8.1") .artifactId("foo") @@ -257,11 +255,11 @@ public void testTwoReferences() throws Exception { Model out = interpolator.interpolateModel(model, new File("."), createModelBuildingRequest(context), collector); assertCollectorState(0, 0, 0, collector); - assertEquals("foo-3.8.1", (out.getDependencies().get(0)).getVersion()); + assertThat((out.getDependencies().get(0)).getVersion()).isEqualTo("foo-3.8.1"); } @Test - public void testBasedir() throws Exception { + public void basedir() throws Exception { Model model = new Model(org.apache.maven.api.model.Model.newBuilder() .version("3.8.1") .artifactId("foo") @@ -276,12 +274,11 @@ public void testBasedir() throws Exception { Model out = interpolator.interpolateModel(model, null, createModelBuildingRequest(context), collector); assertProblemFree(collector); - assertEquals( - "file://localhost/myBasedir/temp-repo", (out.getRepositories().get(0)).getUrl()); + assertThat((out.getRepositories().get(0)).getUrl()).isEqualTo("file://localhost/myBasedir/temp-repo"); } @Test - public void testBaseUri() throws Exception { + public void baseUri() throws Exception { Model model = new Model(org.apache.maven.api.model.Model.newBuilder() .version("3.8.1") .artifactId("foo") @@ -296,11 +293,11 @@ public void testBaseUri() throws Exception { Model out = interpolator.interpolateModel(model, null, createModelBuildingRequest(context), collector); assertProblemFree(collector); - assertEquals("myBaseUri/temp-repo", (out.getRepositories().get(0)).getUrl()); + assertThat((out.getRepositories().get(0)).getUrl()).isEqualTo("myBaseUri/temp-repo"); } @Test - public void testEnvars() throws Exception { + public void envars() throws Exception { context.put("env.HOME", "/path/to/home"); Map modelProperties = new HashMap<>(); @@ -316,7 +313,7 @@ public void testEnvars() throws Exception { Model out = interpolator.interpolateModel(model, new File("."), createModelBuildingRequest(context), collector); assertProblemFree(collector); - assertEquals("/path/to/home", out.getProperties().get("outputDirectory")); + assertThat(out.getProperties().get("outputDirectory")).isEqualTo("/path/to/home"); } @Test @@ -335,7 +332,7 @@ public void envarExpressionThatEvaluatesToNullReturnsTheLiteralString() throws E Model out = interpolator.interpolateModel(model, new File("."), createModelBuildingRequest(context), collector); assertProblemFree(collector); - assertEquals("${env.DOES_NOT_EXIST}", out.getProperties().get("outputDirectory")); + assertThat(out.getProperties().get("outputDirectory")).isEqualTo("${env.DOES_NOT_EXIST}"); } @Test @@ -353,7 +350,7 @@ public void expressionThatEvaluatesToNullReturnsTheLiteralString() throws Except Model out = interpolator.interpolateModel(model, new File("."), createModelBuildingRequest(context), collector); assertProblemFree(collector); - assertEquals("${DOES_NOT_EXIST}", out.getProperties().get("outputDirectory")); + assertThat(out.getProperties().get("outputDirectory")).isEqualTo("${DOES_NOT_EXIST}"); } @Test @@ -376,7 +373,7 @@ public void shouldInterpolateSourceDirectoryReferencedFromResourceDirectoryCorre List outResources = out.getBuild().getResources(); Iterator resIt = outResources.iterator(); - assertEquals(model.getBuild().getSourceDirectory(), resIt.next().getDirectory()); + assertThat(resIt.next().getDirectory()).isEqualTo(model.getBuild().getSourceDirectory()); } @Test @@ -395,15 +392,13 @@ public void shouldInterpolateUnprefixedBasedirExpression() throws Exception { assertProblemFree(collector); List rDeps = result.getDependencies(); - assertNotNull(rDeps); - assertEquals(1, rDeps.size()); - assertEquals( - new File(basedir, "artifact.jar").getAbsolutePath(), - new File(rDeps.get(0).getSystemPath()).getAbsolutePath()); + assertThat(rDeps).isNotNull(); + assertThat(rDeps.size()).isEqualTo(1); + assertThat(new File(rDeps.get(0).getSystemPath()).getAbsolutePath()).isEqualTo(new File(basedir, "artifact.jar").getAbsolutePath()); } @Test - public void testRecursiveExpressionCycleNPE() throws Exception { + public void recursiveExpressionCycleNPE() throws Exception { Map props = new HashMap<>(); props.put("aa", "${bb}"); props.put("bb", "${aa}"); @@ -417,11 +412,11 @@ public void testRecursiveExpressionCycleNPE() throws Exception { interpolator.interpolateModel(model, null, request, collector); assertCollectorState(0, 2, 0, collector); - assertTrue(collector.getErrors().get(0).contains("Detected the following recursive expression cycle")); + assertThat(collector.getErrors().get(0).contains("Detected the following recursive expression cycle")).isTrue(); } @Test - public void testRecursiveExpressionCycleBaseDir() throws Exception { + public void recursiveExpressionCycleBaseDir() throws Exception { Map props = new HashMap<>(); props.put("basedir", "${basedir}"); DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); @@ -434,9 +429,7 @@ public void testRecursiveExpressionCycleBaseDir() throws Exception { interpolator.interpolateModel(model, null, request, collector); assertCollectorState(0, 1, 0, collector); - assertEquals( - "Resolving expression: '${basedir}': Detected the following recursive expression cycle in 'basedir': [basedir]", - collector.getErrors().get(0)); + assertThat(collector.getErrors().get(0)).isEqualTo("Resolving expression: '${basedir}': Detected the following recursive expression cycle in 'basedir': [basedir]"); } protected abstract ModelInterpolator createInterpolator() throws Exception; diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java index cdc92814af8c..1416fcbd6806 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java @@ -23,16 +23,16 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; @Deprecated class MavenBuildTimestampTest { @Test - void testMavenBuildTimestampUsesUTC() { + void mavenBuildTimestampUsesUTC() { Properties interpolationProperties = new Properties(); interpolationProperties.put("maven.build.timestamp.format", "yyyyMMdd'T'HHmm'Z'"); MavenBuildTimestamp timestamp = new MavenBuildTimestamp(new Date(), interpolationProperties); String formattedTimestamp = timestamp.formattedTimestamp(); - assertTrue(formattedTimestamp.endsWith("Z"), "We expect the UTC marker at the end of the timestamp."); + assertThat(formattedTimestamp.endsWith("Z")).as("We expect the UTC marker at the end of the timestamp.").isTrue(); } } diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/reflection/ReflectionValueExtractorTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/reflection/ReflectionValueExtractorTest.java index 861804ea841d..a4ece86ad957 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/reflection/ReflectionValueExtractorTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/reflection/ReflectionValueExtractorTest.java @@ -42,15 +42,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; /** * ReflectionValueExtractorTest class. */ @Deprecated -public class ReflectionValueExtractorTest { +class ReflectionValueExtractorTest { private Project project; /** @@ -87,26 +85,26 @@ void setUp() { * @throws Exception if any. */ @Test - void testValueExtraction() throws Exception { + void valueExtraction() throws Exception { // ---------------------------------------------------------------------- // Top level values // ---------------------------------------------------------------------- - assertEquals("4.0.0", ReflectionValueExtractor.evaluate("project.modelVersion", project)); + assertThat(ReflectionValueExtractor.evaluate("project.modelVersion", project)).isEqualTo("4.0.0"); - assertEquals("org.apache.maven", ReflectionValueExtractor.evaluate("project.groupId", project)); + assertThat(ReflectionValueExtractor.evaluate("project.groupId", project)).isEqualTo("org.apache.maven"); - assertEquals("maven-core", ReflectionValueExtractor.evaluate("project.artifactId", project)); + assertThat(ReflectionValueExtractor.evaluate("project.artifactId", project)).isEqualTo("maven-core"); - assertEquals("Maven", ReflectionValueExtractor.evaluate("project.name", project)); + assertThat(ReflectionValueExtractor.evaluate("project.name", project)).isEqualTo("Maven"); - assertEquals("2.0-SNAPSHOT", ReflectionValueExtractor.evaluate("project.version", project)); + assertThat(ReflectionValueExtractor.evaluate("project.version", project)).isEqualTo("2.0-SNAPSHOT"); // ---------------------------------------------------------------------- // SCM // ---------------------------------------------------------------------- - assertEquals("scm-connection", ReflectionValueExtractor.evaluate("project.scm.connection", project)); + assertThat(ReflectionValueExtractor.evaluate("project.scm.connection", project)).isEqualTo("scm-connection"); // ---------------------------------------------------------------------- // Dependencies @@ -114,9 +112,9 @@ void testValueExtraction() throws Exception { List dependencies = (List) ReflectionValueExtractor.evaluate("project.dependencies", project); - assertNotNull(dependencies); + assertThat(dependencies).isNotNull(); - assertEquals(2, dependencies.size()); + assertThat(dependencies.size()).isEqualTo(2); // ---------------------------------------------------------------------- // Dependencies - using index notation @@ -125,37 +123,37 @@ void testValueExtraction() throws Exception { // List Dependency dependency = (Dependency) ReflectionValueExtractor.evaluate("project.dependencies[0]", project); - assertNotNull(dependency); + assertThat(dependency).isNotNull(); - assertEquals("dep1", dependency.getArtifactId()); + assertThat(dependency.getArtifactId()).isEqualTo("dep1"); String artifactId = (String) ReflectionValueExtractor.evaluate("project.dependencies[1].artifactId", project); - assertEquals("dep2", artifactId); + assertThat(artifactId).isEqualTo("dep2"); // Array dependency = (Dependency) ReflectionValueExtractor.evaluate("project.dependenciesAsArray[0]", project); - assertNotNull(dependency); + assertThat(dependency).isNotNull(); - assertEquals("dep1", dependency.getArtifactId()); + assertThat(dependency.getArtifactId()).isEqualTo("dep1"); artifactId = (String) ReflectionValueExtractor.evaluate("project.dependenciesAsArray[1].artifactId", project); - assertEquals("dep2", artifactId); + assertThat(artifactId).isEqualTo("dep2"); // Map dependency = (Dependency) ReflectionValueExtractor.evaluate("project.dependenciesAsMap(dep1)", project); - assertNotNull(dependency); + assertThat(dependency).isNotNull(); - assertEquals("dep1", dependency.getArtifactId()); + assertThat(dependency.getArtifactId()).isEqualTo("dep1"); artifactId = (String) ReflectionValueExtractor.evaluate("project.dependenciesAsMap(dep2).artifactId", project); - assertEquals("dep2", artifactId); + assertThat(artifactId).isEqualTo("dep2"); // ---------------------------------------------------------------------- // Build @@ -163,7 +161,7 @@ void testValueExtraction() throws Exception { Build build = (Build) ReflectionValueExtractor.evaluate("project.build", project); - assertNotNull(build); + assertThat(build).isNotNull(); } /** @@ -172,10 +170,10 @@ void testValueExtraction() throws Exception { * @throws Exception if any. */ @Test - public void testValueExtractorWithAInvalidExpression() throws Exception { - assertNull(ReflectionValueExtractor.evaluate("project.foo", project)); - assertNull(ReflectionValueExtractor.evaluate("project.dependencies[10]", project)); - assertNull(ReflectionValueExtractor.evaluate("project.dependencies[0].foo", project)); + void valueExtractorWithAInvalidExpression() throws Exception { + assertThat(ReflectionValueExtractor.evaluate("project.foo", project)).isNull(); + assertThat(ReflectionValueExtractor.evaluate("project.dependencies[10]", project)).isNull(); + assertThat(ReflectionValueExtractor.evaluate("project.dependencies[0].foo", project)).isNull(); } /** @@ -184,11 +182,11 @@ public void testValueExtractorWithAInvalidExpression() throws Exception { * @throws Exception if any. */ @Test - public void testMappedDottedKey() throws Exception { + void mappedDottedKey() throws Exception { Map map = new HashMap(); map.put("a.b", "a.b-value"); - assertEquals("a.b-value", ReflectionValueExtractor.evaluate("h.value(a.b)", new ValueHolder(map))); + assertThat(ReflectionValueExtractor.evaluate("h.value(a.b)", new ValueHolder(map))).isEqualTo("a.b-value"); } /** @@ -197,13 +195,13 @@ public void testMappedDottedKey() throws Exception { * @throws Exception if any. */ @Test - public void testIndexedMapped() throws Exception { + void indexedMapped() throws Exception { Map map = new HashMap(); map.put("a", "a-value"); List list = new ArrayList(); list.add(map); - assertEquals("a-value", ReflectionValueExtractor.evaluate("h.value[0](a)", new ValueHolder(list))); + assertThat(ReflectionValueExtractor.evaluate("h.value[0](a)", new ValueHolder(list))).isEqualTo("a-value"); } /** @@ -212,12 +210,12 @@ public void testIndexedMapped() throws Exception { * @throws Exception if any. */ @Test - public void testMappedIndexed() throws Exception { + void mappedIndexed() throws Exception { List list = new ArrayList(); list.add("a-value"); Map map = new HashMap(); map.put("a", list); - assertEquals("a-value", ReflectionValueExtractor.evaluate("h.value(a)[0]", new ValueHolder(map))); + assertThat(ReflectionValueExtractor.evaluate("h.value(a)[0]", new ValueHolder(map))).isEqualTo("a-value"); } /** @@ -226,10 +224,10 @@ public void testMappedIndexed() throws Exception { * @throws Exception if any. */ @Test - public void testMappedMissingDot() throws Exception { + void mappedMissingDot() throws Exception { Map map = new HashMap(); map.put("a", new ValueHolder("a-value")); - assertNull(ReflectionValueExtractor.evaluate("h.value(a)value", new ValueHolder(map))); + assertThat(ReflectionValueExtractor.evaluate("h.value(a)value", new ValueHolder(map))).isNull(); } /** @@ -238,10 +236,10 @@ public void testMappedMissingDot() throws Exception { * @throws Exception if any. */ @Test - public void testIndexedMissingDot() throws Exception { + void indexedMissingDot() throws Exception { List list = new ArrayList(); list.add(new ValueHolder("a-value")); - assertNull(ReflectionValueExtractor.evaluate("h.value[0]value", new ValueHolder(list))); + assertThat(ReflectionValueExtractor.evaluate("h.value[0]value", new ValueHolder(list))).isNull(); } /** @@ -250,8 +248,8 @@ public void testIndexedMissingDot() throws Exception { * @throws Exception if any. */ @Test - public void testDotDot() throws Exception { - assertNull(ReflectionValueExtractor.evaluate("h..value", new ValueHolder("value"))); + void dotDot() throws Exception { + assertThat(ReflectionValueExtractor.evaluate("h..value", new ValueHolder("value"))).isNull(); } /** @@ -260,17 +258,17 @@ public void testDotDot() throws Exception { * @throws Exception if any. */ @Test - public void testBadIndexedSyntax() throws Exception { + void badIndexedSyntax() throws Exception { List list = new ArrayList(); list.add("a-value"); Object value = new ValueHolder(list); - assertNull(ReflectionValueExtractor.evaluate("h.value[", value)); - assertNull(ReflectionValueExtractor.evaluate("h.value[]", value)); - assertNull(ReflectionValueExtractor.evaluate("h.value[a]", value)); - assertNull(ReflectionValueExtractor.evaluate("h.value[0", value)); - assertNull(ReflectionValueExtractor.evaluate("h.value[0)", value)); - assertNull(ReflectionValueExtractor.evaluate("h.value[-1]", value)); + assertThat(ReflectionValueExtractor.evaluate("h.value[", value)).isNull(); + assertThat(ReflectionValueExtractor.evaluate("h.value[]", value)).isNull(); + assertThat(ReflectionValueExtractor.evaluate("h.value[a]", value)).isNull(); + assertThat(ReflectionValueExtractor.evaluate("h.value[0", value)).isNull(); + assertThat(ReflectionValueExtractor.evaluate("h.value[0)", value)).isNull(); + assertThat(ReflectionValueExtractor.evaluate("h.value[-1]", value)).isNull(); } /** @@ -279,15 +277,15 @@ public void testBadIndexedSyntax() throws Exception { * @throws Exception if any. */ @Test - public void testBadMappedSyntax() throws Exception { + void badMappedSyntax() throws Exception { Map map = new HashMap(); map.put("a", "a-value"); Object value = new ValueHolder(map); - assertNull(ReflectionValueExtractor.evaluate("h.value(", value)); - assertNull(ReflectionValueExtractor.evaluate("h.value()", value)); - assertNull(ReflectionValueExtractor.evaluate("h.value(a", value)); - assertNull(ReflectionValueExtractor.evaluate("h.value(a]", value)); + assertThat(ReflectionValueExtractor.evaluate("h.value(", value)).isNull(); + assertThat(ReflectionValueExtractor.evaluate("h.value()", value)).isNull(); + assertThat(ReflectionValueExtractor.evaluate("h.value(a", value)).isNull(); + assertThat(ReflectionValueExtractor.evaluate("h.value(a]", value)).isNull(); } /** @@ -296,7 +294,7 @@ public void testBadMappedSyntax() throws Exception { * @throws Exception if any. */ @Test - public void testIllegalIndexedType() throws Exception { + void illegalIndexedType() throws Exception { try { ReflectionValueExtractor.evaluate("h.value[1]", new ValueHolder("string")); } catch (Exception e) { @@ -310,7 +308,7 @@ public void testIllegalIndexedType() throws Exception { * @throws Exception if any. */ @Test - public void testIllegalMappedType() throws Exception { + void illegalMappedType() throws Exception { try { ReflectionValueExtractor.evaluate("h.value(key)", new ValueHolder("string")); } catch (Exception e) { @@ -324,8 +322,8 @@ public void testIllegalMappedType() throws Exception { * @throws Exception if any. */ @Test - public void testTrimRootToken() throws Exception { - assertNull(ReflectionValueExtractor.evaluate("project", project, true)); + void trimRootToken() throws Exception { + assertThat(ReflectionValueExtractor.evaluate("project", project, true)).isNull(); } /** @@ -334,18 +332,12 @@ public void testTrimRootToken() throws Exception { * @throws Exception if any. */ @Test - public void testArtifactMap() throws Exception { - assertEquals( - "g0", - ((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g0:a0:c0)", project)).getGroupId()); - assertEquals( - "a1", - ((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g1:a1:c1)", project)) - .getArtifactId()); - assertEquals( - "c2", - ((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g2:a2:c2)", project)) - .getClassifier()); + void artifactMap() throws Exception { + assertThat(((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g0:a0:c0)", project)).getGroupId()).isEqualTo("g0"); + assertThat(((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g1:a1:c1)", project)) + .getArtifactId()).isEqualTo("a1"); + assertThat(((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g2:a2:c2)", project)) + .getClassifier()).isEqualTo("c2"); } public static class Artifact { @@ -566,10 +558,10 @@ public Object getValue() { * @throws Exception if any. */ @Test - public void testRootPropertyRegression() throws Exception { + void rootPropertyRegression() throws Exception { Project project = new Project(); project.setDescription("c:\\\\org\\apache\\test"); Object evalued = ReflectionValueExtractor.evaluate("description", project); - assertNotNull(evalued); + assertThat(evalued).isNotNull(); } } diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java index ed46f67fe923..8bb3d22b6d0d 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java @@ -20,8 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; /** */ @@ -35,47 +34,45 @@ private String normalize(String url) { } @Test - void testNullSafe() { - assertNull(normalize(null)); + void nullSafe() { + assertThat(normalize(null)).isNull(); } @Test - void testTrailingSlash() { - assertEquals("", normalize("")); - assertEquals("http://server.org/dir", normalize("http://server.org/dir")); - assertEquals("http://server.org/dir/", normalize("http://server.org/dir/")); + void trailingSlash() { + assertThat(normalize("")).isEqualTo(""); + assertThat(normalize("http://server.org/dir")).isEqualTo("http://server.org/dir"); + assertThat(normalize("http://server.org/dir/")).isEqualTo("http://server.org/dir/"); } @Test - void testRemovalOfParentRefs() { - assertEquals("http://server.org/child", normalize("http://server.org/parent/../child")); - assertEquals("http://server.org/child", normalize("http://server.org/grand/parent/../../child")); + void removalOfParentRefs() { + assertThat(normalize("http://server.org/parent/../child")).isEqualTo("http://server.org/child"); + assertThat(normalize("http://server.org/grand/parent/../../child")).isEqualTo("http://server.org/child"); - assertEquals("http://server.org//child", normalize("http://server.org/parent/..//child")); - assertEquals("http://server.org/child", normalize("http://server.org/parent//../child")); + assertThat(normalize("http://server.org/parent/..//child")).isEqualTo("http://server.org//child"); + assertThat(normalize("http://server.org/parent//../child")).isEqualTo("http://server.org/child"); } @Test - void testPreservationOfDoubleSlashes() { - assertEquals("scm:hg:ssh://localhost//home/user", normalize("scm:hg:ssh://localhost//home/user")); - assertEquals("file:////UNC/server", normalize("file:////UNC/server")); - assertEquals( - "[fetch=]http://server.org/[push=]ssh://server.org/", - normalize("[fetch=]http://server.org/[push=]ssh://server.org/")); + void preservationOfDoubleSlashes() { + assertThat(normalize("scm:hg:ssh://localhost//home/user")).isEqualTo("scm:hg:ssh://localhost//home/user"); + assertThat(normalize("file:////UNC/server")).isEqualTo("file:////UNC/server"); + assertThat(normalize("[fetch=]http://server.org/[push=]ssh://server.org/")).isEqualTo("[fetch=]http://server.org/[push=]ssh://server.org/"); } @Test void absolutePathTraversalPastRootIsOmitted() { - assertEquals("/", normalize("/../")); + assertThat(normalize("/../")).isEqualTo("/"); } @Test void parentDirectoryRemovedFromRelativeUriReference() { - assertEquals("", normalize("a/../")); + assertThat(normalize("a/../")).isEqualTo(""); } @Test void leadingParentDirectoryNotRemovedFromRelativeUriReference() { - assertEquals("../", normalize("../")); + assertThat(normalize("../")).isEqualTo("../"); } } diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/DefaultProfileSelectorTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/DefaultProfileSelectorTest.java index 84f5d4390aec..bed1e4c55602 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/DefaultProfileSelectorTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/DefaultProfileSelectorTest.java @@ -28,14 +28,13 @@ import org.apache.maven.model.profile.activation.ProfileActivator; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@link DefaultProfileSelector}. */ @Deprecated -public class DefaultProfileSelectorTest { +class DefaultProfileSelectorTest { private Profile newProfile(String id) { Activation activation = new Activation(); Profile profile = new Profile(); @@ -45,7 +44,7 @@ private Profile newProfile(String id) { } @Test - void testThrowingActivator() { + void throwingActivator() { DefaultProfileSelector selector = new DefaultProfileSelector(); selector.addProfileActivator(new ProfileActivator() { @Override @@ -64,10 +63,8 @@ public boolean presentInConfig( DefaultProfileActivationContext context = new DefaultProfileActivationContext(); SimpleProblemCollector problems = new SimpleProblemCollector(); List active = selector.getActiveProfiles(profiles, context, problems); - assertTrue(active.isEmpty()); - assertEquals(1, problems.getErrors().size()); - assertEquals( - "Failed to determine activation for profile one: BOOM", - problems.getErrors().get(0)); + assertThat(active.isEmpty()).isTrue(); + assertThat(problems.getErrors().size()).isEqualTo(1); + assertThat(problems.getErrors().get(0)).isEqualTo("Failed to determine activation for profile one: BOOM"); } } diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java index caf37db2fdfa..4731fc33a980 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java @@ -27,7 +27,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Provides common services to test {@link ProfileActivator} implementations. @@ -55,9 +55,9 @@ protected ProfileActivationContext newContext(final Properties userProperties, f protected void assertActivation(boolean active, Profile profile, ProfileActivationContext context) { SimpleProblemCollector problems = new SimpleProblemCollector(); - assertEquals(active, activator.isActive(new org.apache.maven.model.Profile(profile), context, problems)); + assertThat(activator.isActive(new org.apache.maven.model.Profile(profile), context, problems)).isEqualTo(active); - assertEquals(0, problems.getErrors().size(), problems.getErrors().toString()); - assertEquals(0, problems.getWarnings().size(), problems.getWarnings().toString()); + assertThat(problems.getErrors().size()).as(problems.getErrors().toString()).isEqualTo(0); + assertThat(problems.getWarnings().size()).as(problems.getWarnings().toString()).isEqualTo(0); } } diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java index 35440a15cf65..5b289271904a 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java @@ -34,8 +34,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; /** * Tests {@link FileProfileActivator}. @@ -71,17 +71,15 @@ public Path findRoot(Path basedir) { } @Test - void testRootDirectoryWithNull() { + void rootDirectoryWithNull() { context.setProjectDirectory(null); - IllegalStateException e = assertThrows( - IllegalStateException.class, - () -> assertActivation(false, newExistsProfile("${project.rootDirectory}"), context)); - assertEquals(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE, e.getMessage()); + IllegalStateException e = assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> assertActivation(false, newExistsProfile("${project.rootDirectory}"), context)).actual(); + assertThat(e.getMessage()).isEqualTo(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE); } @Test - void testRootDirectory() { + void rootDirectory() { assertActivation(false, newExistsProfile("${project.rootDirectory}/someFile.txt"), context); assertActivation(true, newMissingProfile("${project.rootDirectory}/someFile.txt"), context); assertActivation(true, newExistsProfile("${project.rootDirectory}"), context); @@ -91,7 +89,7 @@ void testRootDirectory() { } @Test - void testIsActiveNoFileWithShortBasedir() { + void isActiveNoFileWithShortBasedir() { assertActivation(false, newExistsProfile(null), context); assertActivation(false, newExistsProfile("someFile.txt"), context); assertActivation(false, newExistsProfile("${basedir}/someFile.txt"), context); @@ -102,7 +100,7 @@ void testIsActiveNoFileWithShortBasedir() { } @Test - void testIsActiveNoFile() { + void isActiveNoFile() { assertActivation(false, newExistsProfile(null), context); assertActivation(false, newExistsProfile("someFile.txt"), context); assertActivation(false, newExistsProfile("${project.basedir}/someFile.txt"), context); @@ -113,7 +111,7 @@ void testIsActiveNoFile() { } @Test - void testIsActiveExistsFileExists() { + void isActiveExistsFileExists() { assertActivation(true, newExistsProfile("file.txt"), context); assertActivation(true, newExistsProfile("${project.basedir}"), context); assertActivation(true, newExistsProfile("${project.basedir}/" + "file.txt"), context); @@ -124,13 +122,13 @@ void testIsActiveExistsFileExists() { } @Test - void testIsActiveExistsLeavesFileUnchanged() { + void isActiveExistsLeavesFileUnchanged() { Profile profile = newExistsProfile("file.txt"); - assertEquals("file.txt", profile.getActivation().getFile().getExists()); + assertThat(profile.getActivation().getFile().getExists()).isEqualTo("file.txt"); assertActivation(true, profile, context); - assertEquals("file.txt", profile.getActivation().getFile().getExists()); + assertThat(profile.getActivation().getFile().getExists()).isEqualTo("file.txt"); } private Profile newExistsProfile(String filePath) { diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java index 853d5d065fc8..f47523f5cbf0 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java @@ -27,9 +27,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@link JdkVersionProfileActivator}. @@ -59,7 +57,7 @@ private Properties newProperties(String javaVersion) { } @Test - void testNullSafe() throws Exception { + void nullSafe() throws Exception { Profile p = Profile.newInstance(); assertActivation(false, p, newContext(null, null)); @@ -70,7 +68,7 @@ void testNullSafe() throws Exception { } @Test - void testPrefix() throws Exception { + void prefix() throws Exception { Profile profile = newProfile("1.4"); assertActivation(true, profile, newContext(null, newProperties("1.4"))); @@ -84,7 +82,7 @@ void testPrefix() throws Exception { } @Test - void testPrefixNegated() throws Exception { + void prefixNegated() throws Exception { Profile profile = newProfile("!1.4"); assertActivation(false, profile, newContext(null, newProperties("1.4"))); @@ -98,7 +96,7 @@ void testPrefixNegated() throws Exception { } @Test - void testVersionRangeInclusiveBounds() throws Exception { + void versionRangeInclusiveBounds() throws Exception { Profile profile = newProfile("[1.5,1.6]"); assertActivation(false, profile, newContext(null, newProperties("1.4"))); @@ -119,7 +117,7 @@ void testVersionRangeInclusiveBounds() throws Exception { } @Test - void testVersionRangeExclusiveBounds() throws Exception { + void versionRangeExclusiveBounds() throws Exception { Profile profile = newProfile("(1.3,1.6)"); assertActivation(false, profile, newContext(null, newProperties("1.3"))); @@ -141,7 +139,7 @@ void testVersionRangeExclusiveBounds() throws Exception { } @Test - void testVersionRangeInclusiveLowerBound() throws Exception { + void versionRangeInclusiveLowerBound() throws Exception { Profile profile = newProfile("[1.5,)"); assertActivation(false, profile, newContext(null, newProperties("1.4"))); @@ -162,7 +160,7 @@ void testVersionRangeInclusiveLowerBound() throws Exception { } @Test - void testVersionRangeExclusiveUpperBound() throws Exception { + void versionRangeExclusiveUpperBound() throws Exception { Profile profile = newProfile("(,1.6)"); assertActivation(true, profile, newContext(null, newProperties("1.5"))); @@ -178,7 +176,7 @@ void testVersionRangeExclusiveUpperBound() throws Exception { } @Test - void testRubbishJavaVersion() { + void rubbishJavaVersion() { Profile profile = newProfile("[1.8,)"); assertActivationWithProblems(profile, newContext(null, newProperties("Pūteketeke")), "invalid JDK version"); @@ -191,10 +189,10 @@ private void assertActivationWithProblems( Profile profile, ProfileActivationContext context, String warningContains) { SimpleProblemCollector problems = new SimpleProblemCollector(); - assertFalse(activator.isActive(new org.apache.maven.model.Profile(profile), context, problems)); + assertThat(activator.isActive(new org.apache.maven.model.Profile(profile), context, problems)).isFalse(); - assertEquals(0, problems.getErrors().size()); - assertEquals(1, problems.getWarnings().size()); - assertTrue(problems.getWarnings().get(0).contains(warningContains)); + assertThat(problems.getErrors().size()).isEqualTo(0); + assertThat(problems.getWarnings().size()).isEqualTo(1); + assertThat(problems.getWarnings().get(0).contains(warningContains)).isTrue(); } } diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivatorTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivatorTest.java index a7c49c319902..370bb3d52ee6 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivatorTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivatorTest.java @@ -56,7 +56,7 @@ private Properties newProperties(String osName, String osVersion, String osArch) } @Test - void testVersionStringComparison() throws Exception { + void versionStringComparison() throws Exception { Profile profile = newProfile(ActivationOS.newBuilder().version("6.5.0-1014-aws")); assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -66,7 +66,7 @@ void testVersionStringComparison() throws Exception { } @Test - void testVersionRegexMatching() throws Exception { + void versionRegexMatching() throws Exception { Profile profile = newProfile(ActivationOS.newBuilder().version("regex:.*aws")); assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -76,7 +76,7 @@ void testVersionRegexMatching() throws Exception { } @Test - void testName() { + void name() { Profile profile = newProfile(ActivationOS.newBuilder().name("windows")); assertActivation(false, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -84,7 +84,7 @@ void testName() { } @Test - void testNegatedName() { + void negatedName() { Profile profile = newProfile(ActivationOS.newBuilder().name("!windows")); assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -92,7 +92,7 @@ void testNegatedName() { } @Test - void testArch() { + void arch() { Profile profile = newProfile(ActivationOS.newBuilder().arch("amd64")); assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -100,7 +100,7 @@ void testArch() { } @Test - void testNegatedArch() { + void negatedArch() { Profile profile = newProfile(ActivationOS.newBuilder().arch("!amd64")); assertActivation(false, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -108,7 +108,7 @@ void testNegatedArch() { } @Test - void testFamily() { + void family() { Profile profile = newProfile(ActivationOS.newBuilder().family("windows")); assertActivation(false, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -116,7 +116,7 @@ void testFamily() { } @Test - void testNegatedFamily() { + void negatedFamily() { Profile profile = newProfile(ActivationOS.newBuilder().family("!windows")); assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -124,7 +124,7 @@ void testNegatedFamily() { } @Test - void testAllOsConditions() { + void allOsConditions() { Profile profile = newProfile(ActivationOS.newBuilder() .family("windows") .name("windows") @@ -138,7 +138,7 @@ void testAllOsConditions() { } @Test - public void testCapitalOsName() { + void capitalOsName() { Profile profile = newProfile(ActivationOS.newBuilder() .family("Mac") .name("Mac OS X") diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java index d411b3810253..0ee13422eed1 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java @@ -57,7 +57,7 @@ private Properties newProperties(String key, String value) { } @Test - void testNullSafe() throws Exception { + void nullSafe() throws Exception { Profile p = Profile.newInstance(); assertActivation(false, p, newContext(null, null)); @@ -68,7 +68,7 @@ void testNullSafe() throws Exception { } @Test - void testWithNameOnlyUserProperty() throws Exception { + void withNameOnlyUserProperty() throws Exception { Profile profile = newProfile("prop", null); assertActivation(true, profile, newContext(newProperties("prop", "value"), null)); @@ -79,7 +79,7 @@ void testWithNameOnlyUserProperty() throws Exception { } @Test - void testWithNameOnlySystemProperty() throws Exception { + void withNameOnlySystemProperty() throws Exception { Profile profile = newProfile("prop", null); assertActivation(true, profile, newContext(null, newProperties("prop", "value"))); @@ -90,7 +90,7 @@ void testWithNameOnlySystemProperty() throws Exception { } @Test - void testWithNegatedNameOnlyUserProperty() throws Exception { + void withNegatedNameOnlyUserProperty() throws Exception { Profile profile = newProfile("!prop", null); assertActivation(false, profile, newContext(newProperties("prop", "value"), null)); @@ -101,7 +101,7 @@ void testWithNegatedNameOnlyUserProperty() throws Exception { } @Test - void testWithNegatedNameOnlySystemProperty() throws Exception { + void withNegatedNameOnlySystemProperty() throws Exception { Profile profile = newProfile("!prop", null); assertActivation(false, profile, newContext(null, newProperties("prop", "value"))); @@ -112,7 +112,7 @@ void testWithNegatedNameOnlySystemProperty() throws Exception { } @Test - void testWithValueUserProperty() throws Exception { + void withValueUserProperty() throws Exception { Profile profile = newProfile("prop", "value"); assertActivation(true, profile, newContext(newProperties("prop", "value"), null)); @@ -123,7 +123,7 @@ void testWithValueUserProperty() throws Exception { } @Test - void testWithValueSystemProperty() throws Exception { + void withValueSystemProperty() throws Exception { Profile profile = newProfile("prop", "value"); assertActivation(true, profile, newContext(null, newProperties("prop", "value"))); @@ -134,7 +134,7 @@ void testWithValueSystemProperty() throws Exception { } @Test - void testWithNegatedValueUserProperty() throws Exception { + void withNegatedValueUserProperty() throws Exception { Profile profile = newProfile("prop", "!value"); assertActivation(false, profile, newContext(newProperties("prop", "value"), null)); @@ -145,7 +145,7 @@ void testWithNegatedValueUserProperty() throws Exception { } @Test - void testWithNegatedValueSystemProperty() throws Exception { + void withNegatedValueSystemProperty() throws Exception { Profile profile = newProfile("prop", "!value"); assertActivation(false, profile, newContext(null, newProperties("prop", "value"))); @@ -156,7 +156,7 @@ void testWithNegatedValueSystemProperty() throws Exception { } @Test - void testWithValueUserPropertyDominantOverSystemProperty() throws Exception { + void withValueUserPropertyDominantOverSystemProperty() throws Exception { Profile profile = newProfile("prop", "value"); Properties props1 = newProperties("prop", "value"); diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java index cdfa9caac1a5..119304088def 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java @@ -34,9 +34,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** */ @@ -48,7 +46,7 @@ class DefaultModelValidatorTest { private Model read(String pom) throws Exception { String resource = "/poms/validation/" + pom; try (InputStream is = getClass().getResourceAsStream(resource)) { - assertNotNull(is, "missing resource: " + resource); + assertThat(is).as("missing resource: " + resource).isNotNull(); return new Model(new MavenStaxReader().read(is)); } } @@ -96,7 +94,7 @@ private SimpleProblemCollector validateRaw(String pom, UnaryOperator messages = result.getErrors(); - assertTrue(messages.contains("'modelVersion' is missing.")); - assertTrue(messages.contains("'groupId' is missing.")); - assertTrue(messages.contains("'artifactId' is missing.")); - assertTrue(messages.contains("'version' is missing.")); + assertThat(messages.contains("'modelVersion' is missing.")).isTrue(); + assertThat(messages.contains("'groupId' is missing.")).isTrue(); + assertThat(messages.contains("'artifactId' is missing.")).isTrue(); + assertThat(messages.contains("'version' is missing.")).isTrue(); // type is inherited from the super pom } @Test - void testMissingPluginArtifactId() throws Exception { + void missingPluginArtifactId() throws Exception { SimpleProblemCollector result = validate("missing-plugin-artifactId-pom.xml"); assertViolations(result, 0, 1, 0); - assertEquals( - "'build.plugins.plugin.artifactId' is missing.", - result.getErrors().get(0)); + assertThat(result.getErrors().get(0)).isEqualTo("'build.plugins.plugin.artifactId' is missing."); } @Test - void testEmptyPluginVersion() throws Exception { + void emptyPluginVersion() throws Exception { SimpleProblemCollector result = validate("empty-plugin-version.xml"); assertViolations(result, 0, 1, 0); - assertEquals( - "'build.plugins.plugin.version' for org.apache.maven.plugins:maven-it-plugin" - + " must be a valid version but is ''.", - result.getErrors().get(0)); + assertThat(result.getErrors().get(0)).isEqualTo("'build.plugins.plugin.version' for org.apache.maven.plugins:maven-it-plugin" + + " must be a valid version but is ''."); } @Test - void testMissingRepositoryId() throws Exception { + void missingRepositoryId() throws Exception { SimpleProblemCollector result = validateRaw("missing-repository-id-pom.xml", ModelBuildingRequest.VALIDATION_LEVEL_STRICT); assertViolations(result, 0, 4, 0); - assertEquals( - "'repositories.repository.id' is missing.", result.getErrors().get(0)); + assertThat(result.getErrors().get(0)).isEqualTo("'repositories.repository.id' is missing."); - assertEquals( - "'repositories.repository.[null].url' is missing.", - result.getErrors().get(1)); + assertThat(result.getErrors().get(1)).isEqualTo("'repositories.repository.[null].url' is missing."); - assertEquals( - "'pluginRepositories.pluginRepository.id' is missing.", - result.getErrors().get(2)); + assertThat(result.getErrors().get(2)).isEqualTo("'pluginRepositories.pluginRepository.id' is missing."); - assertEquals( - "'pluginRepositories.pluginRepository.[null].url' is missing.", - result.getErrors().get(3)); + assertThat(result.getErrors().get(3)).isEqualTo("'pluginRepositories.pluginRepository.[null].url' is missing."); } @Test - void testMissingResourceDirectory() throws Exception { + void missingResourceDirectory() throws Exception { SimpleProblemCollector result = validate("missing-resource-directory-pom.xml"); assertViolations(result, 0, 2, 0); - assertEquals( - "'build.resources.resource.directory' is missing.", - result.getErrors().get(0)); + assertThat(result.getErrors().get(0)).isEqualTo("'build.resources.resource.directory' is missing."); - assertEquals( - "'build.testResources.testResource.directory' is missing.", - result.getErrors().get(1)); + assertThat(result.getErrors().get(1)).isEqualTo("'build.testResources.testResource.directory' is missing."); } @Test - void testBadPluginDependencyScope() throws Exception { + void badPluginDependencyScope() throws Exception { SimpleProblemCollector result = validate("bad-plugin-dependency-scope.xml"); assertViolations(result, 0, 3, 0); - assertTrue(result.getErrors().get(0).contains("test:d")); + assertThat(result.getErrors().get(0).contains("test:d")).isTrue(); - assertTrue(result.getErrors().get(1).contains("test:e")); + assertThat(result.getErrors().get(1).contains("test:e")).isTrue(); - assertTrue(result.getErrors().get(2).contains("test:f")); + assertThat(result.getErrors().get(2).contains("test:f")).isTrue(); } @Test - void testBadDependencyScope() throws Exception { + void badDependencyScope() throws Exception { SimpleProblemCollector result = validate("bad-dependency-scope.xml"); assertViolations(result, 0, 0, 2); - assertTrue(result.getWarnings().get(0).contains("test:f")); + assertThat(result.getWarnings().get(0).contains("test:f")).isTrue(); - assertTrue(result.getWarnings().get(1).contains("test:g")); + assertThat(result.getWarnings().get(1).contains("test:g")).isTrue(); } @Test - void testBadDependencyManagementScope() throws Exception { + void badDependencyManagementScope() throws Exception { SimpleProblemCollector result = validate("bad-dependency-management-scope.xml"); assertViolations(result, 0, 0, 1); @@ -369,7 +348,7 @@ void testBadDependencyManagementScope() throws Exception { } @Test - void testBadDependencyVersion() throws Exception { + void badDependencyVersion() throws Exception { SimpleProblemCollector result = validate("bad-dependency-version.xml"); assertViolations(result, 0, 2, 0); @@ -382,25 +361,25 @@ void testBadDependencyVersion() throws Exception { } @Test - void testDuplicateModule() throws Exception { + void duplicateModule() throws Exception { SimpleProblemCollector result = validate("duplicate-module.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("child")); + assertThat(result.getErrors().get(0).contains("child")).isTrue(); } @Test - void testDuplicateProfileId() throws Exception { + void duplicateProfileId() throws Exception { SimpleProblemCollector result = validateRaw("duplicate-profile-id.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("non-unique-id")); + assertThat(result.getErrors().get(0).contains("non-unique-id")).isTrue(); } @Test - void testBadPluginVersion() throws Exception { + void badPluginVersion() throws Exception { SimpleProblemCollector result = validate("bad-plugin-version.xml"); assertViolations(result, 0, 4, 0); @@ -417,26 +396,26 @@ void testBadPluginVersion() throws Exception { } @Test - void testDistributionManagementStatus() throws Exception { + void distributionManagementStatus() throws Exception { SimpleProblemCollector result = validate("distribution-management-status.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("distributionManagement.status")); + assertThat(result.getErrors().get(0).contains("distributionManagement.status")).isTrue(); } @Test - void testIncompleteParent() throws Exception { + void incompleteParent() throws Exception { SimpleProblemCollector result = validateRaw("incomplete-parent.xml"); assertViolations(result, 3, 0, 0); - assertTrue(result.getFatals().get(0).contains("parent.groupId")); - assertTrue(result.getFatals().get(1).contains("parent.artifactId")); - assertTrue(result.getFatals().get(2).contains("parent.version")); + assertThat(result.getFatals().get(0).contains("parent.groupId")).isTrue(); + assertThat(result.getFatals().get(1).contains("parent.artifactId")).isTrue(); + assertThat(result.getFatals().get(2).contains("parent.version")).isTrue(); } @Test - void testHardCodedSystemPath() throws Exception { + void hardCodedSystemPath() throws Exception { SimpleProblemCollector result = validateRaw("hard-coded-system-path.xml"); assertViolations(result, 0, 0, 1); @@ -464,28 +443,28 @@ void testHardCodedSystemPath() throws Exception { } @Test - void testEmptyModule() throws Exception { + void emptyModule() throws Exception { SimpleProblemCollector result = validate("empty-module.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("'modules.module[0]' has been specified without a path")); + assertThat(result.getErrors().get(0).contains("'modules.module[0]' has been specified without a path")).isTrue(); } @Test - void testDuplicatePlugin() throws Exception { + void duplicatePlugin() throws Exception { SimpleProblemCollector result = validateRaw("duplicate-plugin.xml"); assertViolations(result, 0, 0, 4); - assertTrue(result.getWarnings().get(0).contains("duplicate declaration of plugin test:duplicate")); - assertTrue(result.getWarnings().get(1).contains("duplicate declaration of plugin test:managed-duplicate")); - assertTrue(result.getWarnings().get(2).contains("duplicate declaration of plugin profile:duplicate")); - assertTrue(result.getWarnings().get(3).contains("duplicate declaration of plugin profile:managed-duplicate")); + assertThat(result.getWarnings().get(0).contains("duplicate declaration of plugin test:duplicate")).isTrue(); + assertThat(result.getWarnings().get(1).contains("duplicate declaration of plugin test:managed-duplicate")).isTrue(); + assertThat(result.getWarnings().get(2).contains("duplicate declaration of plugin profile:duplicate")).isTrue(); + assertThat(result.getWarnings().get(3).contains("duplicate declaration of plugin profile:managed-duplicate")).isTrue(); } @Test - void testDuplicatePluginExecution() throws Exception { + void duplicatePluginExecution() throws Exception { SimpleProblemCollector result = validateRaw("duplicate-plugin-execution.xml"); assertViolations(result, 0, 4, 0); @@ -497,7 +476,7 @@ void testDuplicatePluginExecution() throws Exception { } @Test - void testReservedRepositoryId() throws Exception { + void reservedRepositoryId() throws Exception { SimpleProblemCollector result = validate("reserved-repository-id.xml"); assertViolations(result, 0, 0, 4); @@ -510,43 +489,43 @@ void testReservedRepositoryId() throws Exception { } @Test - void testMissingPluginDependencyGroupId() throws Exception { + void missingPluginDependencyGroupId() throws Exception { SimpleProblemCollector result = validate("missing-plugin-dependency-groupId.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains(":a:")); + assertThat(result.getErrors().get(0).contains(":a:")).isTrue(); } @Test - void testMissingPluginDependencyArtifactId() throws Exception { + void missingPluginDependencyArtifactId() throws Exception { SimpleProblemCollector result = validate("missing-plugin-dependency-artifactId.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("test:")); + assertThat(result.getErrors().get(0).contains("test:")).isTrue(); } @Test - void testMissingPluginDependencyVersion() throws Exception { + void missingPluginDependencyVersion() throws Exception { SimpleProblemCollector result = validate("missing-plugin-dependency-version.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("test:a")); + assertThat(result.getErrors().get(0).contains("test:a")).isTrue(); } @Test - void testBadPluginDependencyVersion() throws Exception { + void badPluginDependencyVersion() throws Exception { SimpleProblemCollector result = validate("bad-plugin-dependency-version.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("test:b")); + assertThat(result.getErrors().get(0).contains("test:b")).isTrue(); } @Test - void testBadVersion() throws Exception { + void badVersion() throws Exception { SimpleProblemCollector result = validate("bad-version.xml"); assertViolations(result, 0, 0, 1); @@ -555,7 +534,7 @@ void testBadVersion() throws Exception { } @Test - void testBadSnapshotVersion() throws Exception { + void badSnapshotVersion() throws Exception { SimpleProblemCollector result = validate("bad-snapshot-version.xml"); assertViolations(result, 0, 0, 1); @@ -564,7 +543,7 @@ void testBadSnapshotVersion() throws Exception { } @Test - void testBadRepositoryId() throws Exception { + void badRepositoryId() throws Exception { SimpleProblemCollector result = validate("bad-repository-id.xml"); assertViolations(result, 0, 0, 4); @@ -583,7 +562,7 @@ void testBadRepositoryId() throws Exception { } @Test - void testBadDependencyExclusionId() throws Exception { + void badDependencyExclusionId() throws Exception { SimpleProblemCollector result = validateEffective("bad-dependency-exclusion-id.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0); @@ -603,7 +582,7 @@ void testBadDependencyExclusionId() throws Exception { } @Test - void testMissingDependencyExclusionId() throws Exception { + void missingDependencyExclusionId() throws Exception { SimpleProblemCollector result = validate("missing-dependency-exclusion-id.xml"); assertViolations(result, 0, 0, 2); @@ -617,7 +596,7 @@ void testMissingDependencyExclusionId() throws Exception { } @Test - void testBadImportScopeType() throws Exception { + void badImportScopeType() throws Exception { SimpleProblemCollector result = validateRaw("bad-import-scope-type.xml"); assertViolations(result, 0, 0, 1); @@ -628,7 +607,7 @@ void testBadImportScopeType() throws Exception { } @Test - void testBadImportScopeClassifier() throws Exception { + void badImportScopeClassifier() throws Exception { SimpleProblemCollector result = validateRaw("bad-import-scope-classifier.xml"); assertViolations(result, 0, 1, 0); @@ -639,7 +618,7 @@ void testBadImportScopeClassifier() throws Exception { } @Test - void testSystemPathRefersToProjectBasedir() throws Exception { + void systemPathRefersToProjectBasedir() throws Exception { SimpleProblemCollector result = validateRaw("basedir-system-path.xml"); assertViolations(result, 0, 0, 2); @@ -671,62 +650,52 @@ void testSystemPathRefersToProjectBasedir() throws Exception { } @Test - void testInvalidVersionInPluginManagement() throws Exception { + void invalidVersionInPluginManagement() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/missing-plugin-version-pluginManagement.xml"); assertViolations(result, 1, 0, 0); - assertEquals( - "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' version of a plugin must be defined. ", - result.getFatals().get(0)); + assertThat(result.getFatals().get(0)).isEqualTo("'build.pluginManagement.plugins.plugin.(groupId:artifactId)' version of a plugin must be defined. "); } @Test - void testInvalidGroupIdInPluginManagement() throws Exception { + void invalidGroupIdInPluginManagement() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/missing-groupId-pluginManagement.xml"); assertViolations(result, 1, 0, 0); - assertEquals( - "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' groupId of a plugin must be defined. ", - result.getFatals().get(0)); + assertThat(result.getFatals().get(0)).isEqualTo("'build.pluginManagement.plugins.plugin.(groupId:artifactId)' groupId of a plugin must be defined. "); } @Test - void testInvalidArtifactIdInPluginManagement() throws Exception { + void invalidArtifactIdInPluginManagement() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/missing-artifactId-pluginManagement.xml"); assertViolations(result, 1, 0, 0); - assertEquals( - "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' artifactId of a plugin must be defined. ", - result.getFatals().get(0)); + assertThat(result.getFatals().get(0)).isEqualTo("'build.pluginManagement.plugins.plugin.(groupId:artifactId)' artifactId of a plugin must be defined. "); } @Test - void testInvalidGroupAndArtifactIdInPluginManagement() throws Exception { + void invalidGroupAndArtifactIdInPluginManagement() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/missing-ga-pluginManagement.xml"); assertViolations(result, 2, 0, 0); - assertEquals( - "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' groupId of a plugin must be defined. ", - result.getFatals().get(0)); + assertThat(result.getFatals().get(0)).isEqualTo("'build.pluginManagement.plugins.plugin.(groupId:artifactId)' groupId of a plugin must be defined. "); - assertEquals( - "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' artifactId of a plugin must be defined. ", - result.getFatals().get(1)); + assertThat(result.getFatals().get(1)).isEqualTo("'build.pluginManagement.plugins.plugin.(groupId:artifactId)' artifactId of a plugin must be defined. "); } @Test - void testMissingReportPluginVersion() throws Exception { + void missingReportPluginVersion() throws Exception { SimpleProblemCollector result = validate("missing-report-version-pom.xml"); assertViolations(result, 0, 0, 0); } @Test - void testDeprecatedDependencyMetaversionsLatestAndRelease() throws Exception { + void deprecatedDependencyMetaversionsLatestAndRelease() throws Exception { SimpleProblemCollector result = validateRaw("deprecated-dependency-metaversions-latest-and-release.xml"); assertViolations(result, 0, 0, 2); @@ -740,90 +709,78 @@ void testDeprecatedDependencyMetaversionsLatestAndRelease() throws Exception { } @Test - void testSelfReferencingDependencyInRawModel() throws Exception { + void selfReferencingDependencyInRawModel() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/self-referencing.xml"); assertViolations(result, 1, 0, 0); - assertEquals( - "'dependencies.dependency[com.example.group:testinvalidpom:0.0.1-SNAPSHOT]' for com.example.group:testinvalidpom:0.0.1-SNAPSHOT is referencing itself.", - result.getFatals().get(0)); + assertThat(result.getFatals().get(0)).isEqualTo("'dependencies.dependency[com.example.group:testinvalidpom:0.0.1-SNAPSHOT]' for com.example.group:testinvalidpom:0.0.1-SNAPSHOT is referencing itself."); } @Test - void testSelfReferencingDependencyWithClassifierInRawModel() throws Exception { + void selfReferencingDependencyWithClassifierInRawModel() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/self-referencing-classifier.xml"); assertViolations(result, 0, 0, 0); } @Test - void testCiFriendlySha1() throws Exception { + void ciFriendlySha1() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/ok-ci-friendly-sha1.xml"); assertViolations(result, 0, 0, 0); } @Test - void testCiFriendlyRevision() throws Exception { + void ciFriendlyRevision() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/ok-ci-friendly-revision.xml"); assertViolations(result, 0, 0, 0); } @Test - void testCiFriendlyChangeList() throws Exception { + void ciFriendlyChangeList() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/ok-ci-friendly-changelist.xml"); assertViolations(result, 0, 0, 0); } @Test - void testCiFriendlyAllExpressions() throws Exception { + void ciFriendlyAllExpressions() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/ok-ci-friendly-all-expressions.xml"); assertViolations(result, 0, 0, 0); } @Test - void testCiFriendlyBad() throws Exception { + void ciFriendlyBad() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/bad-ci-friendly.xml"); assertViolations(result, 0, 0, 1); - assertEquals( - "'version' contains an expression but should be a constant.", - result.getWarnings().get(0)); + assertThat(result.getWarnings().get(0)).isEqualTo("'version' contains an expression but should be a constant."); } @Test - void testCiFriendlyBadSha1Plus() throws Exception { + void ciFriendlyBadSha1Plus() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/bad-ci-friendly-sha1plus.xml"); assertViolations(result, 0, 0, 1); - assertEquals( - "'version' contains an expression but should be a constant.", - result.getWarnings().get(0)); + assertThat(result.getWarnings().get(0)).isEqualTo("'version' contains an expression but should be a constant."); } @Test - void testCiFriendlyBadSha1Plus2() throws Exception { + void ciFriendlyBadSha1Plus2() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/bad-ci-friendly-sha1plus2.xml"); assertViolations(result, 0, 0, 1); - assertEquals( - "'version' contains an expression but should be a constant.", - result.getWarnings().get(0)); + assertThat(result.getWarnings().get(0)).isEqualTo("'version' contains an expression but should be a constant."); } @Test - void testParentVersionLATEST() throws Exception { + void parentVersionLATEST() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/bad-parent-version-latest.xml"); assertViolations(result, 0, 0, 1); - assertEquals( - "'parent.version' is either LATEST or RELEASE (both of them are being deprecated)", - result.getWarnings().get(0)); + assertThat(result.getWarnings().get(0)).isEqualTo("'parent.version' is either LATEST or RELEASE (both of them are being deprecated)"); } @Test - void testParentVersionRELEASE() throws Exception { + void parentVersionRELEASE() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/bad-parent-version-release.xml"); assertViolations(result, 0, 0, 1); - assertEquals( - "'parent.version' is either LATEST or RELEASE (both of them are being deprecated)", - result.getWarnings().get(0)); + assertThat(result.getWarnings().get(0)).isEqualTo("'parent.version' is either LATEST or RELEASE (both of them are being deprecated)"); } @Test @@ -859,17 +816,13 @@ void profileActivationFileWithProjectExpression() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/profile-activation-file-with-project-expressions.xml"); assertViolations(result, 0, 0, 2); - assertEquals( - "'profiles.profile[exists-project-version].activation.file.exists' " - + "Failed to interpolate profile activation property ${project.version}/test.txt: " - + "${project.version} expressions are not supported during profile activation.", - result.getWarnings().get(0)); + assertThat(result.getWarnings().get(0)).isEqualTo("'profiles.profile[exists-project-version].activation.file.exists' " + + "Failed to interpolate profile activation property ${project.version}/test.txt: " + + "${project.version} expressions are not supported during profile activation."); - assertEquals( - "'profiles.profile[missing-project-version].activation.file.missing' " - + "Failed to interpolate profile activation property ${project.version}/test.txt: " - + "${project.version} expressions are not supported during profile activation.", - result.getWarnings().get(1)); + assertThat(result.getWarnings().get(1)).isEqualTo("'profiles.profile[missing-project-version].activation.file.missing' " + + "Failed to interpolate profile activation property ${project.version}/test.txt: " + + "${project.version} expressions are not supported during profile activation."); } @Test @@ -878,16 +831,12 @@ void profileActivationPropertyWithProjectExpression() throws Exception { validateRaw("raw-model/profile-activation-property-with-project-expressions.xml"); assertViolations(result, 0, 0, 2); - assertEquals( - "'profiles.profile[property-name-project-version].activation.property.name' " - + "Failed to interpolate profile activation property ${project.version}: " - + "${project.version} expressions are not supported during profile activation.", - result.getWarnings().get(0)); - - assertEquals( - "'profiles.profile[property-value-project-version].activation.property.value' " - + "Failed to interpolate profile activation property ${project.version}: " - + "${project.version} expressions are not supported during profile activation.", - result.getWarnings().get(1)); + assertThat(result.getWarnings().get(0)).isEqualTo("'profiles.profile[property-name-project-version].activation.property.name' " + + "Failed to interpolate profile activation property ${project.version}: " + + "${project.version} expressions are not supported during profile activation."); + + assertThat(result.getWarnings().get(1)).isEqualTo("'profiles.profile[property-value-project-version].activation.property.value' " + + "Failed to interpolate profile activation property ${project.version}: " + + "${project.version} expressions are not supported during profile activation."); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ActivationFileTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ActivationFileTest.java index 5f5dcd18761b..765c911ddd57 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ActivationFileTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ActivationFileTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code ActivationFile}. @@ -31,25 +29,25 @@ class ActivationFileTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new ActivationFile().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new ActivationFile().equals(null)); + void equalsNullSafe() { + assertThat(new ActivationFile()).isNotEqualTo(null); new ActivationFile().equals(new ActivationFile()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { ActivationFile thing = new ActivationFile(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new ActivationFile().toString()); + void toStringNullSafe() { + assertThat(new ActivationFile().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ActivationOSTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ActivationOSTest.java index 5ca7bec65eb4..d3689514fd2f 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ActivationOSTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ActivationOSTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code ActivationOS}. @@ -31,25 +29,25 @@ class ActivationOSTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new ActivationOS().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new ActivationOS().equals(null)); + void equalsNullSafe() { + assertThat(new ActivationOS()).isNotEqualTo(null); new ActivationOS().equals(new ActivationOS()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { ActivationOS thing = new ActivationOS(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new ActivationOS().toString()); + void toStringNullSafe() { + assertThat(new ActivationOS().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ActivationPropertyTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ActivationPropertyTest.java index 32b69dc04655..d015725ff664 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ActivationPropertyTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ActivationPropertyTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code ActivationProperty}. @@ -31,25 +29,25 @@ class ActivationPropertyTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new ActivationProperty().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new ActivationProperty().equals(null)); + void equalsNullSafe() { + assertThat(new ActivationProperty()).isNotEqualTo(null); new ActivationProperty().equals(new ActivationProperty()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { ActivationProperty thing = new ActivationProperty(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new ActivationProperty().toString()); + void toStringNullSafe() { + assertThat(new ActivationProperty().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ActivationTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ActivationTest.java index 545aab5a788b..aec9a0ddde53 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ActivationTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ActivationTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Activation}. @@ -31,25 +29,25 @@ class ActivationTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Activation().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Activation().equals(null)); + void equalsNullSafe() { + assertThat(new Activation()).isNotEqualTo(null); new Activation().equals(new Activation()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Activation thing = new Activation(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Activation().toString()); + void toStringNullSafe() { + assertThat(new Activation().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/BuildTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/BuildTest.java index bd783149549d..ee94c5998696 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/BuildTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/BuildTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Build}. @@ -31,30 +29,30 @@ class BuildTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Build().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Build().equals(null)); + void equalsNullSafe() { + assertThat(new Build()).isNotEqualTo(null); new Build().equals(new Build()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Build thing = new Build(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Build().toString()); + void toStringNullSafe() { + assertThat(new Build().toString()).isNotNull(); } @Test - public void testToStringNotNonsense() { + void toStringNotNonsense() { Build build = new Build(); String s = build.toString(); diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/CiManagementTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/CiManagementTest.java index 71a402747b79..66256c51a664 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/CiManagementTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/CiManagementTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code CiManagement}. @@ -31,25 +29,25 @@ class CiManagementTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new CiManagement().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new CiManagement().equals(null)); + void equalsNullSafe() { + assertThat(new CiManagement()).isNotEqualTo(null); new CiManagement().equals(new CiManagement()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { CiManagement thing = new CiManagement(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new CiManagement().toString()); + void toStringNullSafe() { + assertThat(new CiManagement().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ContributorTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ContributorTest.java index f6ddcc46994a..b537b60df7db 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ContributorTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ContributorTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Contributor}. @@ -31,25 +29,25 @@ class ContributorTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Contributor().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Contributor().equals(null)); + void equalsNullSafe() { + assertThat(new Contributor()).isNotEqualTo(null); new Contributor().equals(new Contributor()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Contributor thing = new Contributor(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Contributor().toString()); + void toStringNullSafe() { + assertThat(new Contributor().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/DependencyManagementTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/DependencyManagementTest.java index 1a32e0e8e323..46006c059ff1 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/DependencyManagementTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/DependencyManagementTest.java @@ -20,10 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code DependencyManagement}. @@ -32,42 +29,42 @@ class DependencyManagementTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new DependencyManagement().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new DependencyManagement().equals(null)); + void equalsNullSafe() { + assertThat(new DependencyManagement()).isNotEqualTo(null); new DependencyManagement().equals(new DependencyManagement()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { DependencyManagement thing = new DependencyManagement(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new DependencyManagement().toString()); + void toStringNullSafe() { + assertThat(new DependencyManagement().toString()).isNotNull(); } @Test - void testDependencies() { + void dependencies() { DependencyManagement dm = new DependencyManagement(); Dependency d1 = new Dependency(); d1.setGroupId("myGroupId"); - assertNotNull(dm.getDependencies()); - assertEquals(0, dm.getDependencies().size()); + assertThat(dm.getDependencies()).isNotNull(); + assertThat(dm.getDependencies().size()).isEqualTo(0); dm.addDependency(d1); - assertNotNull(dm.getDependencies()); - assertEquals(1, dm.getDependencies().size()); + assertThat(dm.getDependencies()).isNotNull(); + assertThat(dm.getDependencies().size()).isEqualTo(1); dm.getDependencies().get(0).setArtifactId("myArtifactId"); - assertEquals("myArtifactId", dm.getDependencies().get(0).getArtifactId()); + assertThat(dm.getDependencies().get(0).getArtifactId()).isEqualTo("myArtifactId"); dm.setDependencies(null); - assertNotNull(dm.getDependencies()); - assertEquals(0, dm.getDependencies().size()); + assertThat(dm.getDependencies()).isNotNull(); + assertThat(dm.getDependencies().size()).isEqualTo(0); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/DependencyTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/DependencyTest.java index 39d7bb30d78f..bc7c41f9b843 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/DependencyTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/DependencyTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Dependency}. @@ -31,25 +29,25 @@ class DependencyTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Dependency().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Dependency().equals(null)); + void equalsNullSafe() { + assertThat(new Dependency()).isNotEqualTo(null); new Dependency().equals(new Dependency()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Dependency thing = new Dependency(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Dependency().toString()); + void toStringNullSafe() { + assertThat(new Dependency().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/DeploymentRepositoryTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/DeploymentRepositoryTest.java index 8b25cc62639e..8a02ae08d233 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/DeploymentRepositoryTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/DeploymentRepositoryTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code DeploymentRepository}. @@ -31,25 +29,25 @@ class DeploymentRepositoryTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new DeploymentRepository().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new DeploymentRepository().equals(null)); + void equalsNullSafe() { + assertThat(new DeploymentRepository()).isNotEqualTo(null); new DeploymentRepository().equals(new DeploymentRepository()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { DeploymentRepository thing = new DeploymentRepository(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new DeploymentRepository().toString()); + void toStringNullSafe() { + assertThat(new DeploymentRepository().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/DeveloperTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/DeveloperTest.java index b6897aea37e6..9cc7e0277245 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/DeveloperTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/DeveloperTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Developer}. @@ -31,25 +29,25 @@ class DeveloperTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Developer().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Developer().equals(null)); + void equalsNullSafe() { + assertThat(new Developer()).isNotEqualTo(null); new Developer().equals(new Developer()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Developer thing = new Developer(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Developer().toString()); + void toStringNullSafe() { + assertThat(new Developer().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/DistributionManagementTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/DistributionManagementTest.java index 18c57a8c901c..3f55c1ae535d 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/DistributionManagementTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/DistributionManagementTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code DistributionManagement}. @@ -31,25 +29,25 @@ class DistributionManagementTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new DistributionManagement().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new DistributionManagement().equals(null)); + void equalsNullSafe() { + assertThat(new DistributionManagement()).isNotEqualTo(null); new DistributionManagement().equals(new DistributionManagement()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { DistributionManagement thing = new DistributionManagement(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new DistributionManagement().toString()); + void toStringNullSafe() { + assertThat(new DistributionManagement().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ExclusionTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ExclusionTest.java index 625f20ec2c0f..441f0c97e421 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ExclusionTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ExclusionTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Exclusion}. @@ -31,25 +29,25 @@ class ExclusionTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Exclusion().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Exclusion().equals(null)); + void equalsNullSafe() { + assertThat(new Exclusion()).isNotEqualTo(null); new Exclusion().equals(new Exclusion()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Exclusion thing = new Exclusion(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Exclusion().toString()); + void toStringNullSafe() { + assertThat(new Exclusion().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ExtensionTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ExtensionTest.java index 3afa12c8eca7..768e36e41224 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ExtensionTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ExtensionTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Extension}. @@ -31,25 +29,25 @@ class ExtensionTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Extension().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Extension().equals(null)); + void equalsNullSafe() { + assertThat(new Extension()).isNotEqualTo(null); new Extension().equals(new Extension()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Extension thing = new Extension(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Extension().toString()); + void toStringNullSafe() { + assertThat(new Extension().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/IssueManagementTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/IssueManagementTest.java index a6905a28be96..ab96df7556e8 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/IssueManagementTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/IssueManagementTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code IssueManagement}. @@ -31,30 +29,30 @@ class IssueManagementTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new IssueManagement().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new IssueManagement().equals(null)); + void equalsNullSafe() { + assertThat(new IssueManagement()).isNotEqualTo(null); new IssueManagement().equals(new IssueManagement()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { IssueManagement thing = new IssueManagement(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new IssueManagement().toString()); + void toStringNullSafe() { + assertThat(new IssueManagement().toString()).isNotNull(); } @Test - public void testToStringNotNonsense() { + void toStringNotNonsense() { IssueManagement im = new IssueManagement(); im.setSystem("Velociraptor"); im.setUrl("https://velo.localdomain"); diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/LicenseTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/LicenseTest.java index 270993c20b42..95b17c1c1d5d 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/LicenseTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/LicenseTest.java @@ -20,10 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code License}. @@ -32,36 +29,36 @@ class LicenseTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new License().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new License().equals(null)); + void equalsNullSafe() { + assertThat(new License()).isNotEqualTo(null); new License().equals(new License()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { License thing = new License(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new License().toString()); + void toStringNullSafe() { + assertThat(new License().toString()).isNotNull(); } @Test - public void testToStringNotNonsense() { + void toStringNotNonsense() { License license = new License(); license.setName("Unlicense"); license.setUrl("http://lic.localdomain"); String s = license.toString(); - assertEquals("License {name=Unlicense, url=http://lic.localdomain}", s); + assertThat(s).isEqualTo("License {name=Unlicense, url=http://lic.localdomain}"); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/MailingListTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/MailingListTest.java index c758c7e76ef1..904fd982f35e 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/MailingListTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/MailingListTest.java @@ -20,10 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code MailingList}. @@ -32,35 +29,35 @@ class MailingListTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new MailingList().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new MailingList().equals(null)); + void equalsNullSafe() { + assertThat(new MailingList()).isNotEqualTo(null); new MailingList().equals(new MailingList()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { MailingList thing = new MailingList(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new MailingList().toString()); + void toStringNullSafe() { + assertThat(new MailingList().toString()).isNotNull(); } @Test - public void testToStringNotNonsense() { + void toStringNotNonsense() { MailingList list = new MailingList(); list.setName("modello-dev"); String s = list.toString(); - assertEquals("MailingList {name=modello-dev, archive=null}", s); + assertThat(s).isEqualTo("MailingList {name=modello-dev, archive=null}"); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ModelTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ModelTest.java index 2f872a7bf505..810f234ab20b 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ModelTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ModelTest.java @@ -20,10 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Model}. @@ -32,38 +29,38 @@ class ModelTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Model().hashCode(); } @Test - void testBuild() { + void build() { Model model = new Model(); Build build = new Build(); build.setOutputDirectory("myOutputDirectory"); model.setBuild(build); Build build2 = model.getBuild(); - assertNotNull(build2); - assertEquals("myOutputDirectory", build2.getOutputDirectory()); + assertThat(build2).isNotNull(); + assertThat(build2.getOutputDirectory()).isEqualTo("myOutputDirectory"); model.setBuild(null); - assertNull(model.getBuild()); + assertThat(model.getBuild()).isNull(); } @Test - void testEqualsNullSafe() { - assertNotEquals(null, new Model()); + void equalsNullSafe() { + assertThat(new Model()).isNotEqualTo(null); new Model().equals(new Model()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Model thing = new Model(); - assertEquals(thing, thing); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Model().toString()); + void toStringNullSafe() { + assertThat(new Model().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/NotifierTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/NotifierTest.java index 33f1c139d9a4..26b505a76588 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/NotifierTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/NotifierTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Notifier}. @@ -31,25 +29,25 @@ class NotifierTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Notifier().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Notifier().equals(null)); + void equalsNullSafe() { + assertThat(new Notifier()).isNotEqualTo(null); new Notifier().equals(new Notifier()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Notifier thing = new Notifier(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Notifier().toString()); + void toStringNullSafe() { + assertThat(new Notifier().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/OrganizationTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/OrganizationTest.java index 62e51a1608d4..e8381bddabc4 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/OrganizationTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/OrganizationTest.java @@ -20,10 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Organization}. @@ -32,57 +29,57 @@ class OrganizationTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Organization().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Organization().equals(null)); + void equalsNullSafe() { + assertThat(new Organization()).isNotEqualTo(null); new Organization().equals(new Organization()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Organization thing = new Organization(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Organization().toString()); + void toStringNullSafe() { + assertThat(new Organization().toString()).isNotNull(); } @Test - public void testToStringNotNonsense11() { + void toStringNotNonsense11() { Organization org = new Organization(); org.setName("Testing Maven Unit"); org.setUrl("https://maven.localdomain"); - assertEquals("Organization {name=Testing Maven Unit, url=https://maven.localdomain}", org.toString()); + assertThat(org.toString()).isEqualTo("Organization {name=Testing Maven Unit, url=https://maven.localdomain}"); } @Test - public void testToStringNotNonsense10() { + void toStringNotNonsense10() { Organization org = new Organization(); org.setName("Testing Maven Unit"); - assertEquals("Organization {name=Testing Maven Unit, url=null}", org.toString()); + assertThat(org.toString()).isEqualTo("Organization {name=Testing Maven Unit, url=null}"); } @Test - public void testToStringNotNonsense01() { + void toStringNotNonsense01() { Organization org = new Organization(); org.setUrl("https://maven.localdomain"); - assertEquals("Organization {name=null, url=https://maven.localdomain}", org.toString()); + assertThat(org.toString()).isEqualTo("Organization {name=null, url=https://maven.localdomain}"); } @Test - public void testToStringNotNonsense00() { + void toStringNotNonsense00() { Organization org = new Organization(); - assertEquals("Organization {name=null, url=null}", org.toString()); + assertThat(org.toString()).isEqualTo("Organization {name=null, url=null}"); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ParentTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ParentTest.java index 79f33785baf4..ef2ff3cf8c2e 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ParentTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ParentTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Parent}. @@ -31,25 +29,25 @@ class ParentTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Parent().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Parent().equals(null)); + void equalsNullSafe() { + assertThat(new Parent()).isNotEqualTo(null); new Parent().equals(new Parent()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Parent thing = new Parent(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Parent().toString()); + void toStringNullSafe() { + assertThat(new Parent().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/PluginConfigurationTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/PluginConfigurationTest.java index 996bf56bd8fe..3bd528f18de5 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/PluginConfigurationTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/PluginConfigurationTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code PluginConfiguration}. @@ -31,25 +29,25 @@ class PluginConfigurationTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new PluginConfiguration().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new PluginConfiguration().equals(null)); + void equalsNullSafe() { + assertThat(new PluginConfiguration()).isNotEqualTo(null); new PluginConfiguration().equals(new PluginConfiguration()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { PluginConfiguration thing = new PluginConfiguration(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new PluginConfiguration().toString()); + void toStringNullSafe() { + assertThat(new PluginConfiguration().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/PluginContainerTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/PluginContainerTest.java index bc4c61404ed0..9aa7cb1fe1ab 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/PluginContainerTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/PluginContainerTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code PluginContainer}. @@ -31,25 +29,25 @@ class PluginContainerTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new PluginContainer().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new PluginContainer().equals(null)); + void equalsNullSafe() { + assertThat(new PluginContainer()).isNotEqualTo(null); new PluginContainer().equals(new PluginContainer()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { PluginContainer thing = new PluginContainer(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new PluginContainer().toString()); + void toStringNullSafe() { + assertThat(new PluginContainer().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/PluginExecutionTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/PluginExecutionTest.java index 110ed253d7de..0f43149444da 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/PluginExecutionTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/PluginExecutionTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code PluginExecution}. @@ -31,25 +29,25 @@ class PluginExecutionTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new PluginExecution().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new PluginExecution().equals(null)); + void equalsNullSafe() { + assertThat(new PluginExecution()).isNotEqualTo(null); new PluginExecution().equals(new PluginExecution()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { PluginExecution thing = new PluginExecution(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new PluginExecution().toString()); + void toStringNullSafe() { + assertThat(new PluginExecution().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/PluginManagementTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/PluginManagementTest.java index c657890a957a..60643c7aeabb 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/PluginManagementTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/PluginManagementTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code PluginManagement}. @@ -31,25 +29,25 @@ class PluginManagementTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new PluginManagement().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new PluginManagement().equals(null)); + void equalsNullSafe() { + assertThat(new PluginManagement()).isNotEqualTo(null); new PluginManagement().equals(new PluginManagement()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { PluginManagement thing = new PluginManagement(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new PluginManagement().toString()); + void toStringNullSafe() { + assertThat(new PluginManagement().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/PluginTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/PluginTest.java index c023199854a5..adc123664f5f 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/PluginTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/PluginTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Plugin}. @@ -31,25 +29,25 @@ class PluginTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Plugin().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Plugin().equals(null)); + void equalsNullSafe() { + assertThat(new Plugin()).isNotEqualTo(null); new Plugin().equals(new Plugin()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Plugin thing = new Plugin(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Plugin().toString()); + void toStringNullSafe() { + assertThat(new Plugin().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/PrerequisitesTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/PrerequisitesTest.java index c886fd86a3c4..cd9ee0cfcb41 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/PrerequisitesTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/PrerequisitesTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Prerequisites}. @@ -31,25 +29,25 @@ class PrerequisitesTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Prerequisites().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Prerequisites().equals(null)); + void equalsNullSafe() { + assertThat(new Prerequisites()).isNotEqualTo(null); new Prerequisites().equals(new Prerequisites()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Prerequisites thing = new Prerequisites(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Prerequisites().toString()); + void toStringNullSafe() { + assertThat(new Prerequisites().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ProfileTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ProfileTest.java index aa8b0dbc9523..1473b9c9aa42 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ProfileTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ProfileTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Profile}. @@ -31,25 +29,25 @@ class ProfileTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Profile().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Profile().equals(null)); + void equalsNullSafe() { + assertThat(new Profile()).isNotEqualTo(null); new Profile().equals(new Profile()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Profile thing = new Profile(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Profile().toString()); + void toStringNullSafe() { + assertThat(new Profile().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/RelocationTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/RelocationTest.java index 9956b12a92f2..1ca5233eecaf 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/RelocationTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/RelocationTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Relocation}. @@ -31,25 +29,25 @@ class RelocationTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Relocation().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Relocation().equals(null)); + void equalsNullSafe() { + assertThat(new Relocation()).isNotEqualTo(null); new Relocation().equals(new Relocation()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Relocation thing = new Relocation(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Relocation().toString()); + void toStringNullSafe() { + assertThat(new Relocation().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ReportPluginTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ReportPluginTest.java index 37f0acf336f7..3aae0d8d155c 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ReportPluginTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ReportPluginTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code ReportPlugin}. @@ -31,25 +29,25 @@ class ReportPluginTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new ReportPlugin().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new ReportPlugin().equals(null)); + void equalsNullSafe() { + assertThat(new ReportPlugin()).isNotEqualTo(null); new ReportPlugin().equals(new ReportPlugin()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { ReportPlugin thing = new ReportPlugin(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new ReportPlugin().toString()); + void toStringNullSafe() { + assertThat(new ReportPlugin().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ReportSetTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ReportSetTest.java index 7314675b268c..3ddbe231572a 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ReportSetTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ReportSetTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code ReportSet}. @@ -31,25 +29,25 @@ class ReportSetTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new ReportSet().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new ReportSet().equals(null)); + void equalsNullSafe() { + assertThat(new ReportSet()).isNotEqualTo(null); new ReportSet().equals(new ReportSet()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { ReportSet thing = new ReportSet(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new ReportSet().toString()); + void toStringNullSafe() { + assertThat(new ReportSet().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ReportingTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ReportingTest.java index 8d3d7d93acd0..9fa0f28e6b13 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ReportingTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ReportingTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Reporting}. @@ -31,25 +29,25 @@ class ReportingTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Reporting().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Reporting().equals(null)); + void equalsNullSafe() { + assertThat(new Reporting()).isNotEqualTo(null); new Reporting().equals(new Reporting()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Reporting thing = new Reporting(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Reporting().toString()); + void toStringNullSafe() { + assertThat(new Reporting().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/RepositoryPolicyTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/RepositoryPolicyTest.java index 24b9e049a4ab..a476d7a98e02 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/RepositoryPolicyTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/RepositoryPolicyTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code RepositoryPolicy}. @@ -31,25 +29,25 @@ class RepositoryPolicyTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new RepositoryPolicy().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new RepositoryPolicy().equals(null)); + void equalsNullSafe() { + assertThat(new RepositoryPolicy()).isNotEqualTo(null); new RepositoryPolicy().equals(new RepositoryPolicy()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { RepositoryPolicy thing = new RepositoryPolicy(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new RepositoryPolicy().toString()); + void toStringNullSafe() { + assertThat(new RepositoryPolicy().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/RepositoryTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/RepositoryTest.java index afcc13b88db1..c58ccb1acd86 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/RepositoryTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/RepositoryTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Repository}. @@ -31,25 +29,25 @@ class RepositoryTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Repository().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Repository().equals(null)); + void equalsNullSafe() { + assertThat(new Repository()).isNotEqualTo(null); new Repository().equals(new Repository()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Repository thing = new Repository(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Repository().toString()); + void toStringNullSafe() { + assertThat(new Repository().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ResourceTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ResourceTest.java index 7ed52946a6b8..4fa76cd37b69 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ResourceTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ResourceTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Resource}. @@ -31,25 +29,25 @@ class ResourceTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Resource().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Resource().equals(null)); + void equalsNullSafe() { + assertThat(new Resource()).isNotEqualTo(null); new Resource().equals(new Resource()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Resource thing = new Resource(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Resource().toString()); + void toStringNullSafe() { + assertThat(new Resource().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/ScmTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/ScmTest.java index 0dde84e4a9c9..2bcca7f642d4 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/ScmTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/ScmTest.java @@ -20,10 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Scm}. @@ -31,35 +28,35 @@ class ScmTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Scm().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Scm().equals(null)); + void equalsNullSafe() { + assertThat(new Scm()).isNotEqualTo(null); new Scm().equals(new Scm()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Scm thing = new Scm(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Scm().toString()); + void toStringNullSafe() { + assertThat(new Scm().toString()).isNotNull(); } @Test - public void testToStringNotNonsense() { + void toStringNotNonsense() { Scm scm = new Scm(); scm.setConnection("scm:git:git://git.localdomain/model"); String s = scm.toString(); - assertEquals("Scm {connection=scm:git:git://git.localdomain/model}", s); + assertThat(s).isEqualTo("Scm {connection=scm:git:git://git.localdomain/model}"); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/SerializationTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/SerializationTest.java index b2cfd60acc56..4e1012e1dafe 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/SerializationTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/SerializationTest.java @@ -27,12 +27,12 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; class SerializationTest { @Test - void testModelSerialization() throws Exception { + void modelSerialization() throws Exception { Model model; try (InputStream is = getClass().getResourceAsStream("/xml/pom.xml")) { model = new MavenXpp3Reader().read(is); @@ -52,11 +52,11 @@ void testModelSerialization() throws Exception { build2 = (Build) ois.readObject(); } - assertNotNull(build2); + assertThat(build2).isNotNull(); } @Test - void testModelPropertiesAndListSerialization() throws Exception { + void modelPropertiesAndListSerialization() throws Exception { Model model; try (InputStream is = getClass().getResourceAsStream("/xml/pom.xml")) { model = new MavenXpp3Reader().read(is); diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/SiteTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/SiteTest.java index 41565017b30c..1383c3dec04a 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/SiteTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/SiteTest.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@code Site}. @@ -31,25 +29,25 @@ class SiteTest { @Test - void testHashCodeNullSafe() { + void hashCodeNullSafe() { new Site().hashCode(); } @Test - void testEqualsNullSafe() { - assertFalse(new Site().equals(null)); + void equalsNullSafe() { + assertThat(new Site()).isNotEqualTo(null); new Site().equals(new Site()); } @Test - void testEqualsIdentity() { + void equalsIdentity() { Site thing = new Site(); - assertTrue(thing.equals(thing)); + assertThat(thing).isEqualTo(thing); } @Test - void testToStringNullSafe() { - assertNotNull(new Site().toString()); + void toStringNullSafe() { + assertThat(new Site().toString()).isNotNull(); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/v4/MavenModelVersionTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/v4/MavenModelVersionTest.java index 9c3555aefff7..bd7f6544736f 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/v4/MavenModelVersionTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/v4/MavenModelVersionTest.java @@ -28,7 +28,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; class MavenModelVersionTest { @@ -42,34 +42,34 @@ static void setup() throws Exception { } @Test - void testV4Model() { - assertEquals("4.0.0", new MavenModelVersion().getModelVersion(model)); + void v4Model() { + assertThat(new MavenModelVersion().getModelVersion(model)).isEqualTo("4.0.0"); } @Test - void testV4ModelVersion() { + void v4ModelVersion() { Model m = model.withModelVersion("4.1.0"); - assertEquals("4.0.0", new MavenModelVersion().getModelVersion(m)); + assertThat(new MavenModelVersion().getModelVersion(m)).isEqualTo("4.0.0"); } @Test - void testV4ModelRoot() { + void v4ModelRoot() { Model m = model.withRoot(true); - assertEquals("4.1.0", new MavenModelVersion().getModelVersion(m)); + assertThat(new MavenModelVersion().getModelVersion(m)).isEqualTo("4.1.0"); } @Test - void testV4ModelPreserveModelVersion() { + void v4ModelPreserveModelVersion() { Model m = model.withPreserveModelVersion(true); - assertEquals("4.1.0", new MavenModelVersion().getModelVersion(m)); + assertThat(new MavenModelVersion().getModelVersion(m)).isEqualTo("4.1.0"); } @Test - void testV4ModelPriority() { + void v4ModelPriority() { Model m = model.withBuild(Build.newInstance() .withPlugins(Collections.singleton(Plugin.newInstance() .withExecutions(Collections.singleton( PluginExecution.newInstance().withPriority(5)))))); - assertEquals("4.0.0", new MavenModelVersion().getModelVersion(m)); + assertThat(new MavenModelVersion().getModelVersion(m)).isEqualTo("4.0.0"); } } diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/v4/ModelXmlTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/v4/ModelXmlTest.java index b7d17e808d40..2701cbc3cd3d 100644 --- a/compat/maven-model/src/test/java/org/apache/maven/model/v4/ModelXmlTest.java +++ b/compat/maven-model/src/test/java/org/apache/maven/model/v4/ModelXmlTest.java @@ -31,14 +31,12 @@ import org.apache.maven.api.xml.XmlNode; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; class ModelXmlTest { @Test - void testXmlRoundtripWithProperties() throws Exception { + void xmlRoundtripWithProperties() throws Exception { Map props = new LinkedHashMap<>(); props.put("javax.version", "3.1.0"); props.put("mockito.version", "1.10.19"); @@ -50,12 +48,12 @@ void testXmlRoundtripWithProperties() throws Exception { for (int i = 0; i < 10; i++) { String newStr = toXml(fromXml(xml)); - assertEquals(newStr, xml); + assertThat(xml).isEqualTo(newStr); } } @Test - void testNamespaceInXmlNode() throws XMLStreamException { + void namespaceInXmlNode() throws XMLStreamException { String xml = "\n" @@ -73,17 +71,17 @@ void testNamespaceInXmlNode() throws XMLStreamException { Model model = fromXml(xml); Plugin plugin = model.getBuild().getPlugins().get(0); XmlNode node = plugin.getConfiguration(); - assertNotNull(node); - assertEquals("http://maven.apache.org/POM/4.0.0", node.namespaceUri()); - assertEquals("m", node.prefix()); - assertEquals("configuration", node.name()); - assertEquals(1, node.children().size()); + assertThat(node).isNotNull(); + assertThat(node.namespaceUri()).isEqualTo("http://maven.apache.org/POM/4.0.0"); + assertThat(node.prefix()).isEqualTo("m"); + assertThat(node.name()).isEqualTo("configuration"); + assertThat(node.children().size()).isEqualTo(1); XmlNode myConfig = node.children().get(0); - assertEquals("http://fabric8.io/fabric8-maven-plugin", myConfig.namespaceUri()); - assertEquals("", myConfig.prefix()); - assertEquals("myConfig", myConfig.name()); + assertThat(myConfig.namespaceUri()).isEqualTo("http://fabric8.io/fabric8-maven-plugin"); + assertThat(myConfig.prefix()).isEqualTo(""); + assertThat(myConfig.name()).isEqualTo("myConfig"); String config = node.toString(); - assertFalse(config.isEmpty()); + assertThat(config.isEmpty()).isFalse(); } String toXml(Model model) throws IOException, XMLStreamException { diff --git a/compat/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/MojoDescriptorTest.java b/compat/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/MojoDescriptorTest.java index 26cffced5d54..8821dd8bdea1 100644 --- a/compat/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/MojoDescriptorTest.java +++ b/compat/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/MojoDescriptorTest.java @@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; class MojoDescriptorTest { @Test @@ -31,20 +31,16 @@ void getParameterMap() throws DuplicateParameterException { param1.setDefaultValue("value1"); mojoDescriptor.addParameter(param1); - assertEquals(1, mojoDescriptor.getParameters().size()); + assertThat(mojoDescriptor.getParameters().size()).isEqualTo(1); - assertEquals( - mojoDescriptor.getParameters().size(), - mojoDescriptor.getParameterMap().size()); + assertThat(mojoDescriptor.getParameterMap().size()).isEqualTo(mojoDescriptor.getParameters().size()); Parameter param2 = new Parameter(); param2.setName("param2"); param2.setDefaultValue("value2"); mojoDescriptor.addParameter(param2); - assertEquals(2, mojoDescriptor.getParameters().size()); - assertEquals( - mojoDescriptor.getParameters().size(), - mojoDescriptor.getParameterMap().size()); + assertThat(mojoDescriptor.getParameters().size()).isEqualTo(2); + assertThat(mojoDescriptor.getParameterMap().size()).isEqualTo(mojoDescriptor.getParameters().size()); } } diff --git a/compat/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilderTest.java b/compat/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilderTest.java index f9839369e23a..6c2113456ee7 100644 --- a/compat/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilderTest.java +++ b/compat/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilderTest.java @@ -27,11 +27,7 @@ import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@link PluginDescriptorBuilder}. @@ -46,85 +42,85 @@ private PluginDescriptor build(String resource) throws IOException, PlexusConfig } @Test - void testBuildReader() throws Exception { + void buildReader() throws Exception { PluginDescriptor pd = build("/plugin.xml"); - assertEquals("org.apache.maven.plugins", pd.getGroupId()); - assertEquals("maven-jar-plugin", pd.getArtifactId()); - assertEquals("2.3-SNAPSHOT", pd.getVersion()); - assertEquals("jar", pd.getGoalPrefix()); - assertEquals("plugin-description", pd.getDescription()); - assertFalse(pd.isIsolatedRealm()); - assertTrue(pd.isInheritedByDefault()); - assertEquals(2, pd.getMojos().size()); - assertEquals(1, pd.getDependencies().size()); + assertThat(pd.getGroupId()).isEqualTo("org.apache.maven.plugins"); + assertThat(pd.getArtifactId()).isEqualTo("maven-jar-plugin"); + assertThat(pd.getVersion()).isEqualTo("2.3-SNAPSHOT"); + assertThat(pd.getGoalPrefix()).isEqualTo("jar"); + assertThat(pd.getDescription()).isEqualTo("plugin-description"); + assertThat(pd.isIsolatedRealm()).isFalse(); + assertThat(pd.isInheritedByDefault()).isTrue(); + assertThat(pd.getMojos().size()).isEqualTo(2); + assertThat(pd.getDependencies().size()).isEqualTo(1); MojoDescriptor md = pd.getMojos().get(0); - assertEquals("jar", md.getGoal()); - assertEquals("mojo-description", md.getDescription()); - assertEquals("runtime", md.getDependencyResolutionRequired()); - assertEquals("test", md.getDependencyCollectionRequired()); - assertFalse(md.isAggregator()); - assertFalse(md.isDirectInvocationOnly()); - assertTrue(md.isInheritedByDefault()); - assertFalse(md.isOnlineRequired()); - assertTrue(md.isProjectRequired()); - assertFalse(md.isThreadSafe()); - assertEquals("package", md.getPhase()); - assertEquals("org.apache.maven.plugin.jar.JarMojo", md.getImplementation()); - assertEquals("antrun", md.getComponentConfigurator()); - assertEquals("java", md.getLanguage()); - assertEquals("per-lookup", md.getInstantiationStrategy()); - assertEquals("some-goal", md.getExecuteGoal()); - assertEquals("generate-sources", md.getExecutePhase()); - assertEquals("cobertura", md.getExecuteLifecycle()); - assertEquals("2.2", md.getSince()); - assertEquals("deprecated-mojo", md.getDeprecated()); - assertEquals(1, md.getRequirements().size()); - assertEquals(1, md.getParameters().size()); - - assertNotNull(md.getMojoConfiguration()); - assertEquals(1, md.getMojoConfiguration().getChildCount()); + assertThat(md.getGoal()).isEqualTo("jar"); + assertThat(md.getDescription()).isEqualTo("mojo-description"); + assertThat(md.getDependencyResolutionRequired()).isEqualTo("runtime"); + assertThat(md.getDependencyCollectionRequired()).isEqualTo("test"); + assertThat(md.isAggregator()).isFalse(); + assertThat(md.isDirectInvocationOnly()).isFalse(); + assertThat(md.isInheritedByDefault()).isTrue(); + assertThat(md.isOnlineRequired()).isFalse(); + assertThat(md.isProjectRequired()).isTrue(); + assertThat(md.isThreadSafe()).isFalse(); + assertThat(md.getPhase()).isEqualTo("package"); + assertThat(md.getImplementation()).isEqualTo("org.apache.maven.plugin.jar.JarMojo"); + assertThat(md.getComponentConfigurator()).isEqualTo("antrun"); + assertThat(md.getLanguage()).isEqualTo("java"); + assertThat(md.getInstantiationStrategy()).isEqualTo("per-lookup"); + assertThat(md.getExecuteGoal()).isEqualTo("some-goal"); + assertThat(md.getExecutePhase()).isEqualTo("generate-sources"); + assertThat(md.getExecuteLifecycle()).isEqualTo("cobertura"); + assertThat(md.getSince()).isEqualTo("2.2"); + assertThat(md.getDeprecated()).isEqualTo("deprecated-mojo"); + assertThat(md.getRequirements().size()).isEqualTo(1); + assertThat(md.getParameters().size()).isEqualTo(1); + + assertThat(md.getMojoConfiguration()).isNotNull(); + assertThat(md.getMojoConfiguration().getChildCount()).isEqualTo(1); PlexusConfiguration pc = md.getMojoConfiguration().getChild(0); - assertEquals("${jar.finalName}", pc.getValue()); - assertEquals("${project.build.finalName}", pc.getAttribute("default-value")); - assertEquals("java.lang.String", pc.getAttribute("implementation")); + assertThat(pc.getValue()).isEqualTo("${jar.finalName}"); + assertThat(pc.getAttribute("default-value")).isEqualTo("${project.build.finalName}"); + assertThat(pc.getAttribute("implementation")).isEqualTo("java.lang.String"); Parameter mp = md.getParameters().get(0); - assertEquals("finalName", mp.getName()); - assertEquals("jarName", mp.getAlias()); - assertEquals("java.lang.String", mp.getType()); - assertEquals("java.lang.String", mp.getImplementation()); - assertTrue(mp.isEditable()); - assertFalse(mp.isRequired()); - assertEquals("parameter-description", mp.getDescription()); - assertEquals("deprecated-parameter", mp.getDeprecated()); - assertEquals("${jar.finalName}", mp.getExpression()); - assertEquals("${project.build.finalName}", mp.getDefaultValue()); - assertEquals("3.0.0", mp.getSince()); + assertThat(mp.getName()).isEqualTo("finalName"); + assertThat(mp.getAlias()).isEqualTo("jarName"); + assertThat(mp.getType()).isEqualTo("java.lang.String"); + assertThat(mp.getImplementation()).isEqualTo("java.lang.String"); + assertThat(mp.isEditable()).isTrue(); + assertThat(mp.isRequired()).isFalse(); + assertThat(mp.getDescription()).isEqualTo("parameter-description"); + assertThat(mp.getDeprecated()).isEqualTo("deprecated-parameter"); + assertThat(mp.getExpression()).isEqualTo("${jar.finalName}"); + assertThat(mp.getDefaultValue()).isEqualTo("${project.build.finalName}"); + assertThat(mp.getSince()).isEqualTo("3.0.0"); ComponentRequirement cr = md.getRequirements().get(0); - assertEquals("org.codehaus.plexus.archiver.Archiver", cr.getRole()); - assertEquals("jar", cr.getRoleHint()); - assertEquals("jarArchiver", cr.getFieldName()); + assertThat(cr.getRole()).isEqualTo("org.codehaus.plexus.archiver.Archiver"); + assertThat(cr.getRoleHint()).isEqualTo("jar"); + assertThat(cr.getFieldName()).isEqualTo("jarArchiver"); ComponentDependency cd = pd.getDependencies().get(0); - assertEquals("org.apache.maven", cd.getGroupId()); - assertEquals("maven-plugin-api", cd.getArtifactId()); - assertEquals("2.0.6", cd.getVersion()); - assertEquals("jar", cd.getType()); + assertThat(cd.getGroupId()).isEqualTo("org.apache.maven"); + assertThat(cd.getArtifactId()).isEqualTo("maven-plugin-api"); + assertThat(cd.getVersion()).isEqualTo("2.0.6"); + assertThat(cd.getType()).isEqualTo("jar"); md = pd.getMojos().get(1); - assertEquals("war", md.getGoal()); - assertNull(md.getDependencyResolutionRequired()); - assertNull(md.getDependencyCollectionRequired()); - assertTrue(md.isThreadSafe()); + assertThat(md.getGoal()).isEqualTo("war"); + assertThat(md.getDependencyResolutionRequired()).isNull(); + assertThat(md.getDependencyCollectionRequired()).isNull(); + assertThat(md.isThreadSafe()).isTrue(); } } diff --git a/compat/maven-repository-metadata/src/test/java/org/apache/maven/artifact/repository/metadata/MetadataTest.java b/compat/maven-repository-metadata/src/test/java/org/apache/maven/artifact/repository/metadata/MetadataTest.java index 8d5472b85bbe..96203a2ac4da 100644 --- a/compat/maven-repository-metadata/src/test/java/org/apache/maven/artifact/repository/metadata/MetadataTest.java +++ b/compat/maven-repository-metadata/src/test/java/org/apache/maven/artifact/repository/metadata/MetadataTest.java @@ -33,10 +33,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class MetadataTest { @@ -54,7 +51,7 @@ void before() { @Test void mergeEmptyMetadata() throws Exception { Metadata metadata = new Metadata(); - assertFalse(metadata.merge(new Metadata())); + assertThat(metadata.merge(new Metadata())).isFalse(); } @Test @@ -64,10 +61,10 @@ void mergeDifferentGAV() throws Exception { source.setArtifactId("source-artifact"); source.setGroupId("source-group"); source.setVersion("2.0"); - assertFalse(target.merge(source)); - assertEquals("myArtifact", target.getArtifactId()); - assertEquals("myGroup", target.getGroupId()); - assertEquals("1.0-SNAPSHOT", target.getVersion()); + assertThat(target.merge(source)).isFalse(); + assertThat(target.getArtifactId()).isEqualTo("myArtifact"); + assertThat(target.getGroupId()).isEqualTo("myGroup"); + assertThat(target.getVersion()).isEqualTo("1.0-SNAPSHOT"); } /*--- END test common metadata ---*/ @@ -87,24 +84,21 @@ void mergeSnapshotWithEmptyList() throws Exception { Metadata source = createMetadataFromArtifact(artifact); // nothing should be actually changed, but still merge returns true - assertTrue(target.merge(source)); + assertThat(target.merge(source)).isTrue(); // NOTE! Merge updates last updated to source - assertEquals("20200921071745", source.getVersioning().getLastUpdated()); + assertThat(source.getVersioning().getLastUpdated()).isEqualTo("20200921071745"); - assertEquals("myArtifact", target.getArtifactId()); - assertEquals("myGroup", target.getGroupId()); + assertThat(target.getArtifactId()).isEqualTo("myArtifact"); + assertThat(target.getGroupId()).isEqualTo("myGroup"); - assertEquals(3, target.getVersioning().getSnapshot().getBuildNumber()); - assertEquals("20200710.072412", target.getVersioning().getSnapshot().getTimestamp()); + assertThat(target.getVersioning().getSnapshot().getBuildNumber()).isEqualTo(3); + assertThat(target.getVersioning().getSnapshot().getTimestamp()).isEqualTo("20200710.072412"); - assertEquals(1, target.getVersioning().getSnapshotVersions().size()); - assertEquals( - "sources", target.getVersioning().getSnapshotVersions().get(0).getClassifier()); - assertEquals("jar", target.getVersioning().getSnapshotVersions().get(0).getExtension()); - assertEquals( - "20200710072412", - target.getVersioning().getSnapshotVersions().get(0).getUpdated()); + assertThat(target.getVersioning().getSnapshotVersions().size()).isEqualTo(1); + assertThat(target.getVersioning().getSnapshotVersions().get(0).getClassifier()).isEqualTo("sources"); + assertThat(target.getVersioning().getSnapshotVersions().get(0).getExtension()).isEqualTo("jar"); + assertThat(target.getVersioning().getSnapshotVersions().get(0).getUpdated()).isEqualTo("20200710072412"); } @Test @@ -117,14 +111,14 @@ void mergeWithSameSnapshotWithDifferentVersionsAndNewerLastUpdated() { addSnapshotVersion(source.getVersioning(), "jar", after, "1.0-" + formatDate(after, true) + "-2", 2); SnapshotVersion sv3 = addSnapshotVersion(source.getVersioning(), "pom", after, "1.0-" + formatDate(after, true) + "-2", 2); - assertTrue(target.merge(source)); + assertThat(target.merge(source)).isTrue(); Versioning actualVersioning = target.getVersioning(); - assertEquals(2, actualVersioning.getSnapshotVersions().size()); - assertEquals(sv2, actualVersioning.getSnapshotVersions().get(0)); - assertEquals(sv3, actualVersioning.getSnapshotVersions().get(1)); - assertEquals(formatDate(after, false), actualVersioning.getLastUpdated()); - assertEquals(formatDate(after, true), actualVersioning.getSnapshot().getTimestamp()); - assertEquals(2, actualVersioning.getSnapshot().getBuildNumber()); + assertThat(actualVersioning.getSnapshotVersions().size()).isEqualTo(2); + assertThat(actualVersioning.getSnapshotVersions().get(0)).isEqualTo(sv2); + assertThat(actualVersioning.getSnapshotVersions().get(1)).isEqualTo(sv3); + assertThat(actualVersioning.getLastUpdated()).isEqualTo(formatDate(after, false)); + assertThat(actualVersioning.getSnapshot().getTimestamp()).isEqualTo(formatDate(after, true)); + assertThat(actualVersioning.getSnapshot().getBuildNumber()).isEqualTo(2); } @Test @@ -135,12 +129,11 @@ void mergeWithSameSnapshotWithDifferentVersionsAndOlderLastUpdated() { SnapshotVersion sv1 = addSnapshotVersion(target.getVersioning(), after, artifact); addSnapshotVersion(source.getVersioning(), before, artifact); // nothing should be updated, as the target was already updated at a later date than source - assertFalse(target.merge(source)); - assertEquals(1, target.getVersioning().getSnapshotVersions().size()); - assertEquals(sv1, target.getVersioning().getSnapshotVersions().get(0)); - assertEquals(formatDate(after, false), target.getVersioning().getLastUpdated()); - assertEquals( - formatDate(after, true), target.getVersioning().getSnapshot().getTimestamp()); + assertThat(target.merge(source)).isFalse(); + assertThat(target.getVersioning().getSnapshotVersions().size()).isEqualTo(1); + assertThat(target.getVersioning().getSnapshotVersions().get(0)).isEqualTo(sv1); + assertThat(target.getVersioning().getLastUpdated()).isEqualTo(formatDate(after, false)); + assertThat(target.getVersioning().getSnapshot().getTimestamp()).isEqualTo(formatDate(after, true)); } @Test @@ -151,12 +144,11 @@ void mergeWithSameSnapshotWithSameVersionAndTimestamp() { SnapshotVersion sv1 = addSnapshotVersion(source.getVersioning(), date, artifact); // although nothing has changed merge returns true, as the last modified date is equal // TODO: improve merge here? - assertTrue(target.merge(source)); - assertEquals(1, target.getVersioning().getSnapshotVersions().size()); - assertEquals(sv1, target.getVersioning().getSnapshotVersions().get(0)); - assertEquals(formatDate(date, false), target.getVersioning().getLastUpdated()); - assertEquals( - formatDate(date, true), target.getVersioning().getSnapshot().getTimestamp()); + assertThat(target.merge(source)).isTrue(); + assertThat(target.getVersioning().getSnapshotVersions().size()).isEqualTo(1); + assertThat(target.getVersioning().getSnapshotVersions().get(0)).isEqualTo(sv1); + assertThat(target.getVersioning().getLastUpdated()).isEqualTo(formatDate(date, false)); + assertThat(target.getVersioning().getSnapshot().getTimestamp()).isEqualTo(formatDate(date, true)); } @Test @@ -169,11 +161,10 @@ void mergeLegacyWithSnapshotLegacy() { addSnapshotVersionLegacy(source.getVersioning(), after, 2); // although nothing has changed merge returns true, as the last modified date is equal // TODO: improve merge here? - assertTrue(target.merge(source)); - assertEquals(0, target.getVersioning().getSnapshotVersions().size()); - assertEquals(formatDate(after, false), target.getVersioning().getLastUpdated()); - assertEquals( - formatDate(after, true), target.getVersioning().getSnapshot().getTimestamp()); + assertThat(target.merge(source)).isTrue(); + assertThat(target.getVersioning().getSnapshotVersions().size()).isEqualTo(0); + assertThat(target.getVersioning().getLastUpdated()).isEqualTo(formatDate(after, false)); + assertThat(target.getVersioning().getSnapshot().getTimestamp()).isEqualTo(formatDate(after, true)); } @Test @@ -186,12 +177,11 @@ void mergeLegacyWithSnapshot() { addSnapshotVersion(source.getVersioning(), after, artifact); // although nothing has changed merge returns true, as the last modified date is equal // TODO: improve merge here? - assertTrue(target.merge(source)); + assertThat(target.merge(source)).isTrue(); // never convert from legacy format to v1.1 format - assertEquals(0, target.getVersioning().getSnapshotVersions().size()); - assertEquals(formatDate(after, false), target.getVersioning().getLastUpdated()); - assertEquals( - formatDate(after, true), target.getVersioning().getSnapshot().getTimestamp()); + assertThat(target.getVersioning().getSnapshotVersions().size()).isEqualTo(0); + assertThat(target.getVersioning().getLastUpdated()).isEqualTo(formatDate(after, false)); + assertThat(target.getVersioning().getSnapshot().getTimestamp()).isEqualTo(formatDate(after, true)); } @Test @@ -204,18 +194,17 @@ void mergeWithSnapshotLegacy() { addSnapshotVersionLegacy(source.getVersioning(), after, 2); // although nothing has changed merge returns true, as the last modified date is equal // TODO: improve merge here? - assertTrue(target.merge(source)); + assertThat(target.merge(source)).isTrue(); // the result must be legacy format as well - assertEquals(0, target.getVersioning().getSnapshotVersions().size()); - assertEquals(formatDate(after, false), target.getVersioning().getLastUpdated()); - assertEquals( - formatDate(after, true), target.getVersioning().getSnapshot().getTimestamp()); - assertEquals(2, target.getVersioning().getSnapshot().getBuildNumber()); + assertThat(target.getVersioning().getSnapshotVersions().size()).isEqualTo(0); + assertThat(target.getVersioning().getLastUpdated()).isEqualTo(formatDate(after, false)); + assertThat(target.getVersioning().getSnapshot().getTimestamp()).isEqualTo(formatDate(after, true)); + assertThat(target.getVersioning().getSnapshot().getBuildNumber()).isEqualTo(2); } /*-- END test "groupId/artifactId/version" metadata ---*/ @Test - void testRoundtrip() throws Exception { + void roundtrip() throws Exception { Metadata source = new Metadata(org.apache.maven.api.metadata.Metadata.newBuilder( createMetadataFromArtifact(artifact).getDelegate(), true) .modelEncoding("UTF-16") @@ -224,7 +213,7 @@ void testRoundtrip() throws Exception { new MetadataStaxWriter().write(baos, source.getDelegate()); Metadata source2 = new Metadata(new MetadataStaxReader().read(new ByteArrayInputStream(baos.toByteArray()), true)); - assertNotNull(source2); + assertThat(source2).isNotNull(); } /*-- START helper methods to populate metadata objects ---*/ diff --git a/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java b/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java index 3aa7ba3b26d4..f2dce887b7e1 100644 --- a/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java +++ b/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java @@ -29,15 +29,14 @@ import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; class DefaultArtifactDescriptorReaderTest extends AbstractRepositoryTestCase { @Test - void testMng5459() throws Exception { + void mng5459() throws Exception { // prepare DefaultArtifactDescriptorReader reader = (DefaultArtifactDescriptorReader) getContainer().lookup(ArtifactDescriptorReader.class); @@ -66,16 +65,12 @@ void testMng5459() throws Exception { for (RepositoryEvent evt : event.getAllValues()) { if (EventType.ARTIFACT_DESCRIPTOR_MISSING.equals(evt.getType())) { - assertEquals( - "Could not find artifact org.apache.maven.its:dep-mng5459:pom:0.4.0-20130404.090532-2 in repo (" - + newTestRepository().getUrl() + ")", - evt.getException().getMessage()); + assertThat(evt.getException().getMessage()).isEqualTo("Could not find artifact org.apache.maven.its:dep-mng5459:pom:0.4.0-20130404.090532-2 in repo (" + + newTestRepository().getUrl() + ")"); missingArtifactDescriptor = true; } } - assertTrue( - missingArtifactDescriptor, - "Expected missing artifact descriptor for org.apache.maven.its:dep-mng5459:pom:0.4.0-20130404.090532-2"); + assertThat(missingArtifactDescriptor).as("Expected missing artifact descriptor for org.apache.maven.its:dep-mng5459:pom:0.4.0-20130404.090532-2").isTrue(); } } diff --git a/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java b/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java index 7083c9c9d07e..549e4cb077cd 100644 --- a/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java +++ b/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java @@ -31,10 +31,8 @@ import org.eclipse.aether.impl.VersionRangeResolver; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; /** * Test cases for the default {@code ModelResolver} implementation. @@ -51,134 +49,116 @@ final class DefaultModelResolverTest extends AbstractRepositoryTestCase { } @Test - public void testResolveParentThrowsUnresolvableModelExceptionWhenNotFound() throws Exception { + void resolveParentThrowsUnresolvableModelExceptionWhenNotFound() throws Exception { final Parent parent = new Parent(); parent.setGroupId("ut.simple"); parent.setArtifactId("artifact"); parent.setVersion("0"); - UnresolvableModelException e = assertThrows( - UnresolvableModelException.class, - () -> newModelResolver().resolveModel(parent), - "Expected 'UnresolvableModelException' not thrown."); - assertNotNull(e.getMessage()); - assertTrue(e.getMessage().contains("Could not find artifact ut.simple:artifact:pom:0 in repo")); + UnresolvableModelException e = assertThatExceptionOfType(UnresolvableModelException.class).as("Expected 'UnresolvableModelException' not thrown.").isThrownBy(() -> newModelResolver().resolveModel(parent)).actual(); + assertThat(e.getMessage()).isNotNull(); + assertThat(e.getMessage().contains("Could not find artifact ut.simple:artifact:pom:0 in repo")).isTrue(); } @Test - public void testResolveParentThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception { + void resolveParentThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception { final Parent parent = new Parent(); parent.setGroupId("ut.simple"); parent.setArtifactId("artifact"); parent.setVersion("[2.0,2.1)"); - UnresolvableModelException e = assertThrows( - UnresolvableModelException.class, - () -> newModelResolver().resolveModel(parent), - "Expected 'UnresolvableModelException' not thrown."); - assertNotNull(e.getMessage()); - assertEquals("No versions matched the requested parent version range '[2.0,2.1)'", e.getMessage()); + UnresolvableModelException e = assertThatExceptionOfType(UnresolvableModelException.class).as("Expected 'UnresolvableModelException' not thrown.").isThrownBy(() -> newModelResolver().resolveModel(parent)).actual(); + assertThat(e.getMessage()).isNotNull(); + assertThat(e.getMessage()).isEqualTo("No versions matched the requested parent version range '[2.0,2.1)'"); } @Test - void testResolveParentThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception { + void resolveParentThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception { final Parent parent = new Parent(); parent.setGroupId("ut.simple"); parent.setArtifactId("artifact"); parent.setVersion("[1.0,)"); - UnresolvableModelException e = assertThrows( - UnresolvableModelException.class, - () -> newModelResolver().resolveModel(parent), - "Expected 'UnresolvableModelException' not thrown."); - assertEquals("The requested parent version range '[1.0,)' does not specify an upper bound", e.getMessage()); + UnresolvableModelException e = assertThatExceptionOfType(UnresolvableModelException.class).as("Expected 'UnresolvableModelException' not thrown.").isThrownBy(() -> newModelResolver().resolveModel(parent)).actual(); + assertThat(e.getMessage()).isEqualTo("The requested parent version range '[1.0,)' does not specify an upper bound"); } @Test - void testResolveParentSuccessfullyResolvesExistingParentWithoutRange() throws Exception { + void resolveParentSuccessfullyResolvesExistingParentWithoutRange() throws Exception { final Parent parent = new Parent(); parent.setGroupId("ut.simple"); parent.setArtifactId("artifact"); parent.setVersion("1.0"); - assertNotNull(this.newModelResolver().resolveModel(parent)); - assertEquals("1.0", parent.getVersion()); + assertThat(this.newModelResolver().resolveModel(parent)).isNotNull(); + assertThat(parent.getVersion()).isEqualTo("1.0"); } @Test - void testResolveParentSuccessfullyResolvesExistingParentUsingHighestVersion() throws Exception { + void resolveParentSuccessfullyResolvesExistingParentUsingHighestVersion() throws Exception { final Parent parent = new Parent(); parent.setGroupId("ut.simple"); parent.setArtifactId("artifact"); parent.setVersion("(,2.0)"); - assertNotNull(this.newModelResolver().resolveModel(parent)); - assertEquals("1.0", parent.getVersion()); + assertThat(this.newModelResolver().resolveModel(parent)).isNotNull(); + assertThat(parent.getVersion()).isEqualTo("1.0"); } @Test - void testResolveDependencyThrowsUnresolvableModelExceptionWhenNotFound() throws Exception { + void resolveDependencyThrowsUnresolvableModelExceptionWhenNotFound() throws Exception { final Dependency dependency = new Dependency(); dependency.setGroupId("ut.simple"); dependency.setArtifactId("artifact"); dependency.setVersion("0"); - UnresolvableModelException e = assertThrows( - UnresolvableModelException.class, - () -> newModelResolver().resolveModel(dependency), - "Expected 'UnresolvableModelException' not thrown."); - assertNotNull(e.getMessage()); - assertTrue(e.getMessage().contains("Could not find artifact ut.simple:artifact:pom:0 in repo")); + UnresolvableModelException e = assertThatExceptionOfType(UnresolvableModelException.class).as("Expected 'UnresolvableModelException' not thrown.").isThrownBy(() -> newModelResolver().resolveModel(dependency)).actual(); + assertThat(e.getMessage()).isNotNull(); + assertThat(e.getMessage().contains("Could not find artifact ut.simple:artifact:pom:0 in repo")).isTrue(); } @Test - void testResolveDependencyThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception { + void resolveDependencyThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception { final Dependency dependency = new Dependency(); dependency.setGroupId("ut.simple"); dependency.setArtifactId("artifact"); dependency.setVersion("[2.0,2.1)"); - UnresolvableModelException e = assertThrows( - UnresolvableModelException.class, - () -> newModelResolver().resolveModel(dependency), - "Expected 'UnresolvableModelException' not thrown."); - assertEquals("No versions matched the requested dependency version range '[2.0,2.1)'", e.getMessage()); + UnresolvableModelException e = assertThatExceptionOfType(UnresolvableModelException.class).as("Expected 'UnresolvableModelException' not thrown.").isThrownBy(() -> newModelResolver().resolveModel(dependency)).actual(); + assertThat(e.getMessage()).isEqualTo("No versions matched the requested dependency version range '[2.0,2.1)'"); } @Test - void testResolveDependencyThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception { + void resolveDependencyThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception { final Dependency dependency = new Dependency(); dependency.setGroupId("ut.simple"); dependency.setArtifactId("artifact"); dependency.setVersion("[1.0,)"); - UnresolvableModelException e = assertThrows( - UnresolvableModelException.class, - () -> newModelResolver().resolveModel(dependency), - "Expected 'UnresolvableModelException' not thrown."); - assertEquals("The requested dependency version range '[1.0,)' does not specify an upper bound", e.getMessage()); + UnresolvableModelException e = assertThatExceptionOfType(UnresolvableModelException.class).as("Expected 'UnresolvableModelException' not thrown.").isThrownBy(() -> newModelResolver().resolveModel(dependency)).actual(); + assertThat(e.getMessage()).isEqualTo("The requested dependency version range '[1.0,)' does not specify an upper bound"); } @Test - void testResolveDependencySuccessfullyResolvesExistingDependencyWithoutRange() throws Exception { + void resolveDependencySuccessfullyResolvesExistingDependencyWithoutRange() throws Exception { final Dependency dependency = new Dependency(); dependency.setGroupId("ut.simple"); dependency.setArtifactId("artifact"); dependency.setVersion("1.0"); - assertNotNull(this.newModelResolver().resolveModel(dependency)); - assertEquals("1.0", dependency.getVersion()); + assertThat(this.newModelResolver().resolveModel(dependency)).isNotNull(); + assertThat(dependency.getVersion()).isEqualTo("1.0"); } @Test - void testResolveDependencySuccessfullyResolvesExistingDependencyUsingHighestVersion() throws Exception { + void resolveDependencySuccessfullyResolvesExistingDependencyUsingHighestVersion() throws Exception { final Dependency dependency = new Dependency(); dependency.setGroupId("ut.simple"); dependency.setArtifactId("artifact"); dependency.setVersion("(,2.0)"); - assertNotNull(this.newModelResolver().resolveModel(dependency)); - assertEquals("1.0", dependency.getVersion()); + assertThat(this.newModelResolver().resolveModel(dependency)).isNotNull(); + assertThat(dependency.getVersion()).isEqualTo("1.0"); } private ModelResolver newModelResolver() throws ComponentLookupException, MalformedURLException { diff --git a/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultVersionResolverTest.java b/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultVersionResolverTest.java index 8231324df9fd..c951843285b0 100644 --- a/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultVersionResolverTest.java +++ b/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultVersionResolverTest.java @@ -26,14 +26,14 @@ import org.eclipse.aether.resolution.VersionResult; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; class DefaultVersionResolverTest extends AbstractRepositoryTestCase { @Inject private DefaultVersionResolver versionResolver; @Test - void testResolveSeparateInstalledClassifiedNonUniqueVersionedArtifacts() throws Exception { + void resolveSeparateInstalledClassifiedNonUniqueVersionedArtifacts() throws Exception { VersionRequest requestB = new VersionRequest(); requestB.addRepository(newTestRepository()); Artifact artifactB = @@ -41,7 +41,7 @@ void testResolveSeparateInstalledClassifiedNonUniqueVersionedArtifacts() throws requestB.setArtifact(artifactB); VersionResult resultB = versionResolver.resolveVersion(session, requestB); - assertEquals("07.20.3-20120809.112920-97", resultB.getVersion()); + assertThat(resultB.getVersion()).isEqualTo("07.20.3-20120809.112920-97"); VersionRequest requestA = new VersionRequest(); requestA.addRepository(newTestRepository()); @@ -51,11 +51,11 @@ void testResolveSeparateInstalledClassifiedNonUniqueVersionedArtifacts() throws requestA.setArtifact(artifactA); VersionResult resultA = versionResolver.resolveVersion(session, requestA); - assertEquals("07.20.3-20120809.112124-88", resultA.getVersion()); + assertThat(resultA.getVersion()).isEqualTo("07.20.3-20120809.112124-88"); } @Test - void testResolveSeparateInstalledClassifiedNonVersionedArtifacts() throws Exception { + void resolveSeparateInstalledClassifiedNonVersionedArtifacts() throws Exception { VersionRequest requestA = new VersionRequest(); requestA.addRepository(newTestRepository()); String versionA = "07.20.3-20120809.112124-88"; @@ -63,7 +63,7 @@ void testResolveSeparateInstalledClassifiedNonVersionedArtifacts() throws Except requestA.setArtifact(artifactA); VersionResult resultA = versionResolver.resolveVersion(session, requestA); - assertEquals(versionA, resultA.getVersion()); + assertThat(resultA.getVersion()).isEqualTo(versionA); VersionRequest requestB = new VersionRequest(); requestB.addRepository(newTestRepository()); @@ -72,6 +72,6 @@ void testResolveSeparateInstalledClassifiedNonVersionedArtifacts() throws Except requestB.setArtifact(artifactB); VersionResult resultB = versionResolver.resolveVersion(session, requestB); - assertEquals(versionB, resultB.getVersion()); + assertThat(resultB.getVersion()).isEqualTo(versionB); } } diff --git a/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataTest.java b/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataTest.java index cc58b3d80d70..91cbdab43869 100644 --- a/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataTest.java +++ b/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataTest.java @@ -33,8 +33,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class RemoteSnapshotMetadataTest { private Locale defaultLocale; @@ -74,7 +73,7 @@ void gregorianCalendarIsUsed() { /* Allow for this test running across midnight */ Set expected = new HashSet<>(Arrays.asList(dateBefore, dateAfter)); - assertTrue(expected.contains(datePart), "Expected " + datePart + " to be in " + expected); + assertThat(expected.contains(datePart)).as("Expected " + datePart + " to be in " + expected).isTrue(); } @Test @@ -84,7 +83,7 @@ void buildNumberNotSet() { metadata.merge(new Metadata()); int buildNumber = metadata.metadata.getVersioning().getSnapshot().getBuildNumber(); - assertEquals(1, buildNumber); + assertThat(buildNumber).isEqualTo(1); } @Test @@ -94,6 +93,6 @@ void buildNumberSet() { metadata.merge(new Metadata()); int buildNumber = metadata.metadata.getVersioning().getSnapshot().getBuildNumber(); - assertEquals(42, buildNumber); + assertThat(buildNumber).isEqualTo(42); } } diff --git a/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RepositorySystemTest.java b/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RepositorySystemTest.java index ce33186a73e1..f58993cc0709 100644 --- a/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RepositorySystemTest.java +++ b/compat/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RepositorySystemTest.java @@ -33,28 +33,24 @@ import org.eclipse.aether.resolution.ArtifactResult; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class RepositorySystemTest extends AbstractRepositoryTestCase { @Test - void testResolveVersionRange() throws Exception { + void resolveVersionRange() throws Exception { // VersionRangeResult resolveVersionRange( RepositorySystemSession session, VersionRangeRequest request ) // throws VersionRangeResolutionException; } @Test - void testResolveVersion() throws Exception { + void resolveVersion() throws Exception { // VersionResult resolveVersion( RepositorySystemSession session, VersionRequest request ) // throws VersionResolutionException; } @Test - void testReadArtifactDescriptor() throws Exception { + void readArtifactDescriptor() throws Exception { Artifact artifact = new DefaultArtifact("ut.simple:artifact:extension:classifier:1.0"); ArtifactDescriptorRequest request = new ArtifactDescriptorRequest(); @@ -64,7 +60,7 @@ void testReadArtifactDescriptor() throws Exception { ArtifactDescriptorResult result = system.readArtifactDescriptor(session, request); List deps = result.getDependencies(); - assertEquals(2, deps.size()); + assertThat(deps.size()).isEqualTo(2); checkUtSimpleArtifactDependencies(deps.get(0), deps.get(1)); } @@ -72,48 +68,45 @@ void testReadArtifactDescriptor() throws Exception { * check ut.simple:artifact:1.0 dependencies */ private void checkUtSimpleArtifactDependencies(Dependency dep1, Dependency dep2) { - assertEquals("compile", dep1.getScope()); - assertFalse(dep1.isOptional()); - assertEquals(0, dep1.getExclusions().size()); + assertThat(dep1.getScope()).isEqualTo("compile"); + assertThat(dep1.isOptional()).isFalse(); + assertThat(dep1.getExclusions().size()).isEqualTo(0); Artifact depArtifact = dep1.getArtifact(); - assertEquals("ut.simple", depArtifact.getGroupId()); - assertEquals("dependency", depArtifact.getArtifactId()); - assertEquals("1.0", depArtifact.getVersion()); - assertEquals("1.0", depArtifact.getBaseVersion()); - assertNull(depArtifact.getFile()); - assertFalse(depArtifact.isSnapshot()); - assertEquals("", depArtifact.getClassifier()); - assertEquals("jar", depArtifact.getExtension()); - assertEquals("java", depArtifact.getProperty("language", null)); - assertEquals("jar", depArtifact.getProperty("type", null)); - assertEquals("true", depArtifact.getProperty("constitutesBuildPath", null)); - assertEquals("false", depArtifact.getProperty("includesDependencies", null)); - assertEquals(4, depArtifact.getProperties().size()); - - assertEquals("compile", dep2.getScope()); - assertFalse(dep2.isOptional()); - assertEquals(0, dep2.getExclusions().size()); + assertThat(depArtifact.getGroupId()).isEqualTo("ut.simple"); + assertThat(depArtifact.getArtifactId()).isEqualTo("dependency"); + assertThat(depArtifact.getVersion()).isEqualTo("1.0"); + assertThat(depArtifact.getBaseVersion()).isEqualTo("1.0"); + assertThat(depArtifact.getFile()).isNull(); + assertThat(depArtifact.isSnapshot()).isFalse(); + assertThat(depArtifact.getClassifier()).isEqualTo(""); + assertThat(depArtifact.getExtension()).isEqualTo("jar"); + assertThat(depArtifact.getProperty("language", null)).isEqualTo("java"); + assertThat(depArtifact.getProperty("type", null)).isEqualTo("jar"); + assertThat(depArtifact.getProperty("constitutesBuildPath", null)).isEqualTo("true"); + assertThat(depArtifact.getProperty("includesDependencies", null)).isEqualTo("false"); + assertThat(depArtifact.getProperties().size()).isEqualTo(4); + + assertThat(dep2.getScope()).isEqualTo("compile"); + assertThat(dep2.isOptional()).isFalse(); + assertThat(dep2.getExclusions().size()).isEqualTo(0); depArtifact = dep2.getArtifact(); - assertEquals("ut.simple", depArtifact.getGroupId()); - assertEquals("dependency", depArtifact.getArtifactId()); - assertEquals("1.0", depArtifact.getVersion()); - assertEquals("1.0", depArtifact.getBaseVersion()); - assertNull(depArtifact.getFile()); - assertFalse(depArtifact.isSnapshot()); - assertEquals("sources", depArtifact.getClassifier()); - assertEquals("jar", depArtifact.getExtension()); - assertEquals("java", depArtifact.getProperty("language", null)); - assertEquals( - "jar", depArtifact.getProperty("type", null)); // shouldn't it be java-sources given the classifier? - assertEquals( - "true", - depArtifact.getProperty("constitutesBuildPath", null)); // shouldn't it be false given the classifier? - assertEquals("false", depArtifact.getProperty("includesDependencies", null)); - assertEquals(4, depArtifact.getProperties().size()); + assertThat(depArtifact.getGroupId()).isEqualTo("ut.simple"); + assertThat(depArtifact.getArtifactId()).isEqualTo("dependency"); + assertThat(depArtifact.getVersion()).isEqualTo("1.0"); + assertThat(depArtifact.getBaseVersion()).isEqualTo("1.0"); + assertThat(depArtifact.getFile()).isNull(); + assertThat(depArtifact.isSnapshot()).isFalse(); + assertThat(depArtifact.getClassifier()).isEqualTo("sources"); + assertThat(depArtifact.getExtension()).isEqualTo("jar"); + assertThat(depArtifact.getProperty("language", null)).isEqualTo("java"); + assertThat(depArtifact.getProperty("type", null)).isEqualTo("jar"); // shouldn't it be java-sources given the classifier? + assertThat(depArtifact.getProperty("constitutesBuildPath", null)).isEqualTo("true"); // shouldn't it be false given the classifier? + assertThat(depArtifact.getProperty("includesDependencies", null)).isEqualTo("false"); + assertThat(depArtifact.getProperties().size()).isEqualTo(4); } @Test - void testCollectDependencies() throws Exception { + void collectDependencies() throws Exception { Artifact artifact = new DefaultArtifact("ut.simple:artifact:extension:classifier:1.0"); // notice: extension and classifier not really used in this test... @@ -124,13 +117,13 @@ void testCollectDependencies() throws Exception { CollectResult collectResult = system.collectDependencies(session, collectRequest); List nodes = collectResult.getRoot().getChildren(); - assertEquals(2, nodes.size()); + assertThat(nodes.size()).isEqualTo(2); checkUtSimpleArtifactDependencies( nodes.get(0).getDependency(), nodes.get(1).getDependency()); } @Test - void testResolveArtifact() throws Exception { + void resolveArtifact() throws Exception { Artifact artifact = new DefaultArtifact("ut.simple:artifact:1.0"); ArtifactRequest artifactRequest = new ArtifactRequest(); @@ -152,15 +145,15 @@ void testResolveArtifact() throws Exception { } private void checkArtifactResult(ArtifactResult result, String filename) { - assertFalse(result.isMissing()); - assertTrue(result.isResolved()); + assertThat(result.isMissing()).isFalse(); + assertThat(result.isResolved()).isTrue(); Artifact artifact = result.getArtifact(); - assertNotNull(artifact.getFile()); - assertEquals(filename, artifact.getFile().getName()); + assertThat(artifact.getFile()).isNotNull(); + assertThat(artifact.getFile().getName()).isEqualTo(filename); } @Test - void testResolveArtifacts() throws Exception { + void resolveArtifacts() throws Exception { ArtifactRequest req1 = new ArtifactRequest(); req1.setArtifact(new DefaultArtifact("ut.simple:artifact:1.0")); req1.addRepository(newTestRepository()); @@ -177,38 +170,38 @@ void testResolveArtifacts() throws Exception { List results = system.resolveArtifacts(session, requests); - assertEquals(3, results.size()); + assertThat(results.size()).isEqualTo(3); checkArtifactResult(results.get(0), "artifact-1.0.jar"); checkArtifactResult(results.get(1), "artifact-1.0.zip"); checkArtifactResult(results.get(2), "artifact-1.0-classifier.zip"); } @Test - void testResolveMetadata() throws Exception { + void resolveMetadata() throws Exception { // List resolveMetadata( RepositorySystemSession session, // Collection requests ); } @Test - void testInstall() throws Exception { + void install() throws Exception { // InstallResult install( RepositorySystemSession session, InstallRequest request ) // throws InstallationException; // release, snapshot unique ou non unique, attachment } @Test - void testDeploy() throws Exception { + void deploy() throws Exception { // DeployResult deploy( RepositorySystemSession session, DeployRequest request ) // throws DeploymentException; } @Test - void testNewLocalRepositoryManager() throws Exception { + void newLocalRepositoryManager() throws Exception { // LocalRepositoryManager newLocalRepositoryManager( LocalRepository localRepository ); } @Test - void testNewSyncContext() throws Exception { + void newSyncContext() throws Exception { // SyncContext newSyncContext( RepositorySystemSession session, boolean shared ); } } diff --git a/compat/maven-settings-builder/src/test/java/org/apache/maven/settings/building/DefaultSettingsBuilderFactoryTest.java b/compat/maven-settings-builder/src/test/java/org/apache/maven/settings/building/DefaultSettingsBuilderFactoryTest.java index 2959e4f68243..665a2245c75d 100644 --- a/compat/maven-settings-builder/src/test/java/org/apache/maven/settings/building/DefaultSettingsBuilderFactoryTest.java +++ b/compat/maven-settings-builder/src/test/java/org/apache/maven/settings/building/DefaultSettingsBuilderFactoryTest.java @@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** */ @@ -33,16 +33,16 @@ private File getSettings(String name) { } @Test - void testCompleteWiring() throws Exception { + void completeWiring() throws Exception { SettingsBuilder builder = new DefaultSettingsBuilderFactory().newInstance(); - assertNotNull(builder); + assertThat(builder).isNotNull(); DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); request.setSystemProperties(System.getProperties()); request.setUserSettingsFile(getSettings("simple")); SettingsBuildingResult result = builder.build(request); - assertNotNull(result); - assertNotNull(result.getEffectiveSettings()); + assertThat(result).isNotNull(); + assertThat(result.getEffectiveSettings()).isNotNull(); } } diff --git a/compat/maven-settings-builder/src/test/java/org/apache/maven/settings/validation/DefaultSettingsValidatorTest.java b/compat/maven-settings-builder/src/test/java/org/apache/maven/settings/validation/DefaultSettingsValidatorTest.java index 0feff31d3cbd..7556b101e264 100644 --- a/compat/maven-settings-builder/src/test/java/org/apache/maven/settings/validation/DefaultSettingsValidatorTest.java +++ b/compat/maven-settings-builder/src/test/java/org/apache/maven/settings/validation/DefaultSettingsValidatorTest.java @@ -33,8 +33,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** */ @@ -53,38 +52,38 @@ void tearDown() throws Exception { } private void assertContains(String msg, String substring) { - assertTrue(msg.contains(substring), "\"" + substring + "\" was not found in: " + msg); + assertThat(msg.contains(substring)).as("\"" + substring + "\" was not found in: " + msg).isTrue(); } @Test - void testValidate() { + void validate() { Settings model = new Settings(); Profile prof = new Profile(); prof.setId("xxx"); model.addProfile(prof); SimpleProblemCollector problems = new SimpleProblemCollector(); validator.validate(model, problems); - assertEquals(0, problems.messages.size()); + assertThat(problems.messages.size()).isEqualTo(0); Repository repo = new Repository(org.apache.maven.api.settings.Repository.newInstance(false)); prof.addRepository(repo); problems = new SimpleProblemCollector(); validator.validate(model, problems); - assertEquals(2, problems.messages.size()); + assertThat(problems.messages.size()).isEqualTo(2); repo.setUrl("http://xxx.xxx.com"); problems = new SimpleProblemCollector(); validator.validate(model, problems); - assertEquals(1, problems.messages.size()); + assertThat(problems.messages.size()).isEqualTo(1); repo.setId("xxx"); problems = new SimpleProblemCollector(); validator.validate(model, problems); - assertEquals(0, problems.messages.size()); + assertThat(problems.messages.size()).isEqualTo(0); } @Test - void testValidateMirror() throws Exception { + void validateMirror() throws Exception { Settings settings = new Settings(); Mirror mirror = new Mirror(); mirror.setId("local"); @@ -97,7 +96,7 @@ void testValidateMirror() throws Exception { SimpleProblemCollector problems = new SimpleProblemCollector(); validator.validate(settings, problems); - assertEquals(4, problems.messages.size()); + assertThat(problems.messages.size()).isEqualTo(4); assertContains(problems.messages.get(0), "'mirrors.mirror.id' must not be 'local'"); assertContains(problems.messages.get(1), "'mirrors.mirror.url' for local is missing"); assertContains(problems.messages.get(2), "'mirrors.mirror.mirrorOf' for local is missing"); @@ -105,7 +104,7 @@ void testValidateMirror() throws Exception { } @Test - void testValidateRepository() throws Exception { + void validateRepository() throws Exception { Profile profile = new Profile(); Repository repo = new Repository(); repo.setId("local"); @@ -119,7 +118,7 @@ void testValidateRepository() throws Exception { SimpleProblemCollector problems = new SimpleProblemCollector(); validator.validate(settings, problems); - assertEquals(3, problems.messages.size()); + assertThat(problems.messages.size()).isEqualTo(3); assertContains( problems.messages.get(0), "'profiles.profile[default].repositories.repository.id' must not be 'local'"); assertContains( @@ -131,7 +130,7 @@ void testValidateRepository() throws Exception { } @Test - void testValidateUniqueServerId() throws Exception { + void validateUniqueServerId() throws Exception { Settings settings = new Settings(); Server server1 = new Server(); server1.setId("test"); @@ -142,13 +141,13 @@ void testValidateUniqueServerId() throws Exception { SimpleProblemCollector problems = new SimpleProblemCollector(); validator.validate(settings, problems); - assertEquals(1, problems.messages.size()); + assertThat(problems.messages.size()).isEqualTo(1); assertContains( problems.messages.get(0), "'servers.server.id' must be unique but found duplicate server with id test"); } @Test - void testValidateUniqueProfileId() throws Exception { + void validateUniqueProfileId() throws Exception { Settings settings = new Settings(); Profile profile1 = new Profile(); profile1.setId("test"); @@ -159,14 +158,14 @@ void testValidateUniqueProfileId() throws Exception { SimpleProblemCollector problems = new SimpleProblemCollector(); validator.validate(settings, problems); - assertEquals(1, problems.messages.size()); + assertThat(problems.messages.size()).isEqualTo(1); assertContains( problems.messages.get(0), "'profiles.profile.id' must be unique but found duplicate profile with id test"); } @Test - void testValidateUniqueRepositoryId() throws Exception { + void validateUniqueRepositoryId() throws Exception { Settings settings = new Settings(); Profile profile = new Profile(); profile.setId("pro"); @@ -182,7 +181,7 @@ void testValidateUniqueRepositoryId() throws Exception { SimpleProblemCollector problems = new SimpleProblemCollector(); validator.validate(settings, problems); - assertEquals(1, problems.messages.size()); + assertThat(problems.messages.size()).isEqualTo(1); assertContains( problems.messages.get(0), "'profiles.profile[pro].repositories.repository.id' must be unique" @@ -190,7 +189,7 @@ void testValidateUniqueRepositoryId() throws Exception { } @Test - void testValidateUniqueProxyId() throws Exception { + void validateUniqueProxyId() throws Exception { Settings settings = new Settings(); Proxy proxy = new Proxy(); String id = "foo"; @@ -201,21 +200,21 @@ void testValidateUniqueProxyId() throws Exception { SimpleProblemCollector problems = new SimpleProblemCollector(); validator.validate(settings, problems); - assertEquals(1, problems.messages.size()); + assertThat(problems.messages.size()).isEqualTo(1); assertContains( problems.messages.get(0), "'proxies.proxy.id' must be unique" + " but found duplicate proxy with id " + id); } @Test - void testValidateProxy() throws Exception { + void validateProxy() throws Exception { Settings settings = new Settings(); Proxy proxy1 = new Proxy(); settings.addProxy(proxy1); SimpleProblemCollector problems = new SimpleProblemCollector(); validator.validate(settings, problems); - assertEquals(1, problems.messages.size()); + assertThat(problems.messages.size()).isEqualTo(1); assertContains(problems.messages.get(0), "'proxies.proxy.host' for default is missing"); } diff --git a/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilderTest.java b/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilderTest.java index 8e3fb5d467ea..acadeac1c26c 100644 --- a/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilderTest.java +++ b/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilderTest.java @@ -43,8 +43,7 @@ import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -74,16 +73,16 @@ void onSetup() { } @Test - void testBuildEmptyRequest() throws Exception { + void buildEmptyRequest() throws Exception { ToolchainsBuildingRequest request = new DefaultToolchainsBuildingRequest(); ToolchainsBuildingResult result = toolchainBuilder.build(request); - assertNotNull(result.getEffectiveToolchains()); - assertNotNull(result.getProblems()); - assertEquals(0, result.getProblems().size()); + assertThat(result.getEffectiveToolchains()).isNotNull(); + assertThat(result.getProblems()).isNotNull(); + assertThat(result.getProblems().size()).isEqualTo(0); } @Test - void testBuildRequestWithUserToolchains() throws Exception { + void buildRequestWithUserToolchains() throws Exception { Properties props = new Properties(); props.put("key", "user_value"); ToolchainModel toolchain = new ToolchainModel(); @@ -97,23 +96,20 @@ void testBuildRequestWithUserToolchains() throws Exception { request.setUserToolchainsSource(new StringSource(xml)); ToolchainsBuildingResult result = toolchainBuilder.build(request); - assertNotNull(result.getEffectiveToolchains()); - assertEquals(1, result.getEffectiveToolchains().getToolchains().size()); - assertEquals( - "TYPE", result.getEffectiveToolchains().getToolchains().get(0).getType()); - assertEquals( - "user_value", - result.getEffectiveToolchains() - .getToolchains() - .get(0) - .getProvides() - .get("key")); - assertNotNull(result.getProblems()); - assertEquals(0, result.getProblems().size()); + assertThat(result.getEffectiveToolchains()).isNotNull(); + assertThat(result.getEffectiveToolchains().getToolchains().size()).isEqualTo(1); + assertThat(result.getEffectiveToolchains().getToolchains().get(0).getType()).isEqualTo("TYPE"); + assertThat(result.getEffectiveToolchains() + .getToolchains() + .get(0) + .getProvides() + .get("key")).isEqualTo("user_value"); + assertThat(result.getProblems()).isNotNull(); + assertThat(result.getProblems().size()).isEqualTo(0); } @Test - void testBuildRequestWithGlobalToolchains() throws Exception { + void buildRequestWithGlobalToolchains() throws Exception { Properties props = new Properties(); props.put("key", "global_value"); ToolchainModel toolchain = new ToolchainModel(); @@ -127,23 +123,20 @@ void testBuildRequestWithGlobalToolchains() throws Exception { request.setGlobalToolchainsSource(new StringSource(xml)); ToolchainsBuildingResult result = toolchainBuilder.build(request); - assertNotNull(result.getEffectiveToolchains()); - assertEquals(1, result.getEffectiveToolchains().getToolchains().size()); - assertEquals( - "TYPE", result.getEffectiveToolchains().getToolchains().get(0).getType()); - assertEquals( - "global_value", - result.getEffectiveToolchains() - .getToolchains() - .get(0) - .getProvides() - .get("key")); - assertNotNull(result.getProblems()); - assertEquals(0, result.getProblems().size()); + assertThat(result.getEffectiveToolchains()).isNotNull(); + assertThat(result.getEffectiveToolchains().getToolchains().size()).isEqualTo(1); + assertThat(result.getEffectiveToolchains().getToolchains().get(0).getType()).isEqualTo("TYPE"); + assertThat(result.getEffectiveToolchains() + .getToolchains() + .get(0) + .getProvides() + .get("key")).isEqualTo("global_value"); + assertThat(result.getProblems()).isNotNull(); + assertThat(result.getProblems().size()).isEqualTo(0); } @Test - void testBuildRequestWithBothToolchains() throws Exception { + void buildRequestWithBothToolchains() throws Exception { Properties props = new Properties(); props.put("key", "user_value"); ToolchainModel toolchain = new ToolchainModel(); @@ -167,32 +160,26 @@ void testBuildRequestWithBothToolchains() throws Exception { new StringSource(new DefaultToolchainsXmlFactory().toXmlString(globalResult.getDelegate()))); ToolchainsBuildingResult result = toolchainBuilder.build(request); - assertNotNull(result.getEffectiveToolchains()); - assertEquals(2, result.getEffectiveToolchains().getToolchains().size()); - assertEquals( - "TYPE", result.getEffectiveToolchains().getToolchains().get(0).getType()); - assertEquals( - "user_value", - result.getEffectiveToolchains() - .getToolchains() - .get(0) - .getProvides() - .get("key")); - assertEquals( - "TYPE", result.getEffectiveToolchains().getToolchains().get(1).getType()); - assertEquals( - "global_value", - result.getEffectiveToolchains() - .getToolchains() - .get(1) - .getProvides() - .get("key")); - assertNotNull(result.getProblems()); - assertEquals(0, result.getProblems().size()); + assertThat(result.getEffectiveToolchains()).isNotNull(); + assertThat(result.getEffectiveToolchains().getToolchains().size()).isEqualTo(2); + assertThat(result.getEffectiveToolchains().getToolchains().get(0).getType()).isEqualTo("TYPE"); + assertThat(result.getEffectiveToolchains() + .getToolchains() + .get(0) + .getProvides() + .get("key")).isEqualTo("user_value"); + assertThat(result.getEffectiveToolchains().getToolchains().get(1).getType()).isEqualTo("TYPE"); + assertThat(result.getEffectiveToolchains() + .getToolchains() + .get(1) + .getProvides() + .get("key")).isEqualTo("global_value"); + assertThat(result.getProblems()).isNotNull(); + assertThat(result.getProblems().size()).isEqualTo(0); } @Test - void testStrictToolchainsParseException() throws Exception { + void strictToolchainsParseException() throws Exception { ToolchainsBuildingRequest request = new DefaultToolchainsBuildingRequest(); request.setGlobalToolchainsSource(new StringSource("")); ToolchainsParseException parseException = new ToolchainsParseException("MESSAGE", 4, 2); @@ -201,15 +188,13 @@ void testStrictToolchainsParseException() throws Exception { try { toolchainBuilder.build(request); } catch (ToolchainsBuildingException e) { - assertEquals( - "1 problem was encountered while building the effective toolchains" + LS - + "[FATAL] Non-parseable toolchains (memory): MESSAGE @ line 4, column 2" + LS, - e.getMessage()); + assertThat(e.getMessage()).isEqualTo("1 problem was encountered while building the effective toolchains" + LS + + "[FATAL] Non-parseable toolchains (memory): MESSAGE @ line 4, column 2" + LS); } } @Test - void testIOException() throws Exception { + void iOException() throws Exception { Source src = mock(Source.class); IOException ioException = new IOException("MESSAGE"); doThrow(ioException).when(src).getInputStream(); @@ -221,15 +206,13 @@ void testIOException() throws Exception { try { toolchainBuilder.build(request); } catch (ToolchainsBuildingException e) { - assertEquals( - "1 problem was encountered while building the effective toolchains" + LS - + "[FATAL] Non-readable toolchains LOCATION: MESSAGE" + LS, - e.getMessage()); + assertThat(e.getMessage()).isEqualTo("1 problem was encountered while building the effective toolchains" + LS + + "[FATAL] Non-readable toolchains LOCATION: MESSAGE" + LS); } } @Test - void testEnvironmentVariablesAreInterpolated() throws Exception { + void environmentVariablesAreInterpolated() throws Exception { Properties props = new Properties(); props.put("key", "${env.testKey}"); Xpp3Dom configurationChild = new Xpp3Dom("jdkHome"); @@ -249,23 +232,20 @@ void testEnvironmentVariablesAreInterpolated() throws Exception { ToolchainsBuildingResult result = toolchainBuilder.build(request); String interpolatedValue = "testValue"; - assertEquals( - interpolatedValue, - result.getEffectiveToolchains() - .getToolchains() - .get(0) - .getProvides() - .get("key")); + assertThat(result.getEffectiveToolchains() + .getToolchains() + .get(0) + .getProvides() + .get("key")).isEqualTo(interpolatedValue); org.codehaus.plexus.util.xml.Xpp3Dom toolchainConfiguration = (org.codehaus.plexus.util.xml.Xpp3Dom) result.getEffectiveToolchains().getToolchains().get(0).getConfiguration(); - assertEquals( - interpolatedValue, toolchainConfiguration.getChild("jdkHome").getValue()); - assertNotNull(result.getProblems()); - assertEquals(0, result.getProblems().size()); + assertThat(toolchainConfiguration.getChild("jdkHome").getValue()).isEqualTo(interpolatedValue); + assertThat(result.getProblems()).isNotNull(); + assertThat(result.getProblems().size()).isEqualTo(0); } @Test - void testNonExistingEnvironmentVariablesAreNotInterpolated() throws Exception { + void nonExistingEnvironmentVariablesAreNotInterpolated() throws Exception { Properties props = new Properties(); props.put("key", "${env.testNonExistingKey}"); ToolchainModel toolchain = new ToolchainModel(); @@ -279,19 +259,17 @@ void testNonExistingEnvironmentVariablesAreNotInterpolated() throws Exception { request.setUserToolchainsSource(new StringSource(xml)); ToolchainsBuildingResult result = toolchainBuilder.build(request); - assertEquals( - "${env.testNonExistingKey}", - result.getEffectiveToolchains() - .getToolchains() - .get(0) - .getProvides() - .get("key")); - assertNotNull(result.getProblems()); - assertEquals(0, result.getProblems().size()); + assertThat(result.getEffectiveToolchains() + .getToolchains() + .get(0) + .getProvides() + .get("key")).isEqualTo("${env.testNonExistingKey}"); + assertThat(result.getProblems()).isNotNull(); + assertThat(result.getProblems().size()).isEqualTo(0); } @Test - void testEnvironmentVariablesWithSpecialCharactersAreInterpolated() throws Exception { + void environmentVariablesWithSpecialCharactersAreInterpolated() throws Exception { Properties props = new Properties(); props.put("key", "${env.testSpecialCharactersKey}"); ToolchainModel toolchain = new ToolchainModel(); @@ -306,15 +284,13 @@ void testEnvironmentVariablesWithSpecialCharactersAreInterpolated() throws Excep ToolchainsBuildingResult result = toolchainBuilder.build(request); String interpolatedValue = ""; - assertEquals( - interpolatedValue, - result.getEffectiveToolchains() - .getToolchains() - .get(0) - .getProvides() - .get("key")); - assertNotNull(result.getProblems()); - assertEquals(0, result.getProblems().size()); + assertThat(result.getEffectiveToolchains() + .getToolchains() + .get(0) + .getProvides() + .get("key")).isEqualTo(interpolatedValue); + assertThat(result.getProblems()).isNotNull(); + assertThat(result.getProblems().size()).isEqualTo(0); } static class TestEnvVarSource implements OperatingSystemUtils.EnvVarSource { diff --git a/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/building/ToolchainsBuildingExceptionTest.java b/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/building/ToolchainsBuildingExceptionTest.java index 0ed92bce7e99..1a6055dce1d5 100644 --- a/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/building/ToolchainsBuildingExceptionTest.java +++ b/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/building/ToolchainsBuildingExceptionTest.java @@ -25,47 +25,41 @@ import org.apache.maven.building.ProblemCollectorFactory; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; class ToolchainsBuildingExceptionTest { private static final String LS = System.lineSeparator(); @Test - void testNoProblems() { + void noProblems() { ToolchainsBuildingException e = new ToolchainsBuildingException(Collections.emptyList()); - assertEquals("0 problems were encountered while building the effective toolchains" + LS, e.getMessage()); + assertThat(e.getMessage()).isEqualTo("0 problems were encountered while building the effective toolchains" + LS); } @Test - void testOneProblem() { + void oneProblem() { ProblemCollector problemCollector = ProblemCollectorFactory.newInstance(null); problemCollector.add(Problem.Severity.ERROR, "MESSAGE", 3, 5, new Exception()); ToolchainsBuildingException e = new ToolchainsBuildingException(problemCollector.getProblems()); - assertEquals( - "1 problem was encountered while building the effective toolchains" + LS - + "[ERROR] MESSAGE @ line 3, column 5" + LS, - e.getMessage()); + assertThat(e.getMessage()).isEqualTo("1 problem was encountered while building the effective toolchains" + LS + + "[ERROR] MESSAGE @ line 3, column 5" + LS); } @Test - void testUnknownPositionAndSource() { + void unknownPositionAndSource() { ProblemCollector problemCollector = ProblemCollectorFactory.newInstance(null); problemCollector.add(Problem.Severity.ERROR, "MESSAGE", -1, -1, new Exception()); ToolchainsBuildingException e = new ToolchainsBuildingException(problemCollector.getProblems()); - assertEquals( - "1 problem was encountered while building the effective toolchains" + LS + "[ERROR] MESSAGE" + LS, - e.getMessage()); + assertThat(e.getMessage()).isEqualTo("1 problem was encountered while building the effective toolchains" + LS + "[ERROR] MESSAGE" + LS); } @Test - void testUnknownPosition() { + void unknownPosition() { ProblemCollector problemCollector = ProblemCollectorFactory.newInstance(null); problemCollector.setSource("SOURCE"); problemCollector.add(Problem.Severity.ERROR, "MESSAGE", -1, -1, new Exception()); ToolchainsBuildingException e = new ToolchainsBuildingException(problemCollector.getProblems()); - assertEquals( - "1 problem was encountered while building the effective toolchains" + LS + "[ERROR] MESSAGE @ SOURCE" - + LS, - e.getMessage()); + assertThat(e.getMessage()).isEqualTo("1 problem was encountered while building the effective toolchains" + LS + "[ERROR] MESSAGE @ SOURCE" + + LS); } } diff --git a/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/merge/MavenToolchainMergerTest.java b/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/merge/MavenToolchainMergerTest.java index 3379ef666d12..0c0401426e5a 100644 --- a/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/merge/MavenToolchainMergerTest.java +++ b/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/merge/MavenToolchainMergerTest.java @@ -28,7 +28,7 @@ import org.codehaus.plexus.util.xml.Xpp3Dom; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; class MavenToolchainMergerTest { private MavenToolchainMerger merger = new MavenToolchainMerger(); @@ -36,7 +36,7 @@ class MavenToolchainMergerTest { private DefaultToolchainsReader reader = new DefaultToolchainsReader(); @Test - void testMergeNulls() { + void mergeNulls() { merger.merge(null, null, null); PersistedToolchains pt = new PersistedToolchains(); @@ -45,81 +45,81 @@ void testMergeNulls() { } @Test - void testMergeJdk() throws Exception { + void mergeJdk() throws Exception { try (InputStream isDominant = MavenToolchainMergerTest.class.getResourceAsStream("toolchains-jdks.xml"); InputStream isRecessive = MavenToolchainMergerTest.class.getResourceAsStream("toolchains-jdks.xml")) { PersistedToolchains dominant = read(isDominant); PersistedToolchains recessive = read(isRecessive); - assertEquals(2, dominant.getToolchains().size()); + assertThat(dominant.getToolchains().size()).isEqualTo(2); merger.merge(dominant, recessive, TrackableBase.USER_LEVEL); - assertEquals(2, dominant.getToolchains().size()); + assertThat(dominant.getToolchains().size()).isEqualTo(2); } } @Test - void testMergeJdkExtra() throws Exception { + void mergeJdkExtra() throws Exception { try (InputStream jdksIS = MavenToolchainMergerTest.class.getResourceAsStream("toolchains-jdks.xml"); InputStream jdksExtraIS = MavenToolchainMergerTest.class.getResourceAsStream("toolchains-jdks-extra.xml")) { PersistedToolchains jdks = read(jdksIS); PersistedToolchains jdksExtra = read(jdksExtraIS); - assertEquals(2, jdks.getToolchains().size()); + assertThat(jdks.getToolchains().size()).isEqualTo(2); merger.merge(jdks, jdksExtra, TrackableBase.USER_LEVEL); - assertEquals(4, jdks.getToolchains().size()); - assertEquals(2, jdksExtra.getToolchains().size()); + assertThat(jdks.getToolchains().size()).isEqualTo(4); + assertThat(jdksExtra.getToolchains().size()).isEqualTo(2); } try (InputStream jdksIS = MavenToolchainMergerTest.class.getResourceAsStream("toolchains-jdks.xml"); InputStream jdksExtraIS = MavenToolchainMergerTest.class.getResourceAsStream("toolchains-jdks-extra.xml")) { PersistedToolchains jdks = read(jdksIS); PersistedToolchains jdksExtra = read(jdksExtraIS); - assertEquals(2, jdks.getToolchains().size()); + assertThat(jdks.getToolchains().size()).isEqualTo(2); // switch dominant with recessive merger.merge(jdksExtra, jdks, TrackableBase.USER_LEVEL); - assertEquals(4, jdksExtra.getToolchains().size()); - assertEquals(2, jdks.getToolchains().size()); + assertThat(jdksExtra.getToolchains().size()).isEqualTo(4); + assertThat(jdks.getToolchains().size()).isEqualTo(2); } } @Test - void testMergeJdkExtend() throws Exception { + void mergeJdkExtend() throws Exception { try (InputStream jdksIS = MavenToolchainMergerTest.class.getResourceAsStream("toolchains-jdks.xml"); InputStream jdksExtendIS = MavenToolchainMergerTest.class.getResourceAsStream("toolchains-jdks-extend.xml")) { PersistedToolchains jdks = read(jdksIS); PersistedToolchains jdksExtend = read(jdksExtendIS); - assertEquals(2, jdks.getToolchains().size()); + assertThat(jdks.getToolchains().size()).isEqualTo(2); merger.merge(jdks, jdksExtend, TrackableBase.USER_LEVEL); - assertEquals(2, jdks.getToolchains().size()); + assertThat(jdks.getToolchains().size()).isEqualTo(2); Xpp3Dom config0 = (Xpp3Dom) jdks.getToolchains().get(0).getConfiguration(); - assertEquals("lib/tools.jar", config0.getChild("toolsJar").getValue()); - assertEquals(2, config0.getChildCount()); + assertThat(config0.getChild("toolsJar").getValue()).isEqualTo("lib/tools.jar"); + assertThat(config0.getChildCount()).isEqualTo(2); Xpp3Dom config1 = (Xpp3Dom) jdks.getToolchains().get(1).getConfiguration(); - assertEquals(2, config1.getChildCount()); - assertEquals("lib/classes.jar", config1.getChild("toolsJar").getValue()); - assertEquals(2, jdksExtend.getToolchains().size()); + assertThat(config1.getChildCount()).isEqualTo(2); + assertThat(config1.getChild("toolsJar").getValue()).isEqualTo("lib/classes.jar"); + assertThat(jdksExtend.getToolchains().size()).isEqualTo(2); } try (InputStream jdksIS = MavenToolchainMergerTest.class.getResourceAsStream("toolchains-jdks.xml"); InputStream jdksExtendIS = MavenToolchainMergerTest.class.getResourceAsStream("toolchains-jdks-extend.xml")) { PersistedToolchains jdks = read(jdksIS); PersistedToolchains jdksExtend = read(jdksExtendIS); - assertEquals(2, jdks.getToolchains().size()); + assertThat(jdks.getToolchains().size()).isEqualTo(2); // switch dominant with recessive merger.merge(jdksExtend, jdks, TrackableBase.USER_LEVEL); - assertEquals(2, jdksExtend.getToolchains().size()); + assertThat(jdksExtend.getToolchains().size()).isEqualTo(2); Xpp3Dom config0 = (Xpp3Dom) jdksExtend.getToolchains().get(0).getConfiguration(); - assertEquals("lib/tools.jar", config0.getChild("toolsJar").getValue()); - assertEquals(2, config0.getChildCount()); + assertThat(config0.getChild("toolsJar").getValue()).isEqualTo("lib/tools.jar"); + assertThat(config0.getChildCount()).isEqualTo(2); Xpp3Dom config1 = (Xpp3Dom) jdksExtend.getToolchains().get(1).getConfiguration(); - assertEquals(2, config1.getChildCount()); - assertEquals("lib/classes.jar", config1.getChild("toolsJar").getValue()); - assertEquals(2, jdks.getToolchains().size()); + assertThat(config1.getChildCount()).isEqualTo(2); + assertThat(config1.getChild("toolsJar").getValue()).isEqualTo("lib/classes.jar"); + assertThat(jdks.getToolchains().size()).isEqualTo(2); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/AbstractVersionTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/AbstractVersionTest.java index f18074ec6003..3be51ea7a289 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/AbstractVersionTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/AbstractVersionTest.java @@ -20,8 +20,7 @@ import org.apache.maven.api.Version; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.assertj.core.api.Assertions.assertThat; /** */ @@ -40,21 +39,31 @@ protected void assertOrder(int expected, String version1, String version2) { Version v2 = newVersion(version2); if (expected > 0) { - assertEquals(1, Integer.signum(v1.compareTo(v2)), "expected " + v1 + " > " + v2); - assertEquals(-1, Integer.signum(v2.compareTo(v1)), "expected " + v2 + " < " + v1); - assertNotEquals(v1, v2, "expected " + v1 + " != " + v2); - assertNotEquals(v2, v1, "expected " + v2 + " != " + v1); + assertThat(Integer.signum(v1.compareTo(v2))) + .as("expected " + v1 + " > " + v2) + .isEqualTo(1); + assertThat(Integer.signum(v2.compareTo(v1))) + .as("expected " + v2 + " < " + v1) + .isEqualTo(-1); + assertThat(v2).as("expected " + v1 + " != " + v2).isNotEqualTo(v1); + assertThat(v1).as("expected " + v2 + " != " + v1).isNotEqualTo(v2); } else if (expected < 0) { - assertEquals(-1, Integer.signum(v1.compareTo(v2)), "expected " + v1 + " < " + v2); - assertEquals(1, Integer.signum(v2.compareTo(v1)), "expected " + v2 + " > " + v1); - assertNotEquals(v1, v2, "expected " + v1 + " != " + v2); - assertNotEquals(v2, v1, "expected " + v2 + " != " + v1); + assertThat(Integer.signum(v1.compareTo(v2))) + .as("expected " + v1 + " < " + v2) + .isEqualTo(-1); + assertThat(Integer.signum(v2.compareTo(v1))) + .as("expected " + v2 + " > " + v1) + .isEqualTo(1); + assertThat(v2).as("expected " + v1 + " != " + v2).isNotEqualTo(v1); + assertThat(v1).as("expected " + v2 + " != " + v1).isNotEqualTo(v2); } else { - assertEquals(0, v1.compareTo(v2), "expected " + v1 + " == " + v2); - assertEquals(0, v2.compareTo(v1), "expected " + v2 + " == " + v1); - assertEquals(v1, v2, "expected " + v1 + " == " + v2); - assertEquals(v2, v1, "expected " + v2 + " == " + v1); - assertEquals(v1.hashCode(), v2.hashCode(), "expected #(" + v1 + ") == #(" + v1 + ")"); + assertThat(v1.compareTo(v2)).as("expected " + v1 + " == " + v2).isEqualTo(0); + assertThat(v2.compareTo(v1)).as("expected " + v2 + " == " + v1).isEqualTo(0); + assertThat(v2).as("expected " + v1 + " == " + v2).isEqualTo(v1); + assertThat(v1).as("expected " + v2 + " == " + v1).isEqualTo(v2); + assertThat(v2.hashCode()) + .as("expected #(" + v1 + ") == #(" + v1 + ")") + .isEqualTo(v1.hashCode()); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelVersionParserTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelVersionParserTest.java index 9bceb1926a16..1d55d37d1b30 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelVersionParserTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelVersionParserTest.java @@ -22,15 +22,14 @@ import org.eclipse.aether.util.version.GenericVersionScheme; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; class DefaultModelVersionParserTest { @Test void parseVersion() { Version v = new DefaultModelVersionParser(new GenericVersionScheme()).parseVersion(""); - assertNotNull(v); - assertEquals("", v.toString()); + assertThat(v).isNotNull(); + assertThat(v.toString()).isEqualTo(""); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelXmlFactoryTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelXmlFactoryTest.java index f10d46fdd852..aeb917ab1941 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelXmlFactoryTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelXmlFactoryTest.java @@ -26,9 +26,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; class DefaultModelXmlFactoryTest { @@ -40,7 +39,7 @@ void setUp() { } @Test - void testValidNamespaceWithModelVersion400() throws Exception { + void validNamespaceWithModelVersion400() throws Exception { String xml = """ @@ -51,12 +50,12 @@ void testValidNamespaceWithModelVersion400() throws Exception { XmlReaderRequest.builder().reader(new StringReader(xml)).build(); Model model = factory.read(request); - assertEquals("4.0.0", model.getModelVersion()); - assertEquals("http://maven.apache.org/POM/4.0.0", model.getNamespaceUri()); + assertThat(model.getModelVersion()).isEqualTo("4.0.0"); + assertThat(model.getNamespaceUri()).isEqualTo("http://maven.apache.org/POM/4.0.0"); } @Test - void testValidNamespaceWithModelVersion410() throws Exception { + void validNamespaceWithModelVersion410() throws Exception { String xml = """ @@ -67,12 +66,12 @@ void testValidNamespaceWithModelVersion410() throws Exception { XmlReaderRequest.builder().reader(new StringReader(xml)).build(); Model model = factory.read(request); - assertEquals("4.1.0", model.getModelVersion()); - assertEquals("http://maven.apache.org/POM/4.1.0", model.getNamespaceUri()); + assertThat(model.getModelVersion()).isEqualTo("4.1.0"); + assertThat(model.getNamespaceUri()).isEqualTo("http://maven.apache.org/POM/4.1.0"); } @Test - void testInvalidNamespaceWithModelVersion410() { + void invalidNamespaceWithModelVersion410() { String xml = """ @@ -82,13 +81,16 @@ void testInvalidNamespaceWithModelVersion410() { XmlReaderRequest request = XmlReaderRequest.builder().reader(new StringReader(xml)).build(); - XmlReaderException ex = assertThrows(XmlReaderException.class, () -> factory.read(request)); - assertTrue(ex.getMessage().contains("Invalid namespace 'http://invalid.namespace/4.1.0'")); - assertTrue(ex.getMessage().contains("4.1.0")); + XmlReaderException ex = assertThatExceptionOfType(XmlReaderException.class) + .isThrownBy(() -> factory.read(request)) + .actual(); + assertThat(ex.getMessage().contains("Invalid namespace 'http://invalid.namespace/4.1.0'")) + .isTrue(); + assertThat(ex.getMessage().contains("4.1.0")).isTrue(); } @Test - void testNoNamespaceWithModelVersion400() throws Exception { + void noNamespaceWithModelVersion400() throws Exception { String xml = """ @@ -99,17 +101,18 @@ void testNoNamespaceWithModelVersion400() throws Exception { XmlReaderRequest.builder().reader(new StringReader(xml)).build(); Model model = factory.read(request); - assertEquals("4.0.0", model.getModelVersion()); - assertEquals("", model.getNamespaceUri()); + assertThat(model.getModelVersion()).isEqualTo("4.0.0"); + assertThat(model.getNamespaceUri()).isEqualTo(""); } @Test - void testNullRequest() { - assertThrows(IllegalArgumentException.class, () -> factory.read((XmlReaderRequest) null)); + void nullRequest() { + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> factory.read((XmlReaderRequest) null)); } @Test - void testMalformedModelVersion() throws Exception { + void malformedModelVersion() throws Exception { String xml = """ @@ -120,6 +123,6 @@ void testMalformedModelVersion() throws Exception { XmlReaderRequest.builder().reader(new StringReader(xml)).build(); Model model = factory.read(request); - assertEquals("invalid.version", model.getModelVersion()); + assertThat(model.getModelVersion()).isEqualTo("invalid.version"); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultNodeTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultNodeTest.java index a67fd4727192..87dd65e21318 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultNodeTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultNodeTest.java @@ -27,12 +27,12 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; class DefaultNodeTest { @Test - void testAsString() { + void asString() { InternalSession session = Mockito.mock(InternalSession.class); // Create a basic dependency node @@ -42,21 +42,20 @@ void testAsString() { // Test non-verbose mode DefaultNode defaultNode = new DefaultNode(session, node, false); - assertEquals("org.example:myapp:jar:1.0:compile", defaultNode.asString()); + assertThat(defaultNode.asString()).isEqualTo("org.example:myapp:jar:1.0:compile"); // Test verbose mode with managed version node.setData(DependencyManagerUtils.NODE_DATA_PREMANAGED_VERSION, "0.9"); node.setManagedBits(DependencyNode.MANAGED_VERSION); defaultNode = new DefaultNode(session, node, true); - assertEquals("org.example:myapp:jar:1.0:compile (version managed from 0.9)", defaultNode.asString()); + assertThat(defaultNode.asString()).isEqualTo("org.example:myapp:jar:1.0:compile (version managed from 0.9)"); // Test verbose mode with managed scope node.setData(DependencyManagerUtils.NODE_DATA_PREMANAGED_SCOPE, "runtime"); node.setManagedBits(DependencyNode.MANAGED_VERSION | DependencyNode.MANAGED_SCOPE); defaultNode = new DefaultNode(session, node, true); - assertEquals( - "org.example:myapp:jar:1.0:compile (version managed from 0.9; scope managed from runtime)", - defaultNode.asString()); + assertThat(defaultNode.asString()) + .isEqualTo("org.example:myapp:jar:1.0:compile (version managed from 0.9; scope managed from runtime)"); // Test verbose mode with conflict resolution DefaultDependencyNode winner = @@ -64,6 +63,7 @@ void testAsString() { node.setData(ConflictResolver.NODE_DATA_WINNER, winner); node.setManagedBits(0); defaultNode = new DefaultNode(session, node, true); - assertEquals("(org.example:myapp:jar:1.0:compile - omitted for conflict with 2.0)", defaultNode.asString()); + assertThat(defaultNode.asString()) + .isEqualTo("(org.example:myapp:jar:1.0:compile - omitted for conflict with 2.0)"); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultProblemCollectorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultProblemCollectorTest.java index b6623e033772..b15d30b2ff10 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultProblemCollectorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultProblemCollectorTest.java @@ -24,9 +24,7 @@ import org.apache.maven.api.services.ProblemCollector; import org.junit.jupiter.api.Test; -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.assertj.core.api.Assertions.assertThat; /** * This UT is for {@link ProblemCollector} but here we have implementations for problems. @@ -36,51 +34,51 @@ class DefaultProblemCollectorTest { void severityFatalDetection() { ProblemCollector collector = ProblemCollector.create(5); - assertFalse(collector.hasProblemsFor(BuilderProblem.Severity.WARNING)); - assertFalse(collector.hasErrorProblems()); - assertFalse(collector.hasFatalProblems()); + assertThat(collector.hasProblemsFor(BuilderProblem.Severity.WARNING)).isFalse(); + assertThat(collector.hasErrorProblems()).isFalse(); + assertThat(collector.hasFatalProblems()).isFalse(); collector.reportProblem( new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.FATAL)); // fatal triggers all - assertTrue(collector.hasProblemsFor(BuilderProblem.Severity.WARNING)); - assertTrue(collector.hasErrorProblems()); - assertTrue(collector.hasFatalProblems()); + assertThat(collector.hasProblemsFor(BuilderProblem.Severity.WARNING)).isTrue(); + assertThat(collector.hasErrorProblems()).isTrue(); + assertThat(collector.hasFatalProblems()).isTrue(); } @Test void severityErrorDetection() { ProblemCollector collector = ProblemCollector.create(5); - assertFalse(collector.hasProblemsFor(BuilderProblem.Severity.WARNING)); - assertFalse(collector.hasErrorProblems()); - assertFalse(collector.hasFatalProblems()); + assertThat(collector.hasProblemsFor(BuilderProblem.Severity.WARNING)).isFalse(); + assertThat(collector.hasErrorProblems()).isFalse(); + assertThat(collector.hasFatalProblems()).isFalse(); collector.reportProblem( new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.ERROR)); // error triggers error + warning - assertTrue(collector.hasProblemsFor(BuilderProblem.Severity.WARNING)); - assertTrue(collector.hasErrorProblems()); - assertFalse(collector.hasFatalProblems()); + assertThat(collector.hasProblemsFor(BuilderProblem.Severity.WARNING)).isTrue(); + assertThat(collector.hasErrorProblems()).isTrue(); + assertThat(collector.hasFatalProblems()).isFalse(); } @Test void severityWarningDetection() { ProblemCollector collector = ProblemCollector.create(5); - assertFalse(collector.hasProblemsFor(BuilderProblem.Severity.WARNING)); - assertFalse(collector.hasErrorProblems()); - assertFalse(collector.hasFatalProblems()); + assertThat(collector.hasProblemsFor(BuilderProblem.Severity.WARNING)).isFalse(); + assertThat(collector.hasErrorProblems()).isFalse(); + assertThat(collector.hasFatalProblems()).isFalse(); collector.reportProblem( new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.WARNING)); // warning triggers warning only - assertTrue(collector.hasProblemsFor(BuilderProblem.Severity.WARNING)); - assertFalse(collector.hasErrorProblems()); - assertFalse(collector.hasFatalProblems()); + assertThat(collector.hasProblemsFor(BuilderProblem.Severity.WARNING)).isTrue(); + assertThat(collector.hasErrorProblems()).isFalse(); + assertThat(collector.hasFatalProblems()).isFalse(); } @Test @@ -91,18 +89,22 @@ void lossy() { "source", 0, 0, null, "message " + i, BuilderProblem.Severity.WARNING))); // collector is "full" of warnings - assertFalse(collector.reportProblem( - new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.WARNING))); + assertThat(collector.reportProblem( + new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.WARNING))) + .isFalse(); // but collector will drop warning for more severe issues - assertTrue(collector.reportProblem( - new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.ERROR))); - assertTrue(collector.reportProblem( - new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.FATAL))); + assertThat(collector.reportProblem( + new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.ERROR))) + .isTrue(); + assertThat(collector.reportProblem( + new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.FATAL))) + .isTrue(); // collector is full of warnings, errors and fatal (mixed) - assertFalse(collector.reportProblem( - new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.WARNING))); + assertThat(collector.reportProblem( + new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.WARNING))) + .isFalse(); // fill it up with fatal ones IntStream.range(0, 5) @@ -110,53 +112,58 @@ void lossy() { "source", 0, 0, null, "message " + i, BuilderProblem.Severity.FATAL))); // from now on, only counters work, problems are lost - assertFalse(collector.reportProblem( - new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.WARNING))); - assertFalse(collector.reportProblem( - new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.ERROR))); - assertFalse(collector.reportProblem( - new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.FATAL))); - - assertEquals(17, collector.totalProblemsReported()); - assertEquals(8, collector.problemsReportedFor(BuilderProblem.Severity.WARNING)); - assertEquals(2, collector.problemsReportedFor(BuilderProblem.Severity.ERROR)); - assertEquals(7, collector.problemsReportedFor(BuilderProblem.Severity.FATAL)); + assertThat(collector.reportProblem( + new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.WARNING))) + .isFalse(); + assertThat(collector.reportProblem( + new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.ERROR))) + .isFalse(); + assertThat(collector.reportProblem( + new DefaultBuilderProblem("source", 0, 0, null, "message", BuilderProblem.Severity.FATAL))) + .isFalse(); + + assertThat(collector.totalProblemsReported()).isEqualTo(17); + assertThat(collector.problemsReportedFor(BuilderProblem.Severity.WARNING)) + .isEqualTo(8); + assertThat(collector.problemsReportedFor(BuilderProblem.Severity.ERROR)).isEqualTo(2); + assertThat(collector.problemsReportedFor(BuilderProblem.Severity.FATAL)).isEqualTo(7); // but preserved problems count == capacity - assertEquals(5, collector.problems().count()); + assertThat(collector.problems().count()).isEqualTo(5); } @Test void moreSeverePushOutLeastSevere() { ProblemCollector collector = ProblemCollector.create(5); - assertEquals(0, collector.totalProblemsReported()); - assertEquals(0, collector.problems().count()); + assertThat(collector.totalProblemsReported()).isEqualTo(0); + assertThat(collector.problems().count()).isEqualTo(0); IntStream.range(0, 5) .forEach(i -> collector.reportProblem(new DefaultBuilderProblem( "source", 0, 0, null, "message " + i, BuilderProblem.Severity.WARNING))); - assertEquals(5, collector.totalProblemsReported()); - assertEquals(5, collector.problems().count()); + assertThat(collector.totalProblemsReported()).isEqualTo(5); + assertThat(collector.problems().count()).isEqualTo(5); IntStream.range(0, 5) .forEach(i -> collector.reportProblem(new DefaultBuilderProblem( "source", 0, 0, null, "message " + i, BuilderProblem.Severity.ERROR))); - assertEquals(10, collector.totalProblemsReported()); - assertEquals(5, collector.problems().count()); + assertThat(collector.totalProblemsReported()).isEqualTo(10); + assertThat(collector.problems().count()).isEqualTo(5); IntStream.range(0, 4) .forEach(i -> collector.reportProblem(new DefaultBuilderProblem( "source", 0, 0, null, "message " + i, BuilderProblem.Severity.FATAL))); - assertEquals(14, collector.totalProblemsReported()); - assertEquals(5, collector.problems().count()); + assertThat(collector.totalProblemsReported()).isEqualTo(14); + assertThat(collector.problems().count()).isEqualTo(5); - assertEquals(5, collector.problemsReportedFor(BuilderProblem.Severity.WARNING)); - assertEquals(5, collector.problemsReportedFor(BuilderProblem.Severity.ERROR)); - assertEquals(4, collector.problemsReportedFor(BuilderProblem.Severity.FATAL)); + assertThat(collector.problemsReportedFor(BuilderProblem.Severity.WARNING)) + .isEqualTo(5); + assertThat(collector.problemsReportedFor(BuilderProblem.Severity.ERROR)).isEqualTo(5); + assertThat(collector.problemsReportedFor(BuilderProblem.Severity.FATAL)).isEqualTo(4); - assertEquals(0, collector.problems(BuilderProblem.Severity.WARNING).count()); - assertEquals(1, collector.problems(BuilderProblem.Severity.ERROR).count()); - assertEquals(4, collector.problems(BuilderProblem.Severity.FATAL).count()); + assertThat(collector.problems(BuilderProblem.Severity.WARNING).count()).isEqualTo(0); + assertThat(collector.problems(BuilderProblem.Severity.ERROR).count()).isEqualTo(1); + assertThat(collector.problems(BuilderProblem.Severity.FATAL).count()).isEqualTo(4); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsBuilderFactoryTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsBuilderFactoryTest.java index 5419b27d6287..4bea8e37d706 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsBuilderFactoryTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsBuilderFactoryTest.java @@ -36,7 +36,7 @@ import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** */ @@ -54,10 +54,10 @@ void setup() { } @Test - void testCompleteWiring() { + void completeWiring() { SettingsBuilder builder = new DefaultSettingsBuilder(new DefaultSettingsXmlFactory(), new DefaultInterpolator(), Map.of()); - assertNotNull(builder); + assertThat(builder).isNotNull(); SettingsBuilderRequest request = SettingsBuilderRequest.builder() .session(session) @@ -65,8 +65,8 @@ void testCompleteWiring() { .build(); SettingsBuilderResult result = builder.build(request); - assertNotNull(result); - assertNotNull(result.getEffectiveSettings()); + assertThat(result).isNotNull(); + assertThat(result.getEffectiveSettings()).isNotNull(); } private Path getSettings(String name) { diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsValidatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsValidatorTest.java index f604fe6bb3af..53ae98f2b4a7 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsValidatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsValidatorTest.java @@ -31,7 +31,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; class DefaultSettingsValidatorTest { @@ -43,31 +43,31 @@ void setUp() throws Exception { } @Test - void testValidate() { + void validate() { Profile prof = Profile.newBuilder().id("xxx").build(); Settings model = Settings.newBuilder().profiles(List.of(prof)).build(); ProblemCollector problems = validator.validate(model); - assertEquals(0, problems.totalProblemsReported()); + assertThat(problems.totalProblemsReported()).isEqualTo(0); Repository repo = org.apache.maven.api.settings.Repository.newInstance(false); Settings model2 = Settings.newBuilder() .profiles(List.of(prof.withRepositories(List.of(repo)))) .build(); problems = validator.validate(model2); - assertEquals(2, problems.totalProblemsReported()); + assertThat(problems.totalProblemsReported()).isEqualTo(2); repo = repo.withUrl("http://xxx.xxx.com"); model2 = Settings.newBuilder() .profiles(List.of(prof.withRepositories(List.of(repo)))) .build(); problems = validator.validate(model2); - assertEquals(1, problems.totalProblemsReported()); + assertThat(problems.totalProblemsReported()).isEqualTo(1); repo = repo.withId("xxx"); model2 = Settings.newBuilder() .profiles(List.of(prof.withRepositories(List.of(repo)))) .build(); problems = validator.validate(model2); - assertEquals(0, problems.totalProblemsReported()); + assertThat(problems.totalProblemsReported()).isEqualTo(0); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultToolchainManagerTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultToolchainManagerTest.java index c916d0ca5fcc..7a810418544f 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultToolchainManagerTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultToolchainManagerTest.java @@ -36,9 +36,8 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -80,14 +79,14 @@ void getToolchainsWithValidTypeAndRequirements() { List result = manager.getToolchains(session, "jdk", Map.of("version", "11")); - assertEquals(1, result.size()); - assertEquals(mockToolchain, result.get(0)); + assertThat(result.size()).isEqualTo(1); + assertThat(result.get(0)).isEqualTo(mockToolchain); } @Test void getToolchainsWithInvalidType() { List result = manager.getToolchains(session, "invalid", null); - assertTrue(result.isEmpty()); + assertThat(result.isEmpty()).isTrue(); } @Test @@ -106,8 +105,8 @@ void storeAndRetrieveToolchainFromBuildContext() { manager.storeToolchainToBuildContext(session, mockToolchain); Optional result = manager.getToolchainFromBuildContext(session, "jdk"); - assertTrue(result.isPresent()); - assertEquals(mockToolchain, result.get()); + assertThat(result.isPresent()).isTrue(); + assertThat(result.get()).isEqualTo(mockToolchain); } @Test @@ -115,11 +114,12 @@ void retrieveContextWithoutProject() { when(session.getService(Lookup.class)).thenReturn(lookup); when(lookup.lookupOptional(Project.class)).thenReturn(Optional.empty()); - assertTrue(manager.retrieveContext(session).isEmpty()); + assertThat(manager.retrieveContext(session).isEmpty()).isTrue(); } @Test void getToolchainsWithNullType() { - assertThrows(NullPointerException.class, () -> manager.getToolchains(session, null, null)); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> manager.getToolchains(session, null, null)); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/ModelVersionParserTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/ModelVersionParserTest.java index 6feffa0ae76f..3ba62ea1c075 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/ModelVersionParserTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/ModelVersionParserTest.java @@ -23,13 +23,10 @@ import org.eclipse.aether.util.version.GenericVersionScheme; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; -public class ModelVersionParserTest { +class ModelVersionParserTest { private final DefaultModelVersionParser versionParser = new DefaultModelVersionParser(new GenericVersionScheme()); @@ -38,23 +35,23 @@ private void parseInvalid(String constraint) { versionParser.parseVersionConstraint(constraint); fail("expected exception for constraint " + constraint); } catch (VersionParserException e) { - assertNotNull(e.getMessage()); + assertThat(e.getMessage()).isNotNull(); } } @Test - void testEnumeratedVersions() throws VersionParserException { + void enumeratedVersions() throws VersionParserException { VersionConstraint c = versionParser.parseVersionConstraint("1.0"); - assertEquals("1.0", c.getRecommendedVersion().toString()); - assertTrue(c.contains(versionParser.parseVersion("1.0"))); + assertThat(c.getRecommendedVersion().toString()).isEqualTo("1.0"); + assertThat(c.contains(versionParser.parseVersion("1.0"))).isTrue(); c = versionParser.parseVersionConstraint("[1.0]"); - assertNull(c.getRecommendedVersion()); - assertTrue(c.contains(versionParser.parseVersion("1.0"))); + assertThat(c.getRecommendedVersion()).isNull(); + assertThat(c.contains(versionParser.parseVersion("1.0"))).isTrue(); c = versionParser.parseVersionConstraint("[1.0],[2.0]"); - assertTrue(c.contains(versionParser.parseVersion("1.0"))); - assertTrue(c.contains(versionParser.parseVersion("2.0"))); + assertThat(c.contains(versionParser.parseVersion("1.0"))).isTrue(); + assertThat(c.contains(versionParser.parseVersion("2.0"))).isTrue(); c = versionParser.parseVersionConstraint("[1.0],[2.0],[3.0]"); assertContains(c, "1.0", "2.0", "3.0"); @@ -75,7 +72,9 @@ private void assertNotContains(VersionConstraint c, String... versions) { private void assertContains(String msg, VersionConstraint c, boolean b, String... versions) { for (String v : versions) { - assertEquals(b, c.contains(versionParser.parseVersion(v)), String.format(msg, v)); + assertThat(c.contains(versionParser.parseVersion(v))) + .as(String.format(msg, v)) + .isEqualTo(b); } } @@ -84,18 +83,18 @@ private void assertContains(VersionConstraint c, String... versions) { } @Test - void testInvalid() { + void invalid() { parseInvalid("[1,"); parseInvalid("[1,2],(3,"); parseInvalid("[1,2],3"); } @Test - void testSameUpperAndLowerBound() throws VersionParserException { + void sameUpperAndLowerBound() throws VersionParserException { VersionConstraint c = versionParser.parseVersionConstraint("[1.0]"); - assertEquals("[1.0,1.0]", c.toString()); + assertThat(c.toString()).isEqualTo("[1.0,1.0]"); VersionConstraint c2 = versionParser.parseVersionConstraint(c.toString()); - assertEquals(c, c2); - assertTrue(c.contains(versionParser.parseVersion("1.0"))); + assertThat(c2).isEqualTo(c); + assertThat(c.contains(versionParser.parseVersion("1.0"))).isTrue(); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/RequestTraceHelperTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/RequestTraceHelperTest.java index 33294298ad1f..1ee4397b7984 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/RequestTraceHelperTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/RequestTraceHelperTest.java @@ -23,10 +23,7 @@ import org.eclipse.aether.resolution.ArtifactRequest; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -34,7 +31,7 @@ class RequestTraceHelperTest { @Test - void testEnterWithRequestData() { + void enterWithRequestData() { InternalSession session = mock(InternalSession.class); Request request = mock(Request.class); org.apache.maven.api.services.RequestTrace existingTrace = @@ -44,33 +41,33 @@ void testEnterWithRequestData() { RequestTraceHelper.ResolverTrace result = RequestTraceHelper.enter(session, request); - assertNotNull(result); - assertEquals(existingTrace, result.mvnTrace()); + assertThat(result).isNotNull(); + assertThat(result.mvnTrace()).isEqualTo(existingTrace); verify(session).setCurrentTrace(existingTrace); } @Test - void testInterpretTraceWithArtifactRequest() { + void interpretTraceWithArtifactRequest() { ArtifactRequest artifactRequest = mock(ArtifactRequest.class); RequestTrace trace = RequestTrace.newChild(null, artifactRequest); String result = RequestTraceHelper.interpretTrace(false, trace); - assertTrue(result.startsWith("artifact request for ")); + assertThat(result.startsWith("artifact request for ")).isTrue(); } @Test - void testToMavenWithNullTrace() { - assertNull(RequestTraceHelper.toMaven("test", null)); + void toMavenWithNullTrace() { + assertThat(RequestTraceHelper.toMaven("test", null)).isNull(); } @Test - void testToResolverWithNullTrace() { - assertNull(RequestTraceHelper.toResolver(null)); + void toResolverWithNullTrace() { + assertThat(RequestTraceHelper.toResolver(null)).isNull(); } @Test - void testExitResetsParentTrace() { + void exitResetsParentTrace() { InternalSession session = mock(InternalSession.class); org.apache.maven.api.services.RequestTrace parentTrace = new org.apache.maven.api.services.RequestTrace(null, "parent"); diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/VersionRangeTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/VersionRangeTest.java index 9e1b74ff3edc..a1f7eb5236cd 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/VersionRangeTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/VersionRangeTest.java @@ -25,12 +25,10 @@ import org.eclipse.aether.util.version.GenericVersionScheme; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; -public class VersionRangeTest { +class VersionRangeTest { private ModelVersionParser versionParser = new DefaultModelVersionParser(new GenericVersionScheme()); @@ -51,93 +49,97 @@ private void parseInvalid(String range) { versionParser.parseVersionRange(range); fail(range + " should be invalid"); } catch (VersionParserException e) { - assertTrue(true); + assertThat(true).isTrue(); } } private void assertContains(VersionRange range, String version) { - assertTrue(range.contains(newVersion(version)), range + " should contain " + version); + assertThat(range.contains(newVersion(version))) + .as(range + " should contain " + version) + .isTrue(); } private void assertNotContains(VersionRange range, String version) { - assertFalse(range.contains(newVersion(version)), range + " should not contain " + version); + assertThat(range.contains(newVersion(version))) + .as(range + " should not contain " + version) + .isFalse(); } @Test - void testLowerBoundInclusiveUpperBoundInclusive() { + void lowerBoundInclusiveUpperBoundInclusive() { VersionRange range = parseValid("[1,2]"); assertContains(range, "1"); assertContains(range, "1.1-SNAPSHOT"); assertContains(range, "2"); - assertEquals(range, parseValid(range.toString())); + assertThat(parseValid(range.toString())).isEqualTo(range); } @Test - void testLowerBoundInclusiveUpperBoundExclusive() { + void lowerBoundInclusiveUpperBoundExclusive() { VersionRange range = parseValid("[1.2.3.4.5,1.2.3.4.6)"); assertContains(range, "1.2.3.4.5"); assertNotContains(range, "1.2.3.4.6"); - assertEquals(range, parseValid(range.toString())); + assertThat(parseValid(range.toString())).isEqualTo(range); } @Test - void testLowerBoundExclusiveUpperBoundInclusive() { + void lowerBoundExclusiveUpperBoundInclusive() { VersionRange range = parseValid("(1a,1b]"); assertNotContains(range, "1a"); assertContains(range, "1b"); - assertEquals(range, parseValid(range.toString())); + assertThat(parseValid(range.toString())).isEqualTo(range); } @Test - void testLowerBoundExclusiveUpperBoundExclusive() { + void lowerBoundExclusiveUpperBoundExclusive() { VersionRange range = parseValid("(1,3)"); assertNotContains(range, "1"); assertContains(range, "2-SNAPSHOT"); assertNotContains(range, "3"); - assertEquals(range, parseValid(range.toString())); + assertThat(parseValid(range.toString())).isEqualTo(range); } @Test - void testSingleVersion() { + void singleVersion() { VersionRange range = parseValid("[1]"); assertContains(range, "1"); - assertEquals(range, parseValid(range.toString())); + assertThat(parseValid(range.toString())).isEqualTo(range); range = parseValid("[1,1]"); assertContains(range, "1"); - assertEquals(range, parseValid(range.toString())); + assertThat(parseValid(range.toString())).isEqualTo(range); } @Test - void testSingleWildcardVersion() { + void singleWildcardVersion() { VersionRange range = parseValid("[1.2.*]"); assertContains(range, "1.2-alpha-1"); assertContains(range, "1.2-SNAPSHOT"); assertContains(range, "1.2"); assertContains(range, "1.2.9999999"); assertNotContains(range, "1.3-rc-1"); - assertEquals(range, parseValid(range.toString())); + assertThat(parseValid(range.toString())).isEqualTo(range); } @Test - void testMissingOpenCloseDelimiter() { + void missingOpenCloseDelimiter() { parseInvalid("1.0"); } @Test - void testMissingOpenDelimiter() { + void missingOpenDelimiter() { parseInvalid("1.0]"); parseInvalid("1.0)"); } @Test - void testMissingCloseDelimiter() { + void missingCloseDelimiter() { parseInvalid("[1.0"); parseInvalid("(1.0"); } @Test - void testTooManyVersions() { + void tooManyVersions() { parseInvalid("[1,2,3]"); parseInvalid("(1,2,3)"); parseInvalid("[1,2,3)"); diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/VersionTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/VersionTest.java index 27ad33272838..5a16965578b7 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/VersionTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/VersionTest.java @@ -30,11 +30,11 @@ import org.eclipse.aether.util.version.GenericVersionScheme; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; /** */ -public class VersionTest extends AbstractVersionTest { +class VersionTest extends AbstractVersionTest { private final ModelVersionParser modelVersionParser = new DefaultModelVersionParser(new GenericVersionScheme()); protected Version newVersion(String version) { @@ -42,12 +42,12 @@ protected Version newVersion(String version) { } @Test - void testEmptyVersion() { + void emptyVersion() { assertOrder(AbstractVersionTest.X_EQ_Y, "0", ""); } @Test - void testNumericOrdering() { + void numericOrdering() { assertOrder(AbstractVersionTest.X_LT_Y, "2", "10"); assertOrder(AbstractVersionTest.X_LT_Y, "1.2", "1.10"); assertOrder(AbstractVersionTest.X_LT_Y, "1.0.2", "1.0.10"); @@ -57,14 +57,14 @@ void testNumericOrdering() { } @Test - void testDelimiters() { + void delimiters() { assertOrder(AbstractVersionTest.X_EQ_Y, "1.0", "1-0"); assertOrder(AbstractVersionTest.X_EQ_Y, "1.0", "1_0"); assertOrder(AbstractVersionTest.X_EQ_Y, "1.a", "1a"); } @Test - void testLeadingZerosAreSemanticallyIrrelevant() { + void leadingZerosAreSemanticallyIrrelevant() { assertOrder(AbstractVersionTest.X_EQ_Y, "1", "01"); assertOrder(AbstractVersionTest.X_EQ_Y, "1.2", "1.002"); assertOrder(AbstractVersionTest.X_EQ_Y, "1.2.3", "1.2.0003"); @@ -72,7 +72,7 @@ void testLeadingZerosAreSemanticallyIrrelevant() { } @Test - void testTrailingZerosAreSemanticallyIrrelevant() { + void trailingZerosAreSemanticallyIrrelevant() { assertOrder(AbstractVersionTest.X_EQ_Y, "1", "1.0.0.0.0.0.0.0.0.0.0.0.0.0"); assertOrder(AbstractVersionTest.X_EQ_Y, "1", "1-0-0-0-0-0-0-0-0-0-0-0-0-0"); assertOrder(AbstractVersionTest.X_EQ_Y, "1", "1.0-0.0-0.0-0.0-0.0-0.0-0.0"); @@ -81,7 +81,7 @@ void testTrailingZerosAreSemanticallyIrrelevant() { } @Test - void testTrailingZerosBeforeQualifierAreSemanticallyIrrelevant() { + void trailingZerosBeforeQualifierAreSemanticallyIrrelevant() { assertOrder(AbstractVersionTest.X_EQ_Y, "1.0-ga", "1.0.0-ga"); assertOrder(AbstractVersionTest.X_EQ_Y, "1.0.ga", "1.0.0.ga"); assertOrder(AbstractVersionTest.X_EQ_Y, "1.0ga", "1.0.0ga"); @@ -99,7 +99,7 @@ void testTrailingZerosBeforeQualifierAreSemanticallyIrrelevant() { } @Test - void testTrailingDelimitersAreSemanticallyIrrelevant() { + void trailingDelimitersAreSemanticallyIrrelevant() { assertOrder(AbstractVersionTest.X_EQ_Y, "1", "1............."); assertOrder(AbstractVersionTest.X_EQ_Y, "1", "1-------------"); assertOrder(AbstractVersionTest.X_EQ_Y, "1.0", "1............."); @@ -107,7 +107,7 @@ void testTrailingDelimitersAreSemanticallyIrrelevant() { } @Test - void testInitialDelimiters() { + void initialDelimiters() { assertOrder(AbstractVersionTest.X_EQ_Y, "0.1", ".1"); assertOrder(AbstractVersionTest.X_EQ_Y, "0.0.1", "..1"); assertOrder(AbstractVersionTest.X_EQ_Y, "0.1", "-1"); @@ -115,7 +115,7 @@ void testInitialDelimiters() { } @Test - void testConsecutiveDelimiters() { + void consecutiveDelimiters() { assertOrder(AbstractVersionTest.X_EQ_Y, "1.0.1", "1..1"); assertOrder(AbstractVersionTest.X_EQ_Y, "1.0.0.1", "1...1"); assertOrder(AbstractVersionTest.X_EQ_Y, "1.0.1", "1--1"); @@ -123,18 +123,18 @@ void testConsecutiveDelimiters() { } @Test - void testUnlimitedNumberOfVersionComponents() { + void unlimitedNumberOfVersionComponents() { assertOrder(AbstractVersionTest.X_GT_Y, "1.0.1.2.3.4.5.6.7.8.9.0.1.2.10", "1.0.1.2.3.4.5.6.7.8.9.0.1.2.3"); } @Test - void testUnlimitedNumberOfDigitsInNumericComponent() { + void unlimitedNumberOfDigitsInNumericComponent() { assertOrder( AbstractVersionTest.X_GT_Y, "1.1234567890123456789012345678901", "1.123456789012345678901234567891"); } @Test - void testTransitionFromDigitToLetterAndViceVersaIsEquivalentToDelimiter() { + void transitionFromDigitToLetterAndViceVersaIsEquivalentToDelimiter() { assertOrder(AbstractVersionTest.X_EQ_Y, "1alpha10", "1.alpha.10"); assertOrder(AbstractVersionTest.X_EQ_Y, "1alpha10", "1-alpha-10"); @@ -143,7 +143,7 @@ void testTransitionFromDigitToLetterAndViceVersaIsEquivalentToDelimiter() { } @Test - void testWellKnownQualifierOrdering() { + void wellKnownQualifierOrdering() { assertOrder(AbstractVersionTest.X_EQ_Y, "1-alpha1", "1-a1"); assertOrder(AbstractVersionTest.X_LT_Y, "1-alpha", "1-beta"); assertOrder(AbstractVersionTest.X_EQ_Y, "1-beta1", "1-b1"); @@ -171,7 +171,7 @@ void testWellKnownQualifierOrdering() { } @Test - void testWellKnownQualifierVersusUnknownQualifierOrdering() { + void wellKnownQualifierVersusUnknownQualifierOrdering() { assertOrder(AbstractVersionTest.X_GT_Y, "1-abc", "1-alpha"); assertOrder(AbstractVersionTest.X_GT_Y, "1-abc", "1-beta"); assertOrder(AbstractVersionTest.X_GT_Y, "1-abc", "1-milestone"); @@ -182,7 +182,7 @@ void testWellKnownQualifierVersusUnknownQualifierOrdering() { } @Test - void testWellKnownSingleCharQualifiersOnlyRecognizedIfImmediatelyFollowedByNumber() { + void wellKnownSingleCharQualifiersOnlyRecognizedIfImmediatelyFollowedByNumber() { assertOrder(AbstractVersionTest.X_GT_Y, "1.0a", "1.0"); assertOrder(AbstractVersionTest.X_GT_Y, "1.0-a", "1.0"); assertOrder(AbstractVersionTest.X_GT_Y, "1.0.a", "1.0"); @@ -212,14 +212,14 @@ void testWellKnownSingleCharQualifiersOnlyRecognizedIfImmediatelyFollowedByNumbe } @Test - void testUnknownQualifierOrdering() { + void unknownQualifierOrdering() { assertOrder(AbstractVersionTest.X_LT_Y, "1-abc", "1-abcd"); assertOrder(AbstractVersionTest.X_LT_Y, "1-abc", "1-bcd"); assertOrder(AbstractVersionTest.X_GT_Y, "1-abc", "1-aac"); } @Test - void testCaseInsensitiveOrderingOfQualifiers() { + void caseInsensitiveOrderingOfQualifiers() { assertOrder(AbstractVersionTest.X_EQ_Y, "1.alpha", "1.ALPHA"); assertOrder(AbstractVersionTest.X_EQ_Y, "1.alpha", "1.Alpha"); @@ -252,7 +252,7 @@ void testCaseInsensitiveOrderingOfQualifiers() { } @Test - void testCaseInsensitiveOrderingOfQualifiersIsLocaleIndependent() { + void caseInsensitiveOrderingOfQualifiersIsLocaleIndependent() { Locale orig = Locale.getDefault(); try { Locale[] locales = {Locale.ENGLISH, new Locale("tr")}; @@ -266,7 +266,7 @@ void testCaseInsensitiveOrderingOfQualifiersIsLocaleIndependent() { } @Test - void testQualifierVersusNumberOrdering() { + void qualifierVersusNumberOrdering() { assertOrder(AbstractVersionTest.X_LT_Y, "1-ga", "1-1"); assertOrder(AbstractVersionTest.X_LT_Y, "1.ga", "1.1"); assertOrder(AbstractVersionTest.X_EQ_Y, "1-ga", "1.0"); @@ -286,7 +286,7 @@ void testQualifierVersusNumberOrdering() { } @Test - void testVersionEvolution() { + void versionEvolution() { assertSequence( "0.9.9-SNAPSHOT", "0.9.9", @@ -322,7 +322,7 @@ void testVersionEvolution() { } @Test - void testMinimumSegment() { + void minimumSegment() { assertOrder(AbstractVersionTest.X_LT_Y, "1.min", "1.0-alpha-1"); assertOrder(AbstractVersionTest.X_LT_Y, "1.min", "1.0-SNAPSHOT"); assertOrder(AbstractVersionTest.X_LT_Y, "1.min", "1.0"); @@ -335,7 +335,7 @@ void testMinimumSegment() { } @Test - void testMaximumSegment() { + void maximumSegment() { assertOrder(AbstractVersionTest.X_GT_Y, "1.max", "1.0-alpha-1"); assertOrder(AbstractVersionTest.X_GT_Y, "1.max", "1.0-SNAPSHOT"); assertOrder(AbstractVersionTest.X_GT_Y, "1.max", "1.0"); @@ -351,11 +351,11 @@ void testMaximumSegment() { * UT for MRESOLVER-314. * * Generates random UUID string based versions and tries to sort them. While this test is not as reliable - * as {@link #testCompareUuidVersionStringStream()}, it covers broader range and in case it fails it records + * as {@link #compareUuidVersionStringStream()}, it covers broader range and in case it fails it records * the failed array, so we can investigate more. */ @Test - void testCompareUuidRandom() { + void compareUuidRandom() { for (int j = 0; j < 32; j++) { ArrayList versions = new ArrayList<>(); for (int i = 0; i < 64; i++) { @@ -378,7 +378,7 @@ void testCompareUuidRandom() { * Works on known set that failed before fix, provided by {@link #uuidVersionStringStream()}. */ @Test - void testCompareUuidVersionStringStream() { + void compareUuidVersionStringStream() { // this operation below fails with IAEx if comparison is unstable uuidVersionStringStream().map(this::newVersion).sorted().toList(); } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/cache/SoftIdentityMapTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/cache/SoftIdentityMapTest.java index 6f64e1b95c4b..52f81321c31d 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/cache/SoftIdentityMapTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/cache/SoftIdentityMapTest.java @@ -29,10 +29,9 @@ import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; class SoftIdentityMapTest { private SoftIdentityMap map; @@ -57,9 +56,9 @@ void shouldComputeValueOnlyOnce() { return "different value"; }); - assertEquals("value", result1); - assertEquals("value", result2); - assertEquals(1, computeCount.get()); + assertThat(result1).isEqualTo("value"); + assertThat(result2).isEqualTo("value"); + assertThat(computeCount.get()).isEqualTo(1); } @RepeatedTest(10) @@ -128,14 +127,12 @@ void shouldBeThreadSafe() throws InterruptedException { sink.accept("Final compute count: " + computeCount.get()); sink.accept("Unique results size: " + uniqueResults.size()); - assertEquals( - 1, - computeCount.get(), - "Value should be computed exactly once, but was computed " + computeCount.get() + " times"); - assertEquals( - 1, - uniqueResults.size(), - "All threads should see the same value, but saw " + uniqueResults.size() + " different values"); + assertThat(computeCount.get()) + .as("Value should be computed exactly once, but was computed " + computeCount.get() + " times") + .isEqualTo(1); + assertThat(uniqueResults.size()) + .as("All threads should see the same value, but saw " + uniqueResults.size() + " different values") + .isEqualTo(1); } @Test @@ -144,7 +141,7 @@ void shouldUseIdentityComparison() { String key1 = new String("key"); String key2 = new String("key"); - assertTrue(key1.equals(key2), "Sanity check: keys should be equal"); + assertThat(key2).as("Sanity check: keys should be equal").isEqualTo(key1); assertNotSame(key1, key2, "Sanity check: keys should be distinct objects"); AtomicInteger computeCount = new AtomicInteger(0); @@ -159,7 +156,9 @@ void shouldUseIdentityComparison() { return "value2"; }); - assertEquals(1, computeCount.get(), "Should compute once for equal but distinct keys"); + assertThat(computeCount.get()) + .as("Should compute once for equal but distinct keys") + .isEqualTo(1); } @Test @@ -187,14 +186,16 @@ void shouldHandleSoftReferences() throws InterruptedException { return "new value"; }); - assertEquals(2, computeCount.get(), "Should compute again after original key is garbage collected"); + assertThat(computeCount.get()) + .as("Should compute again after original key is garbage collected") + .isEqualTo(2); } @Test void shouldHandleNullInputs() { - assertThrows(NullPointerException.class, () -> map.computeIfAbsent(null, k -> "value")); + assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> map.computeIfAbsent(null, k -> "value")); Object key = new Object(); - assertThrows(NullPointerException.class, () -> map.computeIfAbsent(key, null)); + assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> map.computeIfAbsent(key, null)); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/ComplexActivationTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/ComplexActivationTest.java index eed8b9fa5ae0..94457a805b41 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/ComplexActivationTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/ComplexActivationTest.java @@ -32,10 +32,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -49,11 +46,11 @@ class ComplexActivationTest { void setup() { session = ApiRunner.createSession(); builder = session.getService(ModelBuilder.class); - assertNotNull(builder); + assertThat(builder).isNotNull(); } @Test - void testAndConditionInActivation() throws Exception { + void andConditionInActivation() throws Exception { ModelBuilderRequest request = ModelBuilderRequest.builder() .session(session) .requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT) @@ -61,25 +58,28 @@ void testAndConditionInActivation() throws Exception { .systemProperties(Map.of("myproperty", "test")) .build(); ModelBuilderResult result = builder.newSession().build(request); - assertNotNull(result); - assertNotNull(result.getEffectiveModel()); - assertEquals("activated-1", result.getEffectiveModel().getProperties().get("profile.file")); - assertNull(result.getEffectiveModel().getProperties().get("profile.miss")); + assertThat(result).isNotNull(); + assertThat(result.getEffectiveModel()).isNotNull(); + assertThat(result.getEffectiveModel().getProperties().get("profile.file")) + .isEqualTo("activated-1"); + assertThat(result.getEffectiveModel().getProperties().get("profile.miss")) + .isNull(); } @Test - public void testConditionExistingAndMissingInActivation() throws Exception { + void conditionExistingAndMissingInActivation() throws Exception { ModelBuilderRequest request = ModelBuilderRequest.builder() .session(session) .requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT) .source(Sources.buildSource(getPom("complexExistsAndMissing"))) .build(); ModelBuilderResult result = builder.newSession().build(request); - assertNotNull(result); - assertTrue(result.getProblemCollector() - .problems() - .anyMatch(p -> p.getSeverity() == BuilderProblem.Severity.WARNING - && p.getMessage().contains("The 'missing' assertion will be ignored."))); + assertThat(result).isNotNull(); + assertThat(result.getProblemCollector() + .problems() + .anyMatch(p -> p.getSeverity() == BuilderProblem.Severity.WARNING + && p.getMessage().contains("The 'missing' assertion will be ignored."))) + .isTrue(); } private Path getPom(String name) { diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultDependencyManagementImporterTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultDependencyManagementImporterTest.java index 8e30494bf779..c13999742db2 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultDependencyManagementImporterTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultDependencyManagementImporterTest.java @@ -28,7 +28,7 @@ class DefaultDependencyManagementImporterTest { @Test - void testUpdateWithImportedFromDependencyLocationAndBomLocationAreNullDependencyReturned() { + void updateWithImportedFromDependencyLocationAndBomLocationAreNullDependencyReturned() { final Dependency dependency = Dependency.newBuilder().build(); final DependencyManagement depMgmt = DependencyManagement.newBuilder().build(); final Dependency result = DefaultDependencyManagementImporter.updateWithImportedFrom(dependency, depMgmt); @@ -37,7 +37,7 @@ void testUpdateWithImportedFromDependencyLocationAndBomLocationAreNullDependency } @Test - void testUpdateWithImportedFromDependencyManagementAndDependencyHaveSameSourceDependencyImportedFromSameSource() { + void updateWithImportedFromDependencyManagementAndDependencyHaveSameSourceDependencyImportedFromSameSource() { final InputSource source = new InputSource("SINGLE_SOURCE", ""); final Dependency dependency = Dependency.newBuilder() .location("", new InputLocation(1, 1, source)) @@ -54,7 +54,7 @@ void testUpdateWithImportedFromDependencyManagementAndDependencyHaveSameSourceDe } @Test - public void testUpdateWithImportedFromSingleLevelImportedFromSet() { + void updateWithImportedFromSingleLevelImportedFromSet() { // Arrange final InputSource dependencySource = new InputSource("DEPENDENCY", "DEPENDENCY"); final InputSource bomSource = new InputSource("BOM", "BOM"); @@ -75,7 +75,7 @@ public void testUpdateWithImportedFromSingleLevelImportedFromSet() { } @Test - public void testUpdateWithImportedFromMultiLevelImportedFromSetChanged() { + void updateWithImportedFromMultiLevelImportedFromSetChanged() { // Arrange final InputSource bomSource = new InputSource("BOM", "BOM"); final InputSource intermediateSource = @@ -99,7 +99,7 @@ public void testUpdateWithImportedFromMultiLevelImportedFromSetChanged() { } @Test - public void testUpdateWithImportedFromMultiLevelAlreadyFoundInDifferentSourceImportedFromSetMaintained() { + void updateWithImportedFromMultiLevelAlreadyFoundInDifferentSourceImportedFromSetMaintained() { // Arrange final InputSource bomSource = new InputSource("BOM", "BOM"); final InputSource intermediateSource = diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultInterpolatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultInterpolatorTest.java index 9d332e9a5194..1bcf09b701aa 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultInterpolatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultInterpolatorTest.java @@ -26,13 +26,13 @@ import org.apache.maven.api.services.InterpolatorException; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; class DefaultInterpolatorTest { @Test - void testBasicSubstitution() { + void basicSubstitution() { Map props = new HashMap<>(); props.put("key0", "value0"); props.put("key1", "${value1}"); @@ -40,67 +40,66 @@ void testBasicSubstitution() { performSubstitution(props, Map.of("value1", "sub_value1")::get); - assertEquals("value0", props.get("key0")); - assertEquals("sub_value1", props.get("key1")); - assertEquals("", props.get("key2")); + assertThat(props.get("key0")).isEqualTo("value0"); + assertThat(props.get("key1")).isEqualTo("sub_value1"); + assertThat(props.get("key2")).isEqualTo(""); } @Test - void testBasicSubstitutionWithContext() { + void basicSubstitutionWithContext() { HashMap props = new HashMap<>(); props.put("key0", "value0"); props.put("key1", "${value1}"); performSubstitution(props, Map.of("value1", "sub_value1")::get); - assertEquals("value0", props.get("key0")); - assertEquals("sub_value1", props.get("key1")); + assertThat(props.get("key0")).isEqualTo("value0"); + assertThat(props.get("key1")).isEqualTo("sub_value1"); } @Test - void testSubstitutionFailures() { - assertEquals("a}", substVars("a}", "b")); - assertEquals("${a", substVars("${a", "b")); + void substitutionFailures() { + assertThat(substVars("a}", "b")).isEqualTo("a}"); + assertThat(substVars("${a", "b")).isEqualTo("${a"); } @Test - void testEmptyVariable() { - assertEquals("", substVars("${}", "b")); + void emptyVariable() { + assertThat(substVars("${}", "b")).isEqualTo(""); } @Test - void testInnerSubst() { - assertEquals("c", substVars("${${a}}", "z", Map.of("a", "b", "b", "c"))); + void innerSubst() { + assertThat(substVars("${${a}}", "z", Map.of("a", "b", "b", "c"))).isEqualTo("c"); } @Test - void testSubstLoop() { - assertThrows( - InterpolatorException.class, - () -> substVars("${a}", "a"), - "Expected substVars() to throw an InterpolatorException, but it didn't"); + void substLoop() { + assertThatExceptionOfType(InterpolatorException.class) + .as("Expected substVars() to throw an InterpolatorException, but it didn't") + .isThrownBy(() -> substVars("${a}", "a")); } @Test - void testLoopEmpty() { - assertEquals("${a}", substVars("${a}", null, null, null, false)); + void loopEmpty() { + assertThat(substVars("${a}", null, null, null, false)).isEqualTo("${a}"); } @Test - void testLoopEmpty2() { - assertEquals("${a}", substVars("${a}", null, null, null, false)); + void loopEmpty2() { + assertThat(substVars("${a}", null, null, null, false)).isEqualTo("${a}"); } @Test - void testSubstitutionEscape() { - assertEquals("${a}", substVars("$\\{a${#}\\}", "b")); - assertEquals("${a}", substVars("$\\{a\\}${#}", "b")); - assertEquals("${a}", substVars("$\\{a\\}", "b")); - assertEquals("\\\\", substVars("\\\\", "b")); + void substitutionEscape() { + assertThat(substVars("$\\{a${#}\\}", "b")).isEqualTo("${a}"); + assertThat(substVars("$\\{a\\}${#}", "b")).isEqualTo("${a}"); + assertThat(substVars("$\\{a\\}", "b")).isEqualTo("${a}"); + assertThat(substVars("\\\\", "b")).isEqualTo("\\\\"); } @Test - void testSubstitutionOrder() { + void substitutionOrder() { LinkedHashMap map1 = new LinkedHashMap<>(); map1.put("a", "$\\\\{var}"); map1.put("abc", "${ab}c"); @@ -113,39 +112,39 @@ void testSubstitutionOrder() { map2.put("abc", "${ab}c"); performSubstitution(map2); - assertEquals(map1, map2); + assertThat(map2).isEqualTo(map1); } @Test - void testMultipleEscapes() { + void multipleEscapes() { LinkedHashMap map1 = new LinkedHashMap<>(); map1.put("a", "$\\\\{var}"); map1.put("abc", "${ab}c"); map1.put("ab", "${a}b"); performSubstitution(map1); - assertEquals("$\\{var}", map1.get("a")); - assertEquals("$\\{var}b", map1.get("ab")); - assertEquals("$\\{var}bc", map1.get("abc")); + assertThat(map1.get("a")).isEqualTo("$\\{var}"); + assertThat(map1.get("ab")).isEqualTo("$\\{var}b"); + assertThat(map1.get("abc")).isEqualTo("$\\{var}bc"); } @Test - void testPreserveUnresolved() { + void preserveUnresolved() { Map props = new HashMap<>(); props.put("a", "${b}"); - assertEquals("", substVars("${b}", "a", props, null, true)); - assertEquals("${b}", substVars("${b}", "a", props, null, false)); + assertThat(substVars("${b}", "a", props, null, true)).isEqualTo(""); + assertThat(substVars("${b}", "a", props, null, false)).isEqualTo("${b}"); props.put("b", "c"); - assertEquals("c", substVars("${b}", "a", props, null, true)); - assertEquals("c", substVars("${b}", "a", props, null, false)); + assertThat(substVars("${b}", "a", props, null, true)).isEqualTo("c"); + assertThat(substVars("${b}", "a", props, null, false)).isEqualTo("c"); props.put("c", "${d}${d}"); - assertEquals("${d}${d}", substVars("${d}${d}", "c", props, null, false)); + assertThat(substVars("${d}${d}", "c", props, null, false)).isEqualTo("${d}${d}"); } @Test - void testExpansion() { + void expansion() { Map props = new LinkedHashMap<>(); props.put("a", "foo"); props.put("b", ""); @@ -160,17 +159,17 @@ void testExpansion() { performSubstitution(props); - assertEquals("foo", props.get("a_cm")); - assertEquals("bar", props.get("b_cm")); - assertEquals("bar", props.get("c_cm")); + assertThat(props.get("a_cm")).isEqualTo("foo"); + assertThat(props.get("b_cm")).isEqualTo("bar"); + assertThat(props.get("c_cm")).isEqualTo("bar"); - assertEquals("bar", props.get("a_cp")); - assertEquals("", props.get("b_cp")); - assertEquals("", props.get("c_cp")); + assertThat(props.get("a_cp")).isEqualTo("bar"); + assertThat(props.get("b_cp")).isEqualTo(""); + assertThat(props.get("c_cp")).isEqualTo(""); } @Test - void testTernary() { + void ternary() { Map props; props = new LinkedHashMap<>(); @@ -178,7 +177,7 @@ void testTernary() { props.put("bar", "-BAR"); props.put("version", "1.0${release:+${foo}:-${bar}}"); performSubstitution(props); - assertEquals("1.0-BAR", props.get("version")); + assertThat(props.get("version")).isEqualTo("1.0-BAR"); props = new LinkedHashMap<>(); props.put("release", "true"); @@ -186,14 +185,14 @@ void testTernary() { props.put("bar", "-BAR"); props.put("version", "1.0${release:+${foo}:-${bar}}"); performSubstitution(props); - assertEquals("1.0-FOO", props.get("version")); + assertThat(props.get("version")).isEqualTo("1.0-FOO"); props = new LinkedHashMap<>(); props.put("foo", ""); props.put("bar", "-BAR"); props.put("version", "1.0${release:+${foo}:-${bar}}"); performSubstitution(props); - assertEquals("1.0-BAR", props.get("version")); + assertThat(props.get("version")).isEqualTo("1.0-BAR"); props = new LinkedHashMap<>(); props.put("release", "true"); @@ -201,22 +200,22 @@ void testTernary() { props.put("bar", "-BAR"); props.put("version", "1.0${release:+${foo}:-${bar}}"); performSubstitution(props); - assertEquals("1.0", props.get("version")); + assertThat(props.get("version")).isEqualTo("1.0"); props = new LinkedHashMap<>(); props.put("version", "1.0${release:+:--BAR}"); performSubstitution(props); - assertEquals("1.0-BAR", props.get("version")); + assertThat(props.get("version")).isEqualTo("1.0-BAR"); props = new LinkedHashMap<>(); props.put("release", "true"); props.put("version", "1.0${release:+:--BAR}"); performSubstitution(props); - assertEquals("1.0", props.get("version")); + assertThat(props.get("version")).isEqualTo("1.0"); } @Test - void testXdg() { + void xdg() { Map props; props = new LinkedHashMap<>(); @@ -225,7 +224,7 @@ void testXdg() { "maven.user.config", "${env.MAVEN_XDG:+${env.XDG_CONFIG_HOME:-${user.home}/.config/maven}:-${user.home}/.m2}"); performSubstitution(props); - assertEquals("/Users/gnodet/.m2", props.get("maven.user.config")); + assertThat(props.get("maven.user.config")).isEqualTo("/Users/gnodet/.m2"); props = new LinkedHashMap<>(); props.put("user.home", "/Users/gnodet"); @@ -234,7 +233,7 @@ void testXdg() { "${env.MAVEN_XDG:+${env.XDG_CONFIG_HOME:-${user.home}/.config/maven}:-${user.home}/.m2}"); props.put("env.MAVEN_XDG", "true"); performSubstitution(props); - assertEquals("/Users/gnodet/.config/maven", props.get("maven.user.config")); + assertThat(props.get("maven.user.config")).isEqualTo("/Users/gnodet/.config/maven"); props = new LinkedHashMap<>(); props.put("user.home", "/Users/gnodet"); @@ -244,7 +243,7 @@ void testXdg() { props.put("env.MAVEN_XDG", "true"); props.put("env.XDG_CONFIG_HOME", "/Users/gnodet/.xdg/maven"); performSubstitution(props); - assertEquals("/Users/gnodet/.xdg/maven", props.get("maven.user.config")); + assertThat(props.get("maven.user.config")).isEqualTo("/Users/gnodet/.xdg/maven"); } private void performSubstitution(Map props) { diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderResultTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderResultTest.java index cd7c0c5c2063..99c83362b1bb 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderResultTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderResultTest.java @@ -28,10 +28,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; class DefaultModelBuilderResultTest { @@ -57,56 +54,56 @@ void setUp() { } @Test - void testModelLifecycle() { + void modelLifecycle() { // Test initial state - assertNull(result.getSource()); - assertNull(result.getFileModel()); - assertNull(result.getRawModel()); - assertNull(result.getEffectiveModel()); - assertEquals(0L, result.getProblemCollector().problems().count()); + assertThat(result.getSource()).isNull(); + assertThat(result.getFileModel()).isNull(); + assertThat(result.getRawModel()).isNull(); + assertThat(result.getEffectiveModel()).isNull(); + assertThat(result.getProblemCollector().problems().count()).isEqualTo(0L); // Set and verify source result.setSource(source); - assertSame(source, result.getSource()); + assertThat(result.getSource()).isSameAs(source); // Set and verify file model result.setFileModel(fileModel); - assertSame(fileModel, result.getFileModel()); + assertThat(result.getFileModel()).isSameAs(fileModel); // Set and verify raw model result.setRawModel(rawModel); - assertSame(rawModel, result.getRawModel()); + assertThat(result.getRawModel()).isSameAs(rawModel); // Set and verify effective model result.setEffectiveModel(effectiveModel); - assertSame(effectiveModel, result.getEffectiveModel()); + assertThat(result.getEffectiveModel()).isSameAs(effectiveModel); } @Test - void testProblemCollection() { + void problemCollection() { ModelProblem problem = mock(ModelProblem.class); Mockito.when(problem.getSeverity()).thenReturn(BuilderProblem.Severity.ERROR); problemCollector.reportProblem(problem); - assertEquals(1, result.getProblemCollector().problems().count()); - assertSame(problem, result.getProblemCollector().problems().findFirst().get()); + assertThat(result.getProblemCollector().problems().count()).isEqualTo(1); + assertThat(result.getProblemCollector().problems().findFirst().get()).isSameAs(problem); } @Test - void testChildrenManagement() { + void childrenManagement() { DefaultModelBuilderResult child1 = new DefaultModelBuilderResult(request, problemCollector); DefaultModelBuilderResult child2 = new DefaultModelBuilderResult(request, problemCollector); result.getChildren().add(child1); result.getChildren().add(child2); - assertEquals(2, result.getChildren().size()); - assertTrue(result.getChildren().contains(child1)); - assertTrue(result.getChildren().contains(child2)); + assertThat(result.getChildren().size()).isEqualTo(2); + assertThat(result.getChildren().contains(child1)).isTrue(); + assertThat(result.getChildren().contains(child2)).isTrue(); } @Test - void testRequestAssociation() { - assertSame(request, result.getRequest()); + void requestAssociation() { + assertThat(result.getRequest()).isSameAs(request); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderTest.java index 2b012185c4bf..e46255c66baf 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderTest.java @@ -37,8 +37,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -52,23 +51,24 @@ class DefaultModelBuilderTest { void setup() { session = ApiRunner.createSession(); builder = session.getService(ModelBuilder.class); - assertNotNull(builder); + assertThat(builder).isNotNull(); } @Test - public void testPropertiesAndProfiles() { + void propertiesAndProfiles() { ModelBuilderRequest request = ModelBuilderRequest.builder() .session(session) .requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT) .source(Sources.buildSource(getPom("props-and-profiles"))) .build(); ModelBuilderResult result = builder.newSession().build(request); - assertNotNull(result); - assertEquals("21", result.getEffectiveModel().getProperties().get("maven.compiler.release")); + assertThat(result).isNotNull(); + assertThat(result.getEffectiveModel().getProperties().get("maven.compiler.release")) + .isEqualTo("21"); } @Test - public void testMergeRepositories() throws Exception { + void mergeRepositories() throws Exception { // this is here only to trigger mainSession creation; unrelated ModelBuilderRequest request = ModelBuilderRequest.builder() .session(session) @@ -89,7 +89,7 @@ public void testMergeRepositories() throws Exception { List repositories; // before merge repositories = (List) repositoriesField.get(state); - assertEquals(1, repositories.size()); // central + assertThat(repositories.size()).isEqualTo(1); // central Model model = Model.newBuilder() .repositories(Arrays.asList( @@ -106,12 +106,12 @@ public void testMergeRepositories() throws Exception { // after merge repositories = (List) repositoriesField.get(state); - assertEquals(3, repositories.size()); - assertEquals("first", repositories.get(0).getId()); - assertEquals("https://some.repo", repositories.get(0).getUrl()); // interpolated - assertEquals("second", repositories.get(1).getId()); - assertEquals("${secondParentRepo}", repositories.get(1).getUrl()); // un-interpolated (no source) - assertEquals("central", repositories.get(2).getId()); // default + assertThat(repositories.size()).isEqualTo(3); + assertThat(repositories.get(0).getId()).isEqualTo("first"); + assertThat(repositories.get(0).getUrl()).isEqualTo("https://some.repo"); // interpolated + assertThat(repositories.get(1).getId()).isEqualTo("second"); + assertThat(repositories.get(1).getUrl()).isEqualTo("${secondParentRepo}"); // un-interpolated (no source) + assertThat(repositories.get(2).getId()).isEqualTo("central"); // default } private Path getPom(String name) { diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelInterpolatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelInterpolatorTest.java index 7afe7a82e2de..b5ee968de52d 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelInterpolatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelInterpolatorTest.java @@ -56,10 +56,8 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; /** */ @@ -71,30 +69,28 @@ class DefaultModelInterpolatorTest { AtomicReference rootDirectory; // used in TestRootLocator below @BeforeEach - public void setUp() { + void setUp() { context = new HashMap<>(); context.put("basedir", "myBasedir"); context.put("anotherdir", "anotherBasedir"); context.put("project.baseUri", "myBaseUri"); - session = ApiRunner.createSession(injector -> { - injector.bindInstance(DefaultModelInterpolatorTest.class, this); - }); + session = ApiRunner.createSession(injector -> injector.bindInstance(DefaultModelInterpolatorTest.class, this)); interpolator = session.getService(Lookup.class).lookup(DefaultModelInterpolator.class); } protected void assertProblemFree(SimpleProblemCollector collector) { - assertEquals(0, collector.getErrors().size(), "Expected no errors"); - assertEquals(0, collector.getWarnings().size(), "Expected no warnings"); - assertEquals(0, collector.getFatals().size(), "Expected no fatals"); + assertThat(collector.getErrors().size()).as("Expected no errors").isEqualTo(0); + assertThat(collector.getWarnings().size()).as("Expected no warnings").isEqualTo(0); + assertThat(collector.getFatals().size()).as("Expected no fatals").isEqualTo(0); } @SuppressWarnings("SameParameterValue") protected void assertCollectorState( int numFatals, int numErrors, int numWarnings, SimpleProblemCollector collector) { - assertEquals(numErrors, collector.getErrors().size(), "Errors"); - assertEquals(numWarnings, collector.getWarnings().size(), "Warnings"); - assertEquals(numFatals, collector.getFatals().size(), "Fatals"); + assertThat(collector.getErrors().size()).as("Errors").isEqualTo(numErrors); + assertThat(collector.getWarnings().size()).as("Warnings").isEqualTo(numWarnings); + assertThat(collector.getFatals().size()).as("Fatals").isEqualTo(numFatals); } private ModelBuilderRequest.ModelBuilderRequestBuilder createModelBuildingRequest(Map p) { @@ -108,7 +104,7 @@ private ModelBuilderRequest.ModelBuilderRequestBuilder createModelBuildingReques } @Test - public void testDefaultBuildTimestampFormatShouldFormatTimeIn24HourFormat() { + void defaultBuildTimestampFormatShouldFormatTimeIn24HourFormat() { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("Etc/UTC")); cal.set(Calendar.HOUR, 12); @@ -135,12 +131,12 @@ public void testDefaultBuildTimestampFormatShouldFormatTimeIn24HourFormat() { DateTimeFormatter format = DateTimeFormatter.ofPattern(MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT) .withZone(ZoneId.of("UTC")); - assertEquals("1976-11-11T00:16:00Z", format.format(firstTestDate)); - assertEquals("1976-11-11T23:16:00Z", format.format(secondTestDate)); + assertThat(format.format(firstTestDate)).isEqualTo("1976-11-11T00:16:00Z"); + assertThat(format.format(secondTestDate)).isEqualTo("1976-11-11T23:16:00Z"); } @Test - public void testDefaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover() { + void defaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover() { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("Europe/Berlin")); @@ -159,12 +155,12 @@ public void testDefaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover() { DateTimeFormatter format = DateTimeFormatter.ofPattern(MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT) .withZone(ZoneId.of("UTC")); - assertEquals("2014-06-15T23:16:00Z", format.format(firstTestDate)); - assertEquals("2014-11-16T00:16:00Z", format.format(secondTestDate)); + assertThat(format.format(firstTestDate)).isEqualTo("2014-06-15T23:16:00Z"); + assertThat(format.format(secondTestDate)).isEqualTo("2014-11-16T00:16:00Z"); } @Test - public void testShouldNotThrowExceptionOnReferenceToNonExistentValue() throws Exception { + void shouldNotThrowExceptionOnReferenceToNonExistentValue() throws Exception { Scm scm = Scm.newBuilder().connection("${test}/somepath").build(); Model model = Model.newBuilder().scm(scm).build(); @@ -173,11 +169,11 @@ public void testShouldNotThrowExceptionOnReferenceToNonExistentValue() throws Ex model, Paths.get("."), createModelBuildingRequest(context).build(), collector); assertProblemFree(collector); - assertEquals("${test}/somepath", out.getScm().getConnection()); + assertThat(out.getScm().getConnection()).isEqualTo("${test}/somepath"); } @Test - public void testShouldThrowExceptionOnRecursiveScmConnectionReference() throws Exception { + void shouldThrowExceptionOnRecursiveScmConnectionReference() throws Exception { Scm scm = Scm.newBuilder() .connection("${project.scm.connection}/somepath") .build(); @@ -190,7 +186,7 @@ public void testShouldThrowExceptionOnRecursiveScmConnectionReference() throws E } @Test - public void testShouldNotThrowExceptionOnReferenceToValueContainingNakedExpression() throws Exception { + void shouldNotThrowExceptionOnReferenceToValueContainingNakedExpression() throws Exception { Scm scm = Scm.newBuilder().connection("${test}/somepath").build(); Map props = new HashMap<>(); props.put("test", "test"); @@ -202,7 +198,7 @@ public void testShouldNotThrowExceptionOnReferenceToValueContainingNakedExpressi assertProblemFree(collector); - assertEquals("test/somepath", out.getScm().getConnection()); + assertThat(out.getScm().getConnection()).isEqualTo("test/somepath"); } @Test @@ -217,11 +213,11 @@ void shouldInterpolateOrganizationNameCorrectly() throws Exception { Model out = interpolator.interpolateModel( model, Paths.get("."), createModelBuildingRequest(context).build(), new SimpleProblemCollector()); - assertEquals(orgName + " Tools", out.getName()); + assertThat(out.getName()).isEqualTo(orgName + " Tools"); } @Test - public void shouldInterpolateDependencyVersionToSetSameAsProjectVersion() throws Exception { + void shouldInterpolateDependencyVersionToSetSameAsProjectVersion() throws Exception { Model model = Model.newBuilder() .version("3.8.1") .dependencies(Collections.singletonList( @@ -233,11 +229,11 @@ public void shouldInterpolateDependencyVersionToSetSameAsProjectVersion() throws model, Paths.get("."), createModelBuildingRequest(context).build(), collector); assertCollectorState(0, 0, 0, collector); - assertEquals("3.8.1", (out.getDependencies().get(0)).getVersion()); + assertThat((out.getDependencies().get(0)).getVersion()).isEqualTo("3.8.1"); } @Test - public void testShouldNotInterpolateDependencyVersionWithInvalidReference() throws Exception { + void shouldNotInterpolateDependencyVersionWithInvalidReference() throws Exception { Model model = Model.newBuilder() .version("3.8.1") .dependencies(Collections.singletonList( @@ -249,11 +245,11 @@ public void testShouldNotInterpolateDependencyVersionWithInvalidReference() thro model, Paths.get("."), createModelBuildingRequest(context).build(), collector); assertProblemFree(collector); - assertEquals("${something}", (out.getDependencies().get(0)).getVersion()); + assertThat((out.getDependencies().get(0)).getVersion()).isEqualTo("${something}"); } @Test - public void testTwoReferences() throws Exception { + void twoReferences() throws Exception { Model model = Model.newBuilder() .version("3.8.1") .artifactId("foo") @@ -267,11 +263,11 @@ public void testTwoReferences() throws Exception { model, Paths.get("."), createModelBuildingRequest(context).build(), collector); assertCollectorState(0, 0, 0, collector); - assertEquals("foo-3.8.1", (out.getDependencies().get(0)).getVersion()); + assertThat((out.getDependencies().get(0)).getVersion()).isEqualTo("foo-3.8.1"); } @Test - public void testProperty() throws Exception { + void property() throws Exception { Model model = Model.newBuilder() .version("3.8.1") .artifactId("foo") @@ -288,13 +284,11 @@ public void testProperty() throws Exception { collector); assertProblemFree(collector); - assertEquals( - "file://localhost/anotherBasedir/temp-repo", - (out.getRepositories().get(0)).getUrl()); + assertThat((out.getRepositories().get(0)).getUrl()).isEqualTo("file://localhost/anotherBasedir/temp-repo"); } @Test - public void testBasedirUnx() throws Exception { + void basedirUnx() throws Exception { FileSystem fs = Jimfs.newFileSystem(Configuration.unix()); Path projectBasedir = fs.getPath("projectBasedir"); @@ -310,13 +304,11 @@ public void testBasedirUnx() throws Exception { model, projectBasedir, createModelBuildingRequest(context).build(), collector); assertProblemFree(collector); - assertEquals( - projectBasedir.toAbsolutePath() + "/temp-repo", - (out.getRepositories().get(0)).getUrl()); + assertThat((out.getRepositories().get(0)).getUrl()).isEqualTo(projectBasedir.toAbsolutePath() + "/temp-repo"); } @Test - public void testBasedirWin() throws Exception { + void basedirWin() throws Exception { FileSystem fs = Jimfs.newFileSystem(Configuration.windows()); Path projectBasedir = fs.getPath("projectBasedir"); @@ -332,13 +324,11 @@ public void testBasedirWin() throws Exception { model, projectBasedir, createModelBuildingRequest(context).build(), collector); assertProblemFree(collector); - assertEquals( - projectBasedir.toAbsolutePath() + "/temp-repo", - (out.getRepositories().get(0)).getUrl()); + assertThat((out.getRepositories().get(0)).getUrl()).isEqualTo(projectBasedir.toAbsolutePath() + "/temp-repo"); } @Test - public void testBaseUri() throws Exception { + void baseUri() throws Exception { Path projectBasedir = Paths.get("projectBasedir"); Model model = Model.newBuilder() @@ -354,13 +344,12 @@ public void testBaseUri() throws Exception { model, projectBasedir, createModelBuildingRequest(context).build(), collector); assertProblemFree(collector); - assertEquals( - projectBasedir.resolve("temp-repo").toUri().toString(), - (out.getRepositories().get(0)).getUrl()); + assertThat((out.getRepositories().get(0)).getUrl()) + .isEqualTo(projectBasedir.resolve("temp-repo").toUri().toString()); } @Test - void testRootDirectory() throws Exception { + void rootDirectory() throws Exception { Path rootDirectory = Paths.get("myRootDirectory"); Model model = Model.newBuilder() @@ -376,11 +365,11 @@ void testRootDirectory() throws Exception { model, rootDirectory, createModelBuildingRequest(context).build(), collector); assertProblemFree(collector); - assertEquals("file:myRootDirectory/temp-repo", (out.getRepositories().get(0)).getUrl()); + assertThat((out.getRepositories().get(0)).getUrl()).isEqualTo("file:myRootDirectory/temp-repo"); } @Test - void testRootDirectoryWithUri() throws Exception { + void rootDirectoryWithUri() throws Exception { Path rootDirectory = Paths.get("myRootDirectory"); Model model = Model.newBuilder() @@ -396,13 +385,12 @@ void testRootDirectoryWithUri() throws Exception { model, rootDirectory, createModelBuildingRequest(context).build(), collector); assertProblemFree(collector); - assertEquals( - rootDirectory.resolve("temp-repo").toUri().toString(), - (out.getRepositories().get(0)).getUrl()); + assertThat((out.getRepositories().get(0)).getUrl()) + .isEqualTo(rootDirectory.resolve("temp-repo").toUri().toString()); } @Test - void testRootDirectoryWithNull() throws Exception { + void rootDirectoryWithNull() throws Exception { Path projectDirectory = Paths.get("myProjectDirectory"); this.rootDirectory = new AtomicReference<>(null); @@ -415,19 +403,19 @@ void testRootDirectoryWithNull() throws Exception { .build(); final SimpleProblemCollector collector = new SimpleProblemCollector(); - IllegalStateException e = assertThrows( - IllegalStateException.class, - () -> interpolator.interpolateModel( + IllegalStateException e = assertThatExceptionOfType(IllegalStateException.class) + .isThrownBy(() -> interpolator.interpolateModel( model, projectDirectory, createModelBuildingRequest(context).build(), - collector)); + collector)) + .actual(); - assertEquals(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE, e.getMessage()); + assertThat(e.getMessage()).isEqualTo(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE); } @Test - public void testEnvars() throws Exception { + void envars() throws Exception { context.put("env.HOME", "/path/to/home"); Map modelProperties = new HashMap<>(); @@ -440,11 +428,11 @@ public void testEnvars() throws Exception { model, Paths.get("."), createModelBuildingRequest(context).build(), collector); assertProblemFree(collector); - assertEquals("/path/to/home", out.getProperties().get("outputDirectory")); + assertThat(out.getProperties().get("outputDirectory")).isEqualTo("/path/to/home"); } @Test - public void envarExpressionThatEvaluatesToNullReturnsTheLiteralString() throws Exception { + void envarExpressionThatEvaluatesToNullReturnsTheLiteralString() throws Exception { Map modelProperties = new HashMap<>(); modelProperties.put("outputDirectory", "${env.DOES_NOT_EXIST}"); @@ -456,11 +444,11 @@ public void envarExpressionThatEvaluatesToNullReturnsTheLiteralString() throws E model, Paths.get("."), createModelBuildingRequest(context).build(), collector); assertProblemFree(collector); - assertEquals("${env.DOES_NOT_EXIST}", out.getProperties().get("outputDirectory")); + assertThat(out.getProperties().get("outputDirectory")).isEqualTo("${env.DOES_NOT_EXIST}"); } @Test - public void expressionThatEvaluatesToNullReturnsTheLiteralString() throws Exception { + void expressionThatEvaluatesToNullReturnsTheLiteralString() throws Exception { Map modelProperties = new HashMap<>(); modelProperties.put("outputDirectory", "${DOES_NOT_EXIST}"); @@ -471,11 +459,11 @@ public void expressionThatEvaluatesToNullReturnsTheLiteralString() throws Except model, Paths.get("."), createModelBuildingRequest(context).build(), collector); assertProblemFree(collector); - assertEquals("${DOES_NOT_EXIST}", out.getProperties().get("outputDirectory")); + assertThat(out.getProperties().get("outputDirectory")).isEqualTo("${DOES_NOT_EXIST}"); } @Test - public void shouldInterpolateSourceDirectoryReferencedFromResourceDirectoryCorrectly() throws Exception { + void shouldInterpolateSourceDirectoryReferencedFromResourceDirectoryCorrectly() throws Exception { Model model = Model.newBuilder() .build(Build.newBuilder() .sourceDirectory("correct") @@ -493,11 +481,11 @@ public void shouldInterpolateSourceDirectoryReferencedFromResourceDirectoryCorre List outResources = out.getBuild().getResources(); Iterator resIt = outResources.iterator(); - assertEquals(model.getBuild().getSourceDirectory(), resIt.next().getDirectory()); + assertThat(resIt.next().getDirectory()).isEqualTo(model.getBuild().getSourceDirectory()); } @Test - public void shouldInterpolateUnprefixedBasedirExpression() throws Exception { + void shouldInterpolateUnprefixedBasedirExpression() throws Exception { Path basedir = Paths.get("/test/path"); Model model = Model.newBuilder() .dependencies(Collections.singletonList(Dependency.newBuilder() @@ -511,15 +499,14 @@ public void shouldInterpolateUnprefixedBasedirExpression() throws Exception { assertProblemFree(collector); List rDeps = result.getDependencies(); - assertNotNull(rDeps); - assertEquals(1, rDeps.size()); - assertEquals( - basedir.resolve("artifact.jar").toAbsolutePath(), - Paths.get(rDeps.get(0).getSystemPath()).toAbsolutePath()); + assertThat(rDeps).isNotNull(); + assertThat(rDeps.size()).isEqualTo(1); + assertThat(Paths.get(rDeps.get(0).getSystemPath()).toAbsolutePath()) + .isEqualTo(basedir.resolve("artifact.jar").toAbsolutePath()); } @Test - public void testRecursiveExpressionCycleNPE() throws Exception { + void recursiveExpressionCycleNPE() throws Exception { Map props = new HashMap<>(); props.put("aa", "${bb}"); props.put("bb", "${aa}"); @@ -532,12 +519,13 @@ public void testRecursiveExpressionCycleNPE() throws Exception { interpolator.interpolateModel(model, null, request, collector); assertCollectorState(0, 2, 0, collector); - assertTrue(collector.getErrors().get(0).contains("recursive variable reference")); + assertThat(collector.getErrors().get(0).contains("recursive variable reference")) + .isTrue(); } @Disabled("per def cannot be recursive: ${basedir} is immediately going for project.basedir") @Test - public void testRecursiveExpressionCycleBaseDir() throws Exception { + void recursiveExpressionCycleBaseDir() throws Exception { Map props = new HashMap<>(); props.put("basedir", "${basedir}"); ModelBuilderRequest request = createModelBuildingRequest(Map.of()).build(); @@ -549,8 +537,7 @@ public void testRecursiveExpressionCycleBaseDir() throws Exception { interpolator.interpolateModel(model, null, request, collector); assertCollectorState(0, 1, 0, collector); - assertEquals( - "recursive variable reference: basedir", collector.getErrors().get(0)); + assertThat(collector.getErrors().get(0)).isEqualTo("recursive variable reference: basedir"); } @Test @@ -572,7 +559,7 @@ void shouldIgnorePropertiesWithPomPrefix() throws Exception { collector); assertCollectorState(0, 0, 0, collector); - assertEquals(uninterpolatedName, out.getName()); + assertThat(out.getName()).isEqualTo(uninterpolatedName); } @Provides diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java index 06947221f3b5..ba9c0171ed4f 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java @@ -29,9 +29,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** */ @@ -42,7 +40,7 @@ class DefaultModelValidatorTest { private Model read(String pom) throws Exception { String resource = "/poms/validation/" + pom; try (InputStream is = getClass().getResourceAsStream(resource)) { - assertNotNull(is, "missing resource: " + resource); + assertThat(is).as("missing resource: " + resource).isNotNull(); return new MavenStaxReader().read(is); } } @@ -84,7 +82,9 @@ private SimpleProblemCollector validateRaw(String pom, int level) throws Excepti } private void assertContains(String msg, String substring) { - assertTrue(msg.contains(substring), "\"" + substring + "\" was not found in: " + msg); + assertThat(msg.contains(substring)) + .as("\"" + substring + "\" was not found in: " + msg) + .isTrue(); } @BeforeEach @@ -98,265 +98,267 @@ void tearDown() throws Exception { } private void assertViolations(SimpleProblemCollector result, int fatals, int errors, int warnings) { - assertEquals(fatals, result.getFatals().size(), String.valueOf(result.getFatals())); - assertEquals(errors, result.getErrors().size(), String.valueOf(result.getErrors())); - assertEquals(warnings, result.getWarnings().size(), String.valueOf(result.getWarnings())); + assertThat(result.getFatals().size()) + .as(String.valueOf(result.getFatals())) + .isEqualTo(fatals); + assertThat(result.getErrors().size()) + .as(String.valueOf(result.getErrors())) + .isEqualTo(errors); + assertThat(result.getWarnings().size()) + .as(String.valueOf(result.getWarnings())) + .isEqualTo(warnings); } @Test - void testMissingModelVersion() throws Exception { + void missingModelVersion() throws Exception { SimpleProblemCollector result = validate("missing-modelVersion-pom.xml"); assertViolations(result, 0, 1, 0); - assertEquals("'modelVersion' is missing.", result.getErrors().get(0)); + assertThat(result.getErrors().get(0)).isEqualTo("'modelVersion' is missing."); } @Test - void testBadModelVersion() throws Exception { + void badModelVersion() throws Exception { SimpleProblemCollector result = validateFile("bad-modelVersion.xml"); assertViolations(result, 1, 0, 0); - assertTrue(result.getFatals().get(0).contains("modelVersion")); + assertThat(result.getFatals().get(0).contains("modelVersion")).isTrue(); } @Test - void testModelVersionMessage() throws Exception { + void modelVersionMessage() throws Exception { SimpleProblemCollector result = validateFile("modelVersion-4_0.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("'modelVersion' must be one of")); + assertThat(result.getErrors().get(0).contains("'modelVersion' must be one of")) + .isTrue(); } @Test - void testMissingArtifactId() throws Exception { + void missingArtifactId() throws Exception { SimpleProblemCollector result = validate("missing-artifactId-pom.xml"); assertViolations(result, 0, 1, 0); - assertEquals("'artifactId' is missing.", result.getErrors().get(0)); + assertThat(result.getErrors().get(0)).isEqualTo("'artifactId' is missing."); } @Test - void testMissingGroupId() throws Exception { + void missingGroupId() throws Exception { SimpleProblemCollector result = validate("missing-groupId-pom.xml"); assertViolations(result, 0, 1, 0); - assertEquals("'groupId' is missing.", result.getErrors().get(0)); + assertThat(result.getErrors().get(0)).isEqualTo("'groupId' is missing."); } @Test - void testInvalidCoordinateIds() throws Exception { + void invalidCoordinateIds() throws Exception { SimpleProblemCollector result = validate("invalid-coordinate-ids-pom.xml"); assertViolations(result, 0, 2, 0); - assertEquals( - "'groupId' with value 'o/a/m' does not match a valid coordinate id pattern.", - result.getErrors().get(0)); + assertThat(result.getErrors().get(0)) + .isEqualTo("'groupId' with value 'o/a/m' does not match a valid coordinate id pattern."); - assertEquals( - "'artifactId' with value 'm$-do$' does not match a valid coordinate id pattern.", - result.getErrors().get(1)); + assertThat(result.getErrors().get(1)) + .isEqualTo("'artifactId' with value 'm$-do$' does not match a valid coordinate id pattern."); } @Test - void testMissingType() throws Exception { + void missingType() throws Exception { SimpleProblemCollector result = validate("missing-type-pom.xml"); assertViolations(result, 0, 1, 0); - assertEquals("'packaging' is missing.", result.getErrors().get(0)); + assertThat(result.getErrors().get(0)).isEqualTo("'packaging' is missing."); } @Test - void testMissingVersion() throws Exception { + void missingVersion() throws Exception { SimpleProblemCollector result = validate("missing-version-pom.xml"); assertViolations(result, 0, 1, 0); - assertEquals("'version' is missing.", result.getErrors().get(0)); + assertThat(result.getErrors().get(0)).isEqualTo("'version' is missing."); } @Test - void testInvalidAggregatorPackaging() throws Exception { + void invalidAggregatorPackaging() throws Exception { SimpleProblemCollector result = validate("invalid-aggregator-packaging-pom.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("Aggregator projects require 'pom' as packaging.")); + assertThat(result.getErrors().get(0).contains("Aggregator projects require 'pom' as packaging.")) + .isTrue(); } @Test - void testMissingDependencyArtifactId() throws Exception { + void missingDependencyArtifactId() throws Exception { SimpleProblemCollector result = validate("missing-dependency-artifactId-pom.xml"); assertViolations(result, 0, 1, 0); - assertTrue( - result.getErrors() - .get(0) - .contains( - "'dependencies.dependency.artifactId' for groupId='groupId', artifactId=, type='jar' is missing")); + assertThat( + result.getErrors() + .get(0) + .contains( + "'dependencies.dependency.artifactId' for groupId='groupId', artifactId=, type='jar' is missing")) + .isTrue(); } @Test - void testMissingDependencyGroupId() throws Exception { + void missingDependencyGroupId() throws Exception { SimpleProblemCollector result = validate("missing-dependency-groupId-pom.xml"); assertViolations(result, 0, 1, 0); - assertTrue( - result.getErrors() - .get(0) - .contains( - "'dependencies.dependency.groupId' for groupId=, artifactId='artifactId', type='jar' is missing")); + assertThat( + result.getErrors() + .get(0) + .contains( + "'dependencies.dependency.groupId' for groupId=, artifactId='artifactId', type='jar' is missing")) + .isTrue(); } @Test - void testMissingDependencyVersion() throws Exception { + void missingDependencyVersion() throws Exception { SimpleProblemCollector result = validate("missing-dependency-version-pom.xml"); assertViolations(result, 0, 1, 0); - assertTrue( - result.getErrors() - .get(0) - .contains( - "'dependencies.dependency.version' for groupId='groupId', artifactId='artifactId', type='jar' is missing")); + assertThat( + result.getErrors() + .get(0) + .contains( + "'dependencies.dependency.version' for groupId='groupId', artifactId='artifactId', type='jar' is missing")) + .isTrue(); } @Test - void testMissingDependencyManagementArtifactId() throws Exception { + void missingDependencyManagementArtifactId() throws Exception { SimpleProblemCollector result = validate("missing-dependency-mgmt-artifactId-pom.xml"); assertViolations(result, 0, 1, 0); - assertTrue( - result.getErrors() - .get(0) - .contains( - "'dependencyManagement.dependencies.dependency.artifactId' for groupId='groupId', artifactId=, type='jar' is missing")); + assertThat( + result.getErrors() + .get(0) + .contains( + "'dependencyManagement.dependencies.dependency.artifactId' for groupId='groupId', artifactId=, type='jar' is missing")) + .isTrue(); } @Test - void testMissingDependencyManagementGroupId() throws Exception { + void missingDependencyManagementGroupId() throws Exception { SimpleProblemCollector result = validate("missing-dependency-mgmt-groupId-pom.xml"); assertViolations(result, 0, 1, 0); - assertTrue( - result.getErrors() - .get(0) - .contains( - "'dependencyManagement.dependencies.dependency.groupId' for groupId=, artifactId='artifactId', type='jar' is missing")); + assertThat( + result.getErrors() + .get(0) + .contains( + "'dependencyManagement.dependencies.dependency.groupId' for groupId=, artifactId='artifactId', type='jar' is missing")) + .isTrue(); } @Test - void testMissingAll() throws Exception { + void missingAll() throws Exception { SimpleProblemCollector result = validate("missing-1-pom.xml"); assertViolations(result, 0, 4, 0); List messages = result.getErrors(); - assertTrue(messages.contains("'modelVersion' is missing.")); - assertTrue(messages.contains("'groupId' is missing.")); - assertTrue(messages.contains("'artifactId' is missing.")); - assertTrue(messages.contains("'version' is missing.")); + assertThat(messages.contains("'modelVersion' is missing.")).isTrue(); + assertThat(messages.contains("'groupId' is missing.")).isTrue(); + assertThat(messages.contains("'artifactId' is missing.")).isTrue(); + assertThat(messages.contains("'version' is missing.")).isTrue(); // type is inherited from the super pom } @Test - void testMissingPluginArtifactId() throws Exception { + void missingPluginArtifactId() throws Exception { SimpleProblemCollector result = validate("missing-plugin-artifactId-pom.xml"); assertViolations(result, 0, 1, 0); - assertEquals( - "'build.plugins.plugin.artifactId' is missing.", - result.getErrors().get(0)); + assertThat(result.getErrors().get(0)).isEqualTo("'build.plugins.plugin.artifactId' is missing."); } @Test - void testEmptyPluginVersion() throws Exception { + void emptyPluginVersion() throws Exception { SimpleProblemCollector result = validate("empty-plugin-version.xml"); assertViolations(result, 0, 1, 0); - assertEquals( - "'build.plugins.plugin.version' for org.apache.maven.plugins:maven-it-plugin" - + " must be a valid version but is ''.", - result.getErrors().get(0)); + assertThat(result.getErrors().get(0)) + .isEqualTo("'build.plugins.plugin.version' for org.apache.maven.plugins:maven-it-plugin" + + " must be a valid version but is ''."); } @Test - void testMissingRepositoryId() throws Exception { + void missingRepositoryId() throws Exception { SimpleProblemCollector result = validateFile("missing-repository-id-pom.xml", ModelValidator.VALIDATION_LEVEL_STRICT); assertViolations(result, 0, 4, 0); - assertEquals( - "'repositories.repository.id' is missing.", result.getErrors().get(0)); + assertThat(result.getErrors().get(0)).isEqualTo("'repositories.repository.id' is missing."); - assertEquals( - "'repositories.repository.[null].url' is missing.", - result.getErrors().get(1)); + assertThat(result.getErrors().get(1)).isEqualTo("'repositories.repository.[null].url' is missing."); - assertEquals( - "'pluginRepositories.pluginRepository.id' is missing.", - result.getErrors().get(2)); + assertThat(result.getErrors().get(2)).isEqualTo("'pluginRepositories.pluginRepository.id' is missing."); - assertEquals( - "'pluginRepositories.pluginRepository.[null].url' is missing.", - result.getErrors().get(3)); + assertThat(result.getErrors().get(3)).isEqualTo("'pluginRepositories.pluginRepository.[null].url' is missing."); } @Test - void testMissingResourceDirectory() throws Exception { + void missingResourceDirectory() throws Exception { SimpleProblemCollector result = validate("missing-resource-directory-pom.xml"); assertViolations(result, 0, 2, 0); - assertEquals( - "'build.resources.resource.directory' is missing.", - result.getErrors().get(0)); + assertThat(result.getErrors().get(0)).isEqualTo("'build.resources.resource.directory' is missing."); - assertEquals( - "'build.testResources.testResource.directory' is missing.", - result.getErrors().get(1)); + assertThat(result.getErrors().get(1)).isEqualTo("'build.testResources.testResource.directory' is missing."); } @Test - void testBadPluginDependencyScope() throws Exception { + void badPluginDependencyScope() throws Exception { SimpleProblemCollector result = validate("bad-plugin-dependency-scope.xml"); assertViolations(result, 0, 3, 0); - assertTrue(result.getErrors().get(0).contains("groupId='test', artifactId='d'")); + assertThat(result.getErrors().get(0).contains("groupId='test', artifactId='d'")) + .isTrue(); - assertTrue(result.getErrors().get(1).contains("groupId='test', artifactId='e'")); + assertThat(result.getErrors().get(1).contains("groupId='test', artifactId='e'")) + .isTrue(); - assertTrue(result.getErrors().get(2).contains("groupId='test', artifactId='f'")); + assertThat(result.getErrors().get(2).contains("groupId='test', artifactId='f'")) + .isTrue(); } @Test - void testBadDependencyScope() throws Exception { + void badDependencyScope() throws Exception { SimpleProblemCollector result = validate("bad-dependency-scope.xml"); assertViolations(result, 0, 0, 2); - assertTrue(result.getWarnings().get(0).contains("groupId='test', artifactId='f'")); + assertThat(result.getWarnings().get(0).contains("groupId='test', artifactId='f'")) + .isTrue(); - assertTrue(result.getWarnings().get(1).contains("groupId='test', artifactId='g'")); + assertThat(result.getWarnings().get(1).contains("groupId='test', artifactId='g'")) + .isTrue(); } @Test - void testBadDependencyManagementScope() throws Exception { + void badDependencyManagementScope() throws Exception { SimpleProblemCollector result = validate("bad-dependency-management-scope.xml"); assertViolations(result, 0, 0, 1); @@ -365,7 +367,7 @@ void testBadDependencyManagementScope() throws Exception { } @Test - void testBadDependencyVersion() throws Exception { + void badDependencyVersion() throws Exception { SimpleProblemCollector result = validate("bad-dependency-version.xml"); assertViolations(result, 0, 2, 0); @@ -379,37 +381,37 @@ void testBadDependencyVersion() throws Exception { } @Test - void testDuplicateModule() throws Exception { + void duplicateModule() throws Exception { SimpleProblemCollector result = validateFile("duplicate-module.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("child")); + assertThat(result.getErrors().get(0).contains("child")).isTrue(); } @Test - void testInvalidProfileId() throws Exception { + void invalidProfileId() throws Exception { SimpleProblemCollector result = validateFile("invalid-profile-ids.xml"); assertViolations(result, 0, 4, 0); - assertTrue(result.getErrors().get(0).contains("+invalid-id")); - assertTrue(result.getErrors().get(1).contains("-invalid-id")); - assertTrue(result.getErrors().get(2).contains("!invalid-id")); - assertTrue(result.getErrors().get(3).contains("?invalid-id")); + assertThat(result.getErrors().get(0).contains("+invalid-id")).isTrue(); + assertThat(result.getErrors().get(1).contains("-invalid-id")).isTrue(); + assertThat(result.getErrors().get(2).contains("!invalid-id")).isTrue(); + assertThat(result.getErrors().get(3).contains("?invalid-id")).isTrue(); } @Test - void testDuplicateProfileId() throws Exception { + void duplicateProfileId() throws Exception { SimpleProblemCollector result = validateFile("duplicate-profile-id.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("non-unique-id")); + assertThat(result.getErrors().get(0).contains("non-unique-id")).isTrue(); } @Test - void testBadPluginVersion() throws Exception { + void badPluginVersion() throws Exception { SimpleProblemCollector result = validate("bad-plugin-version.xml"); assertViolations(result, 0, 4, 0); @@ -426,26 +428,27 @@ void testBadPluginVersion() throws Exception { } @Test - void testDistributionManagementStatus() throws Exception { + void distributionManagementStatus() throws Exception { SimpleProblemCollector result = validate("distribution-management-status.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("distributionManagement.status")); + assertThat(result.getErrors().get(0).contains("distributionManagement.status")) + .isTrue(); } @Test - void testIncompleteParent() throws Exception { + void incompleteParent() throws Exception { SimpleProblemCollector result = validateRaw("incomplete-parent.xml"); assertViolations(result, 3, 0, 0); - assertTrue(result.getFatals().get(0).contains("parent.groupId")); - assertTrue(result.getFatals().get(1).contains("parent.artifactId")); - assertTrue(result.getFatals().get(2).contains("parent.version")); + assertThat(result.getFatals().get(0).contains("parent.groupId")).isTrue(); + assertThat(result.getFatals().get(1).contains("parent.artifactId")).isTrue(); + assertThat(result.getFatals().get(2).contains("parent.version")).isTrue(); } @Test - void testHardCodedSystemPath() throws Exception { + void hardCodedSystemPath() throws Exception { SimpleProblemCollector result = validateFile("hard-coded-system-path.xml"); assertViolations(result, 0, 0, 3); @@ -462,28 +465,33 @@ void testHardCodedSystemPath() throws Exception { } @Test - void testEmptyModule() throws Exception { + void emptyModule() throws Exception { SimpleProblemCollector result = validate("empty-module.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("'modules.module[0]' has been specified without a path")); + assertThat(result.getErrors().get(0).contains("'modules.module[0]' has been specified without a path")) + .isTrue(); } @Test - void testDuplicatePlugin() throws Exception { + void duplicatePlugin() throws Exception { SimpleProblemCollector result = validateFile("duplicate-plugin.xml"); assertViolations(result, 0, 4, 0); - assertTrue(result.getErrors().get(0).contains("duplicate declaration of plugin test:duplicate")); - assertTrue(result.getErrors().get(1).contains("duplicate declaration of plugin test:managed-duplicate")); - assertTrue(result.getErrors().get(2).contains("duplicate declaration of plugin profile:duplicate")); - assertTrue(result.getErrors().get(3).contains("duplicate declaration of plugin profile:managed-duplicate")); + assertThat(result.getErrors().get(0).contains("duplicate declaration of plugin test:duplicate")) + .isTrue(); + assertThat(result.getErrors().get(1).contains("duplicate declaration of plugin test:managed-duplicate")) + .isTrue(); + assertThat(result.getErrors().get(2).contains("duplicate declaration of plugin profile:duplicate")) + .isTrue(); + assertThat(result.getErrors().get(3).contains("duplicate declaration of plugin profile:managed-duplicate")) + .isTrue(); } @Test - void testDuplicatePluginExecution() throws Exception { + void duplicatePluginExecution() throws Exception { SimpleProblemCollector result = validateFile("duplicate-plugin-execution.xml"); assertViolations(result, 0, 4, 0); @@ -495,7 +503,7 @@ void testDuplicatePluginExecution() throws Exception { } @Test - void testReservedRepositoryId() throws Exception { + void reservedRepositoryId() throws Exception { SimpleProblemCollector result = validate("reserved-repository-id.xml"); assertViolations(result, 0, 4, 0); @@ -507,43 +515,47 @@ void testReservedRepositoryId() throws Exception { } @Test - void testMissingPluginDependencyGroupId() throws Exception { + void missingPluginDependencyGroupId() throws Exception { SimpleProblemCollector result = validate("missing-plugin-dependency-groupId.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("groupId=, artifactId='a',")); + assertThat(result.getErrors().get(0).contains("groupId=, artifactId='a',")) + .isTrue(); } @Test - void testMissingPluginDependencyArtifactId() throws Exception { + void missingPluginDependencyArtifactId() throws Exception { SimpleProblemCollector result = validate("missing-plugin-dependency-artifactId.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("groupId='test', artifactId=,")); + assertThat(result.getErrors().get(0).contains("groupId='test', artifactId=,")) + .isTrue(); } @Test - void testMissingPluginDependencyVersion() throws Exception { + void missingPluginDependencyVersion() throws Exception { SimpleProblemCollector result = validate("missing-plugin-dependency-version.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("groupId='test', artifactId='a',")); + assertThat(result.getErrors().get(0).contains("groupId='test', artifactId='a',")) + .isTrue(); } @Test - void testBadPluginDependencyVersion() throws Exception { + void badPluginDependencyVersion() throws Exception { SimpleProblemCollector result = validate("bad-plugin-dependency-version.xml"); assertViolations(result, 0, 1, 0); - assertTrue(result.getErrors().get(0).contains("groupId='test', artifactId='b'")); + assertThat(result.getErrors().get(0).contains("groupId='test', artifactId='b'")) + .isTrue(); } @Test - void testBadVersion() throws Exception { + void badVersion() throws Exception { SimpleProblemCollector result = validate("bad-version.xml"); assertViolations(result, 0, 1, 0); @@ -552,7 +564,7 @@ void testBadVersion() throws Exception { } @Test - void testBadSnapshotVersion() throws Exception { + void badSnapshotVersion() throws Exception { SimpleProblemCollector result = validate("bad-snapshot-version.xml"); assertViolations(result, 0, 1, 0); @@ -561,7 +573,7 @@ void testBadSnapshotVersion() throws Exception { } @Test - void testBadRepositoryId() throws Exception { + void badRepositoryId() throws Exception { SimpleProblemCollector result = validate("bad-repository-id.xml"); assertViolations(result, 0, 4, 0); @@ -580,7 +592,7 @@ void testBadRepositoryId() throws Exception { } @Test - void testBadDependencyExclusionId() throws Exception { + void badDependencyExclusionId() throws Exception { SimpleProblemCollector result = validateEffective("bad-dependency-exclusion-id.xml", ModelValidator.VALIDATION_LEVEL_MAVEN_2_0); @@ -601,7 +613,7 @@ void testBadDependencyExclusionId() throws Exception { } @Test - void testMissingDependencyExclusionId() throws Exception { + void missingDependencyExclusionId() throws Exception { SimpleProblemCollector result = validate("missing-dependency-exclusion-id.xml"); assertViolations(result, 0, 0, 2); @@ -615,7 +627,7 @@ void testMissingDependencyExclusionId() throws Exception { } @Test - void testBadImportScopeType() throws Exception { + void badImportScopeType() throws Exception { SimpleProblemCollector result = validateFile("bad-import-scope-type.xml"); assertViolations(result, 0, 0, 1); @@ -626,7 +638,7 @@ void testBadImportScopeType() throws Exception { } @Test - void testBadImportScopeClassifier() throws Exception { + void badImportScopeClassifier() throws Exception { SimpleProblemCollector result = validateFile("bad-import-scope-classifier.xml"); assertViolations(result, 0, 1, 0); @@ -637,7 +649,7 @@ void testBadImportScopeClassifier() throws Exception { } @Test - void testSystemPathRefersToProjectBasedir() throws Exception { + void systemPathRefersToProjectBasedir() throws Exception { SimpleProblemCollector result = validateFile("basedir-system-path.xml"); assertViolations(result, 0, 0, 4); @@ -657,62 +669,62 @@ void testSystemPathRefersToProjectBasedir() throws Exception { } @Test - void testInvalidVersionInPluginManagement() throws Exception { + void invalidVersionInPluginManagement() throws Exception { SimpleProblemCollector result = validateFile("raw-model/missing-plugin-version-pluginManagement.xml"); assertViolations(result, 1, 0, 0); - assertEquals( - "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' version of a plugin must be defined. ", - result.getFatals().get(0)); + assertThat(result.getFatals().get(0)) + .isEqualTo( + "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' version of a plugin must be defined. "); } @Test - void testInvalidGroupIdInPluginManagement() throws Exception { + void invalidGroupIdInPluginManagement() throws Exception { SimpleProblemCollector result = validateFile("raw-model/missing-groupId-pluginManagement.xml"); assertViolations(result, 1, 0, 0); - assertEquals( - "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' groupId of a plugin must be defined. ", - result.getFatals().get(0)); + assertThat(result.getFatals().get(0)) + .isEqualTo( + "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' groupId of a plugin must be defined. "); } @Test - void testInvalidArtifactIdInPluginManagement() throws Exception { + void invalidArtifactIdInPluginManagement() throws Exception { SimpleProblemCollector result = validateFile("raw-model/missing-artifactId-pluginManagement.xml"); assertViolations(result, 1, 0, 0); - assertEquals( - "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' artifactId of a plugin must be defined. ", - result.getFatals().get(0)); + assertThat(result.getFatals().get(0)) + .isEqualTo( + "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' artifactId of a plugin must be defined. "); } @Test - void testInvalidGroupAndArtifactIdInPluginManagement() throws Exception { + void invalidGroupAndArtifactIdInPluginManagement() throws Exception { SimpleProblemCollector result = validateFile("raw-model/missing-ga-pluginManagement.xml"); assertViolations(result, 2, 0, 0); - assertEquals( - "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' groupId of a plugin must be defined. ", - result.getFatals().get(0)); + assertThat(result.getFatals().get(0)) + .isEqualTo( + "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' groupId of a plugin must be defined. "); - assertEquals( - "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' artifactId of a plugin must be defined. ", - result.getFatals().get(1)); + assertThat(result.getFatals().get(1)) + .isEqualTo( + "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' artifactId of a plugin must be defined. "); } @Test - void testMissingReportPluginVersion() throws Exception { + void missingReportPluginVersion() throws Exception { SimpleProblemCollector result = validate("missing-report-version-pom.xml"); assertViolations(result, 0, 0, 0); } @Test - void testDeprecatedDependencyMetaversionsLatestAndRelease() throws Exception { + void deprecatedDependencyMetaversionsLatestAndRelease() throws Exception { SimpleProblemCollector result = validateFile("deprecated-dependency-metaversions-latest-and-release.xml"); assertViolations(result, 0, 0, 2); @@ -726,99 +738,91 @@ void testDeprecatedDependencyMetaversionsLatestAndRelease() throws Exception { } @Test - void testSelfReferencingDependencyInRawModel() throws Exception { + void selfReferencingDependencyInRawModel() throws Exception { SimpleProblemCollector result = validateFile("raw-model/self-referencing.xml"); assertViolations(result, 1, 0, 0); - assertEquals( - "'dependencies.dependency[com.example.group:testinvalidpom:0.0.1-SNAPSHOT]' for com.example.group:testinvalidpom:0.0.1-SNAPSHOT is referencing itself.", - result.getFatals().get(0)); + assertThat(result.getFatals().get(0)) + .isEqualTo( + "'dependencies.dependency[com.example.group:testinvalidpom:0.0.1-SNAPSHOT]' for com.example.group:testinvalidpom:0.0.1-SNAPSHOT is referencing itself."); } @Test - void testSelfReferencingDependencyWithClassifierInRawModel() throws Exception { + void selfReferencingDependencyWithClassifierInRawModel() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/self-referencing-classifier.xml"); assertViolations(result, 0, 0, 0); } @Test - void testCiFriendlySha1() throws Exception { + void ciFriendlySha1() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/ok-ci-friendly-sha1.xml"); assertViolations(result, 0, 0, 0); } @Test - void testCiFriendlyRevision() throws Exception { + void ciFriendlyRevision() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/ok-ci-friendly-revision.xml"); assertViolations(result, 0, 0, 0); } @Test - void testCiFriendlyChangeList() throws Exception { + void ciFriendlyChangeList() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/ok-ci-friendly-changelist.xml"); assertViolations(result, 0, 0, 0); } @Test - void testCiFriendlyAllExpressions() throws Exception { + void ciFriendlyAllExpressions() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/ok-ci-friendly-all-expressions.xml"); assertViolations(result, 0, 0, 0); } @Test - void testCiFriendlyBad() throws Exception { + void ciFriendlyBad() throws Exception { SimpleProblemCollector result = validateFile("raw-model/bad-ci-friendly.xml"); assertViolations(result, 0, 0, 1); - assertEquals( - "'version' contains an expression but should be a constant.", - result.getWarnings().get(0)); + assertThat(result.getWarnings().get(0)).isEqualTo("'version' contains an expression but should be a constant."); } @Test - void testCiFriendlyBadSha1Plus() throws Exception { + void ciFriendlyBadSha1Plus() throws Exception { SimpleProblemCollector result = validateFile("raw-model/bad-ci-friendly-sha1plus.xml"); assertViolations(result, 0, 0, 1); - assertEquals( - "'version' contains an expression but should be a constant.", - result.getWarnings().get(0)); + assertThat(result.getWarnings().get(0)).isEqualTo("'version' contains an expression but should be a constant."); } @Test - void testCiFriendlyBadSha1Plus2() throws Exception { + void ciFriendlyBadSha1Plus2() throws Exception { SimpleProblemCollector result = validateFile("raw-model/bad-ci-friendly-sha1plus2.xml"); assertViolations(result, 0, 0, 1); - assertEquals( - "'version' contains an expression but should be a constant.", - result.getWarnings().get(0)); + assertThat(result.getWarnings().get(0)).isEqualTo("'version' contains an expression but should be a constant."); } @Test - void testParentVersionLATEST() throws Exception { + void parentVersionLATEST() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/bad-parent-version-latest.xml"); assertViolations(result, 0, 0, 1); - assertEquals( - "'parent.version' is either LATEST or RELEASE (both of them are being deprecated)", - result.getWarnings().get(0)); + assertThat(result.getWarnings().get(0)) + .isEqualTo("'parent.version' is either LATEST or RELEASE (both of them are being deprecated)"); } @Test - void testParentVersionRELEASE() throws Exception { + void parentVersionRELEASE() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/bad-parent-version-release.xml"); assertViolations(result, 0, 0, 1); - assertEquals( - "'parent.version' is either LATEST or RELEASE (both of them are being deprecated)", - result.getWarnings().get(0)); + assertThat(result.getWarnings().get(0)) + .isEqualTo("'parent.version' is either LATEST or RELEASE (both of them are being deprecated)"); } @Test void repositoryWithExpression() throws Exception { SimpleProblemCollector result = validateFile("raw-model/repository-with-expression.xml"); assertViolations(result, 0, 1, 0); - assertEquals( - "'repositories.repository.[repo].url' contains an unsupported expression (only expressions starting with 'project.basedir' or 'project.rootDirectory' are supported).", - result.getErrors().get(0)); + assertThat(result.getErrors().get(0)) + .isEqualTo( + "'repositories.repository.[repo].url' contains an unsupported expression (only expressions starting with 'project.basedir' or 'project.rootDirectory' are supported)."); } @Test @@ -842,17 +846,15 @@ void profileActivationFileWithProjectExpression() throws Exception { SimpleProblemCollector result = validateFile("raw-model/profile-activation-file-with-project-expressions.xml"); assertViolations(result, 0, 0, 2); - assertEquals( - "'profiles.profile[exists-project-version].activation.file.exists' " + assertThat(result.getWarnings().get(0)) + .isEqualTo("'profiles.profile[exists-project-version].activation.file.exists' " + "Failed to interpolate profile activation property ${project.version}/test.txt: " - + "${project.version} expressions are not supported during profile activation.", - result.getWarnings().get(0)); + + "${project.version} expressions are not supported during profile activation."); - assertEquals( - "'profiles.profile[missing-project-version].activation.file.missing' " + assertThat(result.getWarnings().get(1)) + .isEqualTo("'profiles.profile[missing-project-version].activation.file.missing' " + "Failed to interpolate profile activation property ${project.version}/test.txt: " - + "${project.version} expressions are not supported during profile activation.", - result.getWarnings().get(1)); + + "${project.version} expressions are not supported during profile activation."); } @Test @@ -861,17 +863,15 @@ void profileActivationPropertyWithProjectExpression() throws Exception { validateFile("raw-model/profile-activation-property-with-project-expressions.xml"); assertViolations(result, 0, 0, 2); - assertEquals( - "'profiles.profile[property-name-project-version].activation.property.name' " + assertThat(result.getWarnings().get(0)) + .isEqualTo("'profiles.profile[property-name-project-version].activation.property.name' " + "Failed to interpolate profile activation property ${project.version}: " - + "${project.version} expressions are not supported during profile activation.", - result.getWarnings().get(0)); + + "${project.version} expressions are not supported during profile activation."); - assertEquals( - "'profiles.profile[property-value-project-version].activation.property.value' " + assertThat(result.getWarnings().get(1)) + .isEqualTo("'profiles.profile[property-value-project-version].activation.property.value' " + "Failed to interpolate profile activation property ${project.version}: " - + "${project.version} expressions are not supported during profile activation.", - result.getWarnings().get(1)); + + "${project.version} expressions are not supported during profile activation."); } @Test diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/MavenBuildTimestampTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/MavenBuildTimestampTest.java index ac3acae14a9a..43c3b5279189 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/MavenBuildTimestampTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/MavenBuildTimestampTest.java @@ -24,15 +24,17 @@ import org.apache.maven.api.MonotonicClock; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class MavenBuildTimestampTest { @Test - void testMavenBuildTimestampUsesUTC() { + void mavenBuildTimestampUsesUTC() { Map interpolationProperties = new HashMap<>(); interpolationProperties.put("maven.build.timestamp.format", "yyyyMMdd'T'HHmm'Z'"); MavenBuildTimestamp timestamp = new MavenBuildTimestamp(MonotonicClock.now(), interpolationProperties); String formattedTimestamp = timestamp.formattedTimestamp(); - assertTrue(formattedTimestamp.endsWith("Z"), "We expect the UTC marker at the end of the timestamp."); + assertThat(formattedTimestamp.endsWith("Z")) + .as("We expect the UTC marker at the end of the timestamp.") + .isTrue(); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/MavenModelMergerTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/MavenModelMergerTest.java index 22227f2da9f3..c07c164aca30 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/MavenModelMergerTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/MavenModelMergerTest.java @@ -25,70 +25,69 @@ import org.apache.maven.api.model.Profile; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; class MavenModelMergerTest { private MavenModelMerger modelMerger = new MavenModelMerger(); // modelVersion is neither inherited nor injected @Test - void testMergeModelModelVersion() { + void mergeModelModelVersion() { Model parent = Model.newBuilder().modelVersion("4.0.0").build(); Model model = Model.newInstance(); Model.Builder builder = Model.newBuilder(model); modelMerger.mergeModel_ModelVersion(builder, model, parent, false, null); - assertNull(builder.build().getModelVersion()); + assertThat(builder.build().getModelVersion()).isNull(); model = Model.newBuilder().modelVersion("5.0.0").build(); builder = Model.newBuilder(model); modelMerger.mergeModel_ModelVersion(builder, model, parent, false, null); - assertEquals("5.0.0", builder.build().getModelVersion()); + assertThat(builder.build().getModelVersion()).isEqualTo("5.0.0"); } // ArtifactId is neither inherited nor injected @Test - void testMergeModelArtifactId() { + void mergeModelArtifactId() { Model parent = Model.newBuilder().artifactId("PARENT").build(); Model model = Model.newInstance(); Model.Builder builder = Model.newBuilder(model); modelMerger.mergeModel_ArtifactId(builder, model, parent, false, null); - assertNull(model.getArtifactId()); + assertThat(model.getArtifactId()).isNull(); model = Model.newBuilder().artifactId("MODEL").build(); builder = Model.newBuilder(model); modelMerger.mergeModel_ArtifactId(builder, model, parent, false, null); - assertEquals("MODEL", builder.build().getArtifactId()); + assertThat(builder.build().getArtifactId()).isEqualTo("MODEL"); } // Prerequisites are neither inherited nor injected @Test - void testMergeModelPrerequisites() { + void mergeModelPrerequisites() { Model parent = Model.newBuilder().prerequisites(Prerequisites.newInstance()).build(); Model model = Model.newInstance(); Model.Builder builder = Model.newBuilder(model); modelMerger.mergeModel_Prerequisites(builder, model, parent, false, null); - assertNull(builder.build().getPrerequisites()); + assertThat(builder.build().getPrerequisites()).isNull(); Prerequisites modelPrerequisites = Prerequisites.newBuilder().maven("3.0").build(); model = Model.newBuilder().prerequisites(modelPrerequisites).build(); builder = Model.newBuilder(model); modelMerger.mergeModel_Prerequisites(builder, model, parent, false, null); - assertEquals(modelPrerequisites, builder.build().getPrerequisites()); + assertThat(builder.build().getPrerequisites()).isEqualTo(modelPrerequisites); } // Profiles are neither inherited nor injected @Test - void testMergeModelProfiles() { + void mergeModelProfiles() { Model parent = Model.newBuilder() .profiles(Collections.singletonList(Profile.newInstance())) .build(); Model model = Model.newInstance(); Model.Builder builder = Model.newBuilder(model); modelMerger.mergeModel_Profiles(builder, model, parent, false, null); - assertEquals(0, builder.build().getProfiles().size()); + assertThat(builder.build().getProfiles().size()).isEqualTo(0); Profile modelProfile = Profile.newBuilder().id("MODEL").build(); model = Model.newBuilder() @@ -96,6 +95,6 @@ void testMergeModelProfiles() { .build(); builder = Model.newBuilder(model); modelMerger.mergeModel_Prerequisites(builder, model, parent, false, null); - assertEquals(Collections.singletonList(modelProfile), builder.build().getProfiles()); + assertThat(builder.build().getProfiles()).isEqualTo(Collections.singletonList(modelProfile)); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/AbstractProfileActivatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/AbstractProfileActivatorTest.java index 3829f03e49ad..49b7d34d3bd1 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/AbstractProfileActivatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/AbstractProfileActivatorTest.java @@ -32,7 +32,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Provides common services to test {@link ProfileActivator} implementations. @@ -74,8 +74,12 @@ protected void assertActivation(boolean active, Profile profile, ProfileActivati SimpleProblemCollector problems = new SimpleProblemCollector(); boolean res = activator.isActive(profile, context, problems); - assertEquals(0, problems.getErrors().size(), problems.getErrors().toString()); - assertEquals(0, problems.getWarnings().size(), problems.getWarnings().toString()); - assertEquals(active, res); + assertThat(problems.getErrors().size()) + .as(problems.getErrors().toString()) + .isEqualTo(0); + assertThat(problems.getWarnings().size()) + .as(problems.getWarnings().toString()) + .isEqualTo(0); + assertThat(res).isEqualTo(active); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java index 56d2cbb3aec9..47f16ddc97af 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java @@ -33,11 +33,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.within; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; class ConditionParserTest { ConditionParser parser; @@ -71,117 +70,118 @@ private ProfileActivationContext createMockContext() { } @Test - void testStringLiterals() { - assertEquals("Hello, World!", parser.parse("'Hello, World!'")); - assertEquals("Hello, World!", parser.parse("\"Hello, World!\"")); + void stringLiterals() { + assertThat(parser.parse("'Hello, World!'")).isEqualTo("Hello, World!"); + assertThat(parser.parse("\"Hello, World!\"")).isEqualTo("Hello, World!"); } @Test - void testStringConcatenation() { - assertEquals("HelloWorld", parser.parse("'Hello' + 'World'")); - assertEquals("Hello123", parser.parse("'Hello' + 123")); + void stringConcatenation() { + assertThat(parser.parse("'Hello' + 'World'")).isEqualTo("HelloWorld"); + assertThat(parser.parse("'Hello' + 123")).isEqualTo("Hello123"); } @Test - void testLengthFunction() { - assertEquals(13, parser.parse("length('Hello, World!')")); - assertEquals(5, parser.parse("length(\"Hello\")")); + void lengthFunction() { + assertThat(parser.parse("length('Hello, World!')")).isEqualTo(13); + assertThat(parser.parse("length(\"Hello\")")).isEqualTo(5); } @Test - void testCaseConversionFunctions() { - assertEquals("HELLO", parser.parse("upper('hello')")); - assertEquals("world", parser.parse("lower('WORLD')")); + void caseConversionFunctions() { + assertThat(parser.parse("upper('hello')")).isEqualTo("HELLO"); + assertThat(parser.parse("lower('WORLD')")).isEqualTo("world"); } @Test - void testConcatFunction() { - assertEquals("HelloWorld", parser.parse("'Hello' + 'World'")); - assertEquals("The answer is 42", parser.parse("'The answer is ' + 42")); - assertEquals("The answer is 42", parser.parse("'The answer is ' + 42.0")); - assertEquals("The answer is 42", parser.parse("'The answer is ' + 42.0f")); - assertEquals("Pi is approximately 3.14", parser.parse("'Pi is approximately ' + 3.14")); - assertEquals("Pi is approximately 3.14", parser.parse("'Pi is approximately ' + 3.14f")); + void concatFunction() { + assertThat(parser.parse("'Hello' + 'World'")).isEqualTo("HelloWorld"); + assertThat(parser.parse("'The answer is ' + 42")).isEqualTo("The answer is 42"); + assertThat(parser.parse("'The answer is ' + 42.0")).isEqualTo("The answer is 42"); + assertThat(parser.parse("'The answer is ' + 42.0f")).isEqualTo("The answer is 42"); + assertThat(parser.parse("'Pi is approximately ' + 3.14")).isEqualTo("Pi is approximately 3.14"); + assertThat(parser.parse("'Pi is approximately ' + 3.14f")).isEqualTo("Pi is approximately 3.14"); } @Test void testToString() { - assertEquals("42", ConditionParser.toString(42)); - assertEquals("42", ConditionParser.toString(42L)); - assertEquals("42", ConditionParser.toString(42.0)); - assertEquals("42", ConditionParser.toString(42.0f)); - assertEquals("3.14", ConditionParser.toString(3.14)); - assertEquals("3.14", ConditionParser.toString(3.14f)); - assertEquals("true", ConditionParser.toString(true)); - assertEquals("false", ConditionParser.toString(false)); - assertEquals("hello", ConditionParser.toString("hello")); + assertThat(ConditionParser.toString(42)).isEqualTo("42"); + assertThat(ConditionParser.toString(42L)).isEqualTo("42"); + assertThat(ConditionParser.toString(42.0)).isEqualTo("42"); + assertThat(ConditionParser.toString(42.0f)).isEqualTo("42"); + assertThat(ConditionParser.toString(3.14)).isEqualTo("3.14"); + assertThat(ConditionParser.toString(3.14f)).isEqualTo("3.14"); + assertThat(ConditionParser.toString(true)).isEqualTo("true"); + assertThat(ConditionParser.toString(false)).isEqualTo("false"); + assertThat(ConditionParser.toString("hello")).isEqualTo("hello"); } @Test - void testSubstringFunction() { - assertEquals("World", parser.parse("substring('Hello, World!', 7, 12)")); - assertEquals("World!", parser.parse("substring('Hello, World!', 7)")); + void substringFunction() { + assertThat(parser.parse("substring('Hello, World!', 7, 12)")).isEqualTo("World"); + assertThat(parser.parse("substring('Hello, World!', 7)")).isEqualTo("World!"); } @Test - void testIndexOf() { - assertEquals(7, parser.parse("indexOf('Hello, World!', 'World')")); - assertEquals(-1, parser.parse("indexOf('Hello, World!', 'OpenAI')")); + void indexOf() { + assertThat(parser.parse("indexOf('Hello, World!', 'World')")).isEqualTo(7); + assertThat(parser.parse("indexOf('Hello, World!', 'OpenAI')")).isEqualTo(-1); } @Test - void testInRange() { - assertTrue((Boolean) parser.parse("inrange('1.8.0_292', '[1.8,2.0)')")); - assertFalse((Boolean) parser.parse("inrange('1.7.0', '[1.8,2.0)')")); + void inRange() { + assertThat((Boolean) parser.parse("inrange('1.8.0_292', '[1.8,2.0)')")).isTrue(); + assertThat((Boolean) parser.parse("inrange('1.7.0', '[1.8,2.0)')")).isFalse(); } @Test - void testIfFunction() { - assertEquals("long", parser.parse("if(length('test') > 3, 'long', 'short')")); - assertEquals("short", parser.parse("if(length('hi') > 3, 'long', 'short')")); + void ifFunction() { + assertThat(parser.parse("if(length('test') > 3, 'long', 'short')")).isEqualTo("long"); + assertThat(parser.parse("if(length('hi') > 3, 'long', 'short')")).isEqualTo("short"); } @Test - void testContainsFunction() { - assertTrue((Boolean) parser.parse("contains('Hello, World!', 'World')")); - assertFalse((Boolean) parser.parse("contains('Hello, World!', 'OpenAI')")); + void containsFunction() { + assertThat((Boolean) parser.parse("contains('Hello, World!', 'World')")).isTrue(); + assertThat((Boolean) parser.parse("contains('Hello, World!', 'OpenAI')")) + .isFalse(); } @Test - void testMatchesFunction() { - assertTrue((Boolean) parser.parse("matches('test123', '\\w+')")); - assertFalse((Boolean) parser.parse("matches('test123', '\\d+')")); + void matchesFunction() { + assertThat((Boolean) parser.parse("matches('test123', '\\w+')")).isTrue(); + assertThat((Boolean) parser.parse("matches('test123', '\\d+')")).isFalse(); } @Test - void testComplexExpression() { + void complexExpression() { String expression = "if(contains(lower('HELLO WORLD'), 'hello'), upper('success') + '!', 'failure')"; - assertEquals("SUCCESS!", parser.parse(expression)); + assertThat(parser.parse(expression)).isEqualTo("SUCCESS!"); } @Test - void testStringComparison() { - assertTrue((Boolean) parser.parse("'abc' != 'cdf'")); - assertFalse((Boolean) parser.parse("'abc' != 'abc'")); - assertTrue((Boolean) parser.parse("'abc' == 'abc'")); - assertFalse((Boolean) parser.parse("'abc' == 'cdf'")); + void stringComparison() { + assertThat((Boolean) parser.parse("'abc' != 'cdf'")).isTrue(); + assertThat((Boolean) parser.parse("'abc' != 'abc'")).isFalse(); + assertThat((Boolean) parser.parse("'abc' == 'abc'")).isTrue(); + assertThat((Boolean) parser.parse("'abc' == 'cdf'")).isFalse(); } @Test - void testParenthesesMismatch() { + void parenthesesMismatch() { functions.put("property", args -> "foo"); functions.put("inrange", args -> false); - assertThrows( - RuntimeException.class, - () -> parser.parse( - "property('os.name') == 'windows' && property('os.arch') != 'amd64') && inrange(property('os.version'), '[99,)')"), - "Should throw RuntimeException due to parentheses mismatch"); - - assertThrows( - RuntimeException.class, - () -> parser.parse( - "(property('os.name') == 'windows' && property('os.arch') != 'amd64') && inrange(property('os.version'), '[99,)'"), - "Should throw RuntimeException due to parentheses mismatch"); + assertThatExceptionOfType(RuntimeException.class) + .as("Should throw RuntimeException due to parentheses mismatch") + .isThrownBy( + () -> parser.parse( + "property('os.name') == 'windows' && property('os.arch') != 'amd64') && inrange(property('os.version'), '[99,)')")); + + assertThatExceptionOfType(RuntimeException.class) + .as("Should throw RuntimeException due to parentheses mismatch") + .isThrownBy( + () -> parser.parse( + "(property('os.name') == 'windows' && property('os.arch') != 'amd64') && inrange(property('os.version'), '[99,)'")); // This should not throw an exception if parentheses are balanced and properties are handled correctly assertDoesNotThrow( @@ -190,80 +190,81 @@ void testParenthesesMismatch() { } @Test - void testBasicArithmetic() { - assertEquals(5.0, parser.parse("2 + 3")); - assertEquals(10.0, parser.parse("15 - 5")); - assertEquals(24.0, parser.parse("6 * 4")); - assertEquals(3.0, parser.parse("9 / 3")); + void basicArithmetic() { + assertThat(parser.parse("2 + 3")).isEqualTo(5.0); + assertThat(parser.parse("15 - 5")).isEqualTo(10.0); + assertThat(parser.parse("6 * 4")).isEqualTo(24.0); + assertThat(parser.parse("9 / 3")).isEqualTo(3.0); } @Test - void testArithmeticPrecedence() { - assertEquals(14.0, parser.parse("2 + 3 * 4")); - assertEquals(20.0, parser.parse("(2 + 3) * 4")); - assertEquals(11.0, parser.parse("15 - 6 + 2")); - assertEquals(10.0, parser.parse("10 / 2 + 2 * 2.5")); + void arithmeticPrecedence() { + assertThat(parser.parse("2 + 3 * 4")).isEqualTo(14.0); + assertThat(parser.parse("(2 + 3) * 4")).isEqualTo(20.0); + assertThat(parser.parse("15 - 6 + 2")).isEqualTo(11.0); + assertThat(parser.parse("10 / 2 + 2 * 2.5")).isEqualTo(10.0); } @Test - void testFloatingPointArithmetic() { - assertEquals(5.5, parser.parse("2.2 + 3.3")); - assertEquals(0.1, (Double) parser.parse("3.3 - 3.2"), 1e-10); - assertEquals(6.25, parser.parse("2.5 * 2.5")); - assertEquals(2.5, parser.parse("5 / 2")); + void floatingPointArithmetic() { + assertThat(parser.parse("2.2 + 3.3")).isEqualTo(5.5); + assertThat((Double) parser.parse("3.3 - 3.2")).isCloseTo(0.1, within(1e-10)); + assertThat(parser.parse("2.5 * 2.5")).isEqualTo(6.25); + assertThat(parser.parse("5 / 2")).isEqualTo(2.5); } @Test - void testArithmeticComparisons() { - assertTrue((Boolean) parser.parse("5 > 3")); - assertTrue((Boolean) parser.parse("3 < 5")); - assertTrue((Boolean) parser.parse("5 >= 5")); - assertTrue((Boolean) parser.parse("3 <= 3")); - assertTrue((Boolean) parser.parse("5 == 5")); - assertTrue((Boolean) parser.parse("5 != 3")); - assertFalse((Boolean) parser.parse("5 < 3")); - assertFalse((Boolean) parser.parse("3 > 5")); - assertFalse((Boolean) parser.parse("5 != 5")); + void arithmeticComparisons() { + assertThat((Boolean) parser.parse("5 > 3")).isTrue(); + assertThat((Boolean) parser.parse("3 < 5")).isTrue(); + assertThat((Boolean) parser.parse("5 >= 5")).isTrue(); + assertThat((Boolean) parser.parse("3 <= 3")).isTrue(); + assertThat((Boolean) parser.parse("5 == 5")).isTrue(); + assertThat((Boolean) parser.parse("5 != 3")).isTrue(); + assertThat((Boolean) parser.parse("5 < 3")).isFalse(); + assertThat((Boolean) parser.parse("3 > 5")).isFalse(); + assertThat((Boolean) parser.parse("5 != 5")).isFalse(); } @Test - void testComplexArithmeticExpressions() { - assertFalse((Boolean) parser.parse("(2 + 3 * 4) > (10 + 5)")); - assertTrue((Boolean) parser.parse("(2 + 3 * 4) < (10 + 5)")); - assertTrue((Boolean) parser.parse("(10 / 2 + 3) == 8")); - assertTrue((Boolean) parser.parse("(10 / 2 + 3) != 9")); + void complexArithmeticExpressions() { + assertThat((Boolean) parser.parse("(2 + 3 * 4) > (10 + 5)")).isFalse(); + assertThat((Boolean) parser.parse("(2 + 3 * 4) < (10 + 5)")).isTrue(); + assertThat((Boolean) parser.parse("(10 / 2 + 3) == 8")).isTrue(); + assertThat((Boolean) parser.parse("(10 / 2 + 3) != 9")).isTrue(); } @Test - void testArithmeticFunctions() { - assertEquals(5.0, parser.parse("2 + 3")); - assertEquals(2.0, parser.parse("5 - 3")); - assertEquals(15.0, parser.parse("3 * 5")); - assertEquals(2.5, parser.parse("5 / 2")); + void arithmeticFunctions() { + assertThat(parser.parse("2 + 3")).isEqualTo(5.0); + assertThat(parser.parse("5 - 3")).isEqualTo(2.0); + assertThat(parser.parse("3 * 5")).isEqualTo(15.0); + assertThat(parser.parse("5 / 2")).isEqualTo(2.5); } @Test - void testCombinedArithmeticAndLogic() { - assertTrue((Boolean) parser.parse("(5 > 3) && (10 / 2 == 5)")); - assertFalse((Boolean) parser.parse("(5 < 3) || (10 / 2 != 5)")); - assertTrue((Boolean) parser.parse("2 + 3 == 1 * 5")); + void combinedArithmeticAndLogic() { + assertThat((Boolean) parser.parse("(5 > 3) && (10 / 2 == 5)")).isTrue(); + assertThat((Boolean) parser.parse("(5 < 3) || (10 / 2 != 5)")).isFalse(); + assertThat((Boolean) parser.parse("2 + 3 == 1 * 5")).isTrue(); } @Test - void testDivisionByZero() { - assertThrows(ArithmeticException.class, () -> parser.parse("5 / 0")); + void divisionByZero() { + assertThatExceptionOfType(ArithmeticException.class).isThrownBy(() -> parser.parse("5 / 0")); } @Test - void testPropertyAlias() { - assertTrue((Boolean) parser.parse("${os.name} == 'windows'")); - assertFalse((Boolean) parser.parse("${os.name} == 'linux'")); - assertTrue((Boolean) parser.parse("${os.arch} == 'amd64' && ${os.name} == 'windows'")); - assertThrows(RuntimeException.class, () -> parser.parse("${unclosed")); + void propertyAlias() { + assertThat((Boolean) parser.parse("${os.name} == 'windows'")).isTrue(); + assertThat((Boolean) parser.parse("${os.name} == 'linux'")).isFalse(); + assertThat((Boolean) parser.parse("${os.arch} == 'amd64' && ${os.name} == 'windows'")) + .isTrue(); + assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> parser.parse("${unclosed")); } @Test - void testNestedPropertyAlias() { + void nestedPropertyAlias() { functions.put("property", args -> { if (args.get(0).equals("project.rootDirectory")) { return "/home/user/project"; @@ -273,27 +274,27 @@ void testNestedPropertyAlias() { functions.put("exists", args -> true); // Mock implementation Object result = parser.parse("exists('${project.rootDirectory}/someFile.txt')"); - assertTrue((Boolean) result); + assertThat((Boolean) result).isTrue(); result = parser.parse("exists('${project.rootDirectory}/${nested.property}/someFile.txt')"); - assertTrue((Boolean) result); + assertThat((Boolean) result).isTrue(); assertDoesNotThrow(() -> parser.parse("property('')")); } @Test - void testToInt() { - assertEquals(123, ConditionParser.toInt(123)); - assertEquals(123, ConditionParser.toInt(123L)); - assertEquals(123, ConditionParser.toInt(123.0)); - assertEquals(123, ConditionParser.toInt(123.5)); // This will truncate the decimal part - assertEquals(123, ConditionParser.toInt("123")); - assertEquals(123, ConditionParser.toInt("123.0")); - assertEquals(123, ConditionParser.toInt("123.5")); // This will truncate the decimal part - assertEquals(1, ConditionParser.toInt(true)); - assertEquals(0, ConditionParser.toInt(false)); - - assertThrows(RuntimeException.class, () -> ConditionParser.toInt("not a number")); - assertThrows(RuntimeException.class, () -> ConditionParser.toInt(new Object())); + void toInt() { + assertThat(ConditionParser.toInt(123)).isEqualTo(123); + assertThat(ConditionParser.toInt(123L)).isEqualTo(123); + assertThat(ConditionParser.toInt(123.0)).isEqualTo(123); + assertThat(ConditionParser.toInt(123.5)).isEqualTo(123); // This will truncate the decimal part + assertThat(ConditionParser.toInt("123")).isEqualTo(123); + assertThat(ConditionParser.toInt("123.0")).isEqualTo(123); + assertThat(ConditionParser.toInt("123.5")).isEqualTo(123); // This will truncate the decimal part + assertThat(ConditionParser.toInt(true)).isEqualTo(1); + assertThat(ConditionParser.toInt(false)).isEqualTo(0); + + assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> ConditionParser.toInt("not a number")); + assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> ConditionParser.toInt(new Object())); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionProfileActivatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionProfileActivatorTest.java index 5d371c2fc3cc..44ebba2a29cc 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionProfileActivatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionProfileActivatorTest.java @@ -39,12 +39,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; -public class ConditionProfileActivatorTest extends AbstractProfileActivatorTest { +class ConditionProfileActivatorTest extends AbstractProfileActivatorTest { @TempDir Path tempDir; @@ -75,7 +73,7 @@ private Map newJdkProperties(String javaVersion) { } @Test - void testNullSafe() throws Exception { + void nullSafe() throws Exception { Profile p = Profile.newInstance(); assertActivation(false, p, newContext(null, null)); @@ -86,7 +84,7 @@ void testNullSafe() throws Exception { } @Test - void testJdkPrefix() throws Exception { + void jdkPrefix() throws Exception { Profile profile = newProfile("inrange(${java.version}, '[1.4,1.5)')"); assertActivation(true, profile, newContext(null, newJdkProperties("1.4"))); @@ -100,7 +98,7 @@ void testJdkPrefix() throws Exception { } @Test - void testJdkPrefixNegated() throws Exception { + void jdkPrefixNegated() throws Exception { Profile profile = newProfile("not(inrange(${java.version}, '[1.4,1.5)'))"); assertActivation(false, profile, newContext(null, newJdkProperties("1.4"))); @@ -114,7 +112,7 @@ void testJdkPrefixNegated() throws Exception { } @Test - void testJdkVersionRangeInclusiveBounds() throws Exception { + void jdkVersionRangeInclusiveBounds() throws Exception { Profile profile = newProfile("inrange(${java.version}, '[1.5,1.6.1]')"); assertActivation(false, profile, newContext(null, newJdkProperties("1.4"))); @@ -135,7 +133,7 @@ void testJdkVersionRangeInclusiveBounds() throws Exception { } @Test - void testJdkVersionRangeExclusiveBounds() throws Exception { + void jdkVersionRangeExclusiveBounds() throws Exception { Profile profile = newProfile("inrange(${java.version}, '[1.3.1,1.6)')"); assertActivation(false, profile, newContext(null, newJdkProperties("1.3"))); @@ -157,7 +155,7 @@ void testJdkVersionRangeExclusiveBounds() throws Exception { } @Test - void testJdkVersionRangeInclusiveLowerBound() throws Exception { + void jdkVersionRangeInclusiveLowerBound() throws Exception { Profile profile = newProfile("inrange(${java.version}, '[1.5,)')"); assertActivation(false, profile, newContext(null, newJdkProperties("1.4"))); @@ -178,7 +176,7 @@ void testJdkVersionRangeInclusiveLowerBound() throws Exception { } @Test - void testJdkVersionRangeExclusiveUpperBound() throws Exception { + void jdkVersionRangeExclusiveUpperBound() throws Exception { Profile profile = newProfile("inrange(${java.version}, '(,1.6)')"); assertActivation(true, profile, newContext(null, newJdkProperties("1.5"))); @@ -195,7 +193,7 @@ void testJdkVersionRangeExclusiveUpperBound() throws Exception { @Disabled @Test - void testJdkRubbishJavaVersion() { + void jdkRubbishJavaVersion() { Profile profile = newProfile("inrange(${java.version}, '[1.8,)')"); assertActivationWithProblems(profile, newContext(null, newJdkProperties("Pūteketeke")), "invalid JDK version"); @@ -208,13 +206,17 @@ private void assertActivationWithProblems( Profile profile, ProfileActivationContext context, String warningContains) { SimpleProblemCollector problems = new SimpleProblemCollector(); - assertFalse(activator.isActive(profile, context, problems)); + assertThat(activator.isActive(profile, context, problems)).isFalse(); - assertEquals(0, problems.getErrors().size(), problems.getErrors().toString()); - assertEquals(1, problems.getWarnings().size(), problems.getWarnings().toString()); - assertTrue( - problems.getWarnings().get(0).contains(warningContains), - problems.getWarnings().toString()); + assertThat(problems.getErrors().size()) + .as(problems.getErrors().toString()) + .isEqualTo(0); + assertThat(problems.getWarnings().size()) + .as(problems.getWarnings().toString()) + .isEqualTo(1); + assertThat(problems.getWarnings().get(0).contains(warningContains)) + .as(problems.getWarnings().toString()) + .isTrue(); } private Map newOsProperties(String osName, String osVersion, String osArch) { @@ -222,7 +224,7 @@ private Map newOsProperties(String osName, String osVersion, Str } @Test - void testOsVersionStringComparison() throws Exception { + void osVersionStringComparison() throws Exception { Profile profile = newProfile("inrange(${os.version}, '[6.5.0-1014-aws,6.6)')"); assertActivation(true, profile, newContext(null, newOsProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -232,7 +234,7 @@ void testOsVersionStringComparison() throws Exception { } @Test - void testOsVersionRegexMatching() throws Exception { + void osVersionRegexMatching() throws Exception { Profile profile = newProfile("matches(${os.version}, '.*aws')"); assertActivation(true, profile, newContext(null, newOsProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -242,7 +244,7 @@ void testOsVersionRegexMatching() throws Exception { } @Test - void testOsName() { + void osName() { Profile profile = newProfile("${os.name} == 'windows'"); assertActivation(false, profile, newContext(null, newOsProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -250,7 +252,7 @@ void testOsName() { } @Test - void testOsNegatedName() { + void osNegatedName() { Profile profile = newProfile("${os.name} != 'windows'"); assertActivation(true, profile, newContext(null, newOsProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -258,7 +260,7 @@ void testOsNegatedName() { } @Test - void testOsArch() { + void osArch() { Profile profile = newProfile("${os.arch} == 'amd64'"); assertActivation(true, profile, newContext(null, newOsProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -266,7 +268,7 @@ void testOsArch() { } @Test - void testOsNegatedArch() { + void osNegatedArch() { Profile profile = newProfile("${os.arch} != 'amd64'"); assertActivation(false, profile, newContext(null, newOsProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -274,7 +276,7 @@ void testOsNegatedArch() { } @Test - void testOsAllConditions() { + void osAllConditions() { Profile profile = newProfile("${os.name} == 'windows' && ${os.arch} != 'amd64' && inrange(${os.version}, '[99,)')"); @@ -285,7 +287,7 @@ void testOsAllConditions() { } @Test - public void testOsCapitalName() { + void osCapitalName() { Profile profile = newProfile("lower(${os.name}) == 'mac os x'"); assertActivation(false, profile, newContext(null, newOsProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -299,7 +301,7 @@ private Map newPropProperties(String key, String value) { } @Test - void testPropWithNameOnlyUserProperty() throws Exception { + void propWithNameOnlyUserProperty() throws Exception { Profile profile = newProfile("${prop}"); assertActivation(true, profile, newContext(newPropProperties("prop", "value"), null)); @@ -308,7 +310,7 @@ void testPropWithNameOnlyUserProperty() throws Exception { } @Test - void testPropWithNameOnlySystemProperty() throws Exception { + void propWithNameOnlySystemProperty() throws Exception { Profile profile = newProfile("${prop}"); assertActivation(true, profile, newContext(null, newPropProperties("prop", "value"))); @@ -317,7 +319,7 @@ void testPropWithNameOnlySystemProperty() throws Exception { } @Test - void testPropWithNegatedNameOnlyUserProperty() throws Exception { + void propWithNegatedNameOnlyUserProperty() throws Exception { Profile profile = newProfile("not(${prop})"); assertActivation(false, profile, newContext(newPropProperties("prop", "value"), null)); @@ -326,7 +328,7 @@ void testPropWithNegatedNameOnlyUserProperty() throws Exception { } @Test - void testPropWithNegatedNameOnlySystemProperty() throws Exception { + void propWithNegatedNameOnlySystemProperty() throws Exception { Profile profile = newProfile("not(${prop})"); assertActivation(false, profile, newContext(null, newPropProperties("prop", "value"))); @@ -335,7 +337,7 @@ void testPropWithNegatedNameOnlySystemProperty() throws Exception { } @Test - void testPropWithValueUserProperty() throws Exception { + void propWithValueUserProperty() throws Exception { Profile profile = newProfile("${prop} == 'value'"); assertActivation(true, profile, newContext(newPropProperties("prop", "value"), null)); @@ -344,7 +346,7 @@ void testPropWithValueUserProperty() throws Exception { } @Test - void testPropWithValueSystemProperty() throws Exception { + void propWithValueSystemProperty() throws Exception { Profile profile = newProfile("${prop} == 'value'"); assertActivation(true, profile, newContext(null, newPropProperties("prop", "value"))); @@ -353,7 +355,7 @@ void testPropWithValueSystemProperty() throws Exception { } @Test - void testPropWithNegatedValueUserProperty() throws Exception { + void propWithNegatedValueUserProperty() throws Exception { Profile profile = newProfile("${prop} != 'value'"); assertActivation(false, profile, newContext(newPropProperties("prop", "value"), null)); @@ -362,7 +364,7 @@ void testPropWithNegatedValueUserProperty() throws Exception { } @Test - void testPropWithNegatedValueSystemProperty() throws Exception { + void propWithNegatedValueSystemProperty() throws Exception { Profile profile = newProfile("${prop} != 'value'"); assertActivation(false, profile, newContext(null, newPropProperties("prop", "value"))); @@ -371,7 +373,7 @@ void testPropWithNegatedValueSystemProperty() throws Exception { } @Test - void testPropWithValueUserPropertyDominantOverSystemProperty() throws Exception { + void propWithValueUserPropertyDominantOverSystemProperty() throws Exception { Profile profile = newProfile("${prop} == 'value'"); Map props1 = newPropProperties("prop", "value"); @@ -383,15 +385,16 @@ void testPropWithValueUserPropertyDominantOverSystemProperty() throws Exception @Test @Disabled - void testFileRootDirectoryWithNull() { - IllegalStateException e = assertThrows( - IllegalStateException.class, - () -> assertActivation(false, newProfile("exists('${project.rootDirectory}')"), newFileContext(null))); - assertEquals(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE, e.getMessage()); + void fileRootDirectoryWithNull() { + IllegalStateException e = assertThatExceptionOfType(IllegalStateException.class) + .isThrownBy(() -> + assertActivation(false, newProfile("exists('${project.rootDirectory}')"), newFileContext(null))) + .actual(); + assertThat(e.getMessage()).isEqualTo(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE); } @Test - void testFileRootDirectory() { + void fileRootDirectory() { assertActivation(false, newProfile("exists('${project.rootDirectory}/someFile.txt')"), newFileContext()); assertActivation(true, newProfile("missing('${project.rootDirectory}/someFile.txt')"), newFileContext()); assertActivation(true, newProfile("exists('${project.rootDirectory}')"), newFileContext()); @@ -402,7 +405,7 @@ void testFileRootDirectory() { @Test @Disabled - void testFileWilcards() { + void fileWilcards() { assertActivation(true, newProfile("exists('${project.rootDirectory}/**/*.xsd')"), newFileContext()); assertActivation(true, newProfile("exists('${project.basedir}/**/*.xsd')"), newFileContext()); assertActivation(true, newProfile("exists('${project.basedir}/**/*.xsd')"), newFileContext()); @@ -411,7 +414,7 @@ void testFileWilcards() { } @Test - void testFileIsActiveNoFileWithShortBasedir() { + void fileIsActiveNoFileWithShortBasedir() { assertActivation(false, newExistsProfile(null), newFileContext()); assertActivation(false, newProfile("exists('someFile.txt')"), newFileContext()); assertActivation(false, newProfile("exists('${basedir}/someFile.txt')"), newFileContext()); @@ -422,7 +425,7 @@ void testFileIsActiveNoFileWithShortBasedir() { } @Test - void testFileIsActiveNoFile() { + void fileIsActiveNoFile() { assertActivation(false, newExistsProfile(null), newFileContext()); assertActivation(false, newProfile("exists('someFile.txt')"), newFileContext()); assertActivation(false, newProfile("exists('${project.basedir}/someFile.txt')"), newFileContext()); @@ -433,7 +436,7 @@ void testFileIsActiveNoFile() { } @Test - void testFileIsActiveExistsFileExists() { + void fileIsActiveExistsFileExists() { assertActivation(true, newProfile("exists('file.txt')"), newFileContext()); assertActivation(true, newProfile("exists('${project.basedir}')"), newFileContext()); assertActivation(true, newProfile("exists('${project.basedir}/file.txt')"), newFileContext()); diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/FileProfileActivatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/FileProfileActivatorTest.java index c7312beb66d2..858ca0c4b186 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/FileProfileActivatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/FileProfileActivatorTest.java @@ -32,8 +32,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; /** * Tests {@link FileProfileActivator}. @@ -60,17 +60,17 @@ void setUp() throws Exception { } @Test - void testRootDirectoryWithNull() { + void rootDirectoryWithNull() { context.setModel(Model.newInstance()); - NullPointerException e = assertThrows( - NullPointerException.class, - () -> assertActivation(false, newExistsProfile("${project.rootDirectory}"), context)); - assertEquals(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE, e.getMessage()); + NullPointerException e = assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> assertActivation(false, newExistsProfile("${project.rootDirectory}"), context)) + .actual(); + assertThat(e.getMessage()).isEqualTo(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE); } @Test - void testRootDirectory() { + void rootDirectory() { assertActivation(false, newExistsProfile("${project.rootDirectory}/someFile.txt"), context); assertActivation(true, newMissingProfile("${project.rootDirectory}/someFile.txt"), context); assertActivation(true, newExistsProfile("${project.rootDirectory}"), context); @@ -80,7 +80,7 @@ void testRootDirectory() { } @Test - void testIsActiveNoFileWithShortBasedir() { + void isActiveNoFileWithShortBasedir() { assertActivation(false, newExistsProfile(null), context); assertActivation(false, newExistsProfile("someFile.txt"), context); assertActivation(false, newExistsProfile("${basedir}/someFile.txt"), context); @@ -91,7 +91,7 @@ void testIsActiveNoFileWithShortBasedir() { } @Test - void testIsActiveNoFile() { + void isActiveNoFile() { assertActivation(false, newExistsProfile(null), context); assertActivation(false, newExistsProfile("someFile.txt"), context); assertActivation(false, newExistsProfile("${project.basedir}/someFile.txt"), context); @@ -102,7 +102,7 @@ void testIsActiveNoFile() { } @Test - void testIsActiveExistsFileExists() { + void isActiveExistsFileExists() { assertActivation(true, newExistsProfile("file.txt"), context); assertActivation(true, newExistsProfile("${project.basedir}"), context); assertActivation(true, newExistsProfile("${project.basedir}/" + "file.txt"), context); @@ -113,13 +113,13 @@ void testIsActiveExistsFileExists() { } @Test - void testIsActiveExistsLeavesFileUnchanged() { + void isActiveExistsLeavesFileUnchanged() { Profile profile = newExistsProfile("file.txt"); - assertEquals("file.txt", profile.getActivation().getFile().getExists()); + assertThat(profile.getActivation().getFile().getExists()).isEqualTo("file.txt"); assertActivation(true, profile, context); - assertEquals("file.txt", profile.getActivation().getFile().getExists()); + assertThat(profile.getActivation().getFile().getExists()).isEqualTo("file.txt"); } private Profile newExistsProfile(String filePath) { diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/JdkVersionProfileActivatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/JdkVersionProfileActivatorTest.java index 9f72bee87af1..e3ed739dad10 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/JdkVersionProfileActivatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/JdkVersionProfileActivatorTest.java @@ -26,9 +26,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests {@link JdkVersionProfileActivator}. @@ -55,7 +53,7 @@ private Map newProperties(String javaVersion) { } @Test - void testNullSafe() throws Exception { + void nullSafe() throws Exception { Profile p = Profile.newInstance(); assertActivation(false, p, newContext(null, null)); @@ -66,7 +64,7 @@ void testNullSafe() throws Exception { } @Test - void testPrefix() throws Exception { + void prefix() throws Exception { Profile profile = newProfile("1.4"); assertActivation(true, profile, newContext(null, newProperties("1.4"))); @@ -80,7 +78,7 @@ void testPrefix() throws Exception { } @Test - void testPrefixNegated() throws Exception { + void prefixNegated() throws Exception { Profile profile = newProfile("!1.4"); assertActivation(false, profile, newContext(null, newProperties("1.4"))); @@ -94,7 +92,7 @@ void testPrefixNegated() throws Exception { } @Test - void testVersionRangeInclusiveBounds() throws Exception { + void versionRangeInclusiveBounds() throws Exception { Profile profile = newProfile("[1.5,1.6]"); assertActivation(false, profile, newContext(null, newProperties("1.4"))); @@ -115,7 +113,7 @@ void testVersionRangeInclusiveBounds() throws Exception { } @Test - void testVersionRangeExclusiveBounds() throws Exception { + void versionRangeExclusiveBounds() throws Exception { Profile profile = newProfile("(1.3,1.6)"); assertActivation(false, profile, newContext(null, newProperties("1.3"))); @@ -137,7 +135,7 @@ void testVersionRangeExclusiveBounds() throws Exception { } @Test - void testVersionRangeInclusiveLowerBound() throws Exception { + void versionRangeInclusiveLowerBound() throws Exception { Profile profile = newProfile("[1.5,)"); assertActivation(false, profile, newContext(null, newProperties("1.4"))); @@ -158,7 +156,7 @@ void testVersionRangeInclusiveLowerBound() throws Exception { } @Test - void testVersionRangeExclusiveUpperBound() throws Exception { + void versionRangeExclusiveUpperBound() throws Exception { Profile profile = newProfile("(,1.6)"); assertActivation(true, profile, newContext(null, newProperties("1.5"))); @@ -174,7 +172,7 @@ void testVersionRangeExclusiveUpperBound() throws Exception { } @Test - void testRubbishJavaVersion() { + void rubbishJavaVersion() { Profile profile = newProfile("[1.8,)"); assertActivationWithProblems(profile, newContext(null, newProperties("Pūteketeke")), "invalid JDK version"); @@ -187,10 +185,10 @@ private void assertActivationWithProblems( Profile profile, ProfileActivationContext context, String warningContains) { SimpleProblemCollector problems = new SimpleProblemCollector(); - assertFalse(activator.isActive(profile, context, problems)); + assertThat(activator.isActive(profile, context, problems)).isFalse(); - assertEquals(0, problems.getErrors().size()); - assertEquals(1, problems.getWarnings().size()); - assertTrue(problems.getWarnings().get(0).contains(warningContains)); + assertThat(problems.getErrors().size()).isEqualTo(0); + assertThat(problems.getWarnings().size()).isEqualTo(1); + assertThat(problems.getWarnings().get(0).contains(warningContains)).isTrue(); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivatorTest.java index 4f228a5f1495..d247207a4439 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivatorTest.java @@ -51,7 +51,7 @@ private Map newProperties(String osName, String osVersion, Strin } @Test - void testVersionStringComparison() throws Exception { + void versionStringComparison() throws Exception { Profile profile = newProfile(ActivationOS.newBuilder().version("6.5.0-1014-aws")); assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -61,7 +61,7 @@ void testVersionStringComparison() throws Exception { } @Test - void testVersionRegexMatching() throws Exception { + void versionRegexMatching() throws Exception { Profile profile = newProfile(ActivationOS.newBuilder().version("regex:.*aws")); assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -71,7 +71,7 @@ void testVersionRegexMatching() throws Exception { } @Test - void testName() { + void name() { Profile profile = newProfile(ActivationOS.newBuilder().name("windows")); assertActivation(false, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -79,7 +79,7 @@ void testName() { } @Test - void testNegatedName() { + void negatedName() { Profile profile = newProfile(ActivationOS.newBuilder().name("!windows")); assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -87,7 +87,7 @@ void testNegatedName() { } @Test - void testArch() { + void arch() { Profile profile = newProfile(ActivationOS.newBuilder().arch("amd64")); assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -95,7 +95,7 @@ void testArch() { } @Test - void testNegatedArch() { + void negatedArch() { Profile profile = newProfile(ActivationOS.newBuilder().arch("!amd64")); assertActivation(false, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -103,7 +103,7 @@ void testNegatedArch() { } @Test - void testFamily() { + void family() { Profile profile = newProfile(ActivationOS.newBuilder().family("windows")); assertActivation(false, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -111,7 +111,7 @@ void testFamily() { } @Test - void testNegatedFamily() { + void negatedFamily() { Profile profile = newProfile(ActivationOS.newBuilder().family("!windows")); assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64"))); @@ -119,7 +119,7 @@ void testNegatedFamily() { } @Test - void testAllOsConditions() { + void allOsConditions() { Profile profile = newProfile(ActivationOS.newBuilder() .family("windows") .name("windows") @@ -133,7 +133,7 @@ void testAllOsConditions() { } @Test - void testCapitalOsName() { + void capitalOsName() { Profile profile = newProfile(ActivationOS.newBuilder() .family("Mac") .name("Mac OS X") diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/PropertyProfileActivatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/PropertyProfileActivatorTest.java index 0f193614b20f..d9fb5898e9b7 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/PropertyProfileActivatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/PropertyProfileActivatorTest.java @@ -54,7 +54,7 @@ private Map newProperties(String key, String value) { } @Test - void testNullSafe() throws Exception { + void nullSafe() throws Exception { Profile p = Profile.newInstance(); assertActivation(false, p, newContext(null, null)); @@ -65,7 +65,7 @@ void testNullSafe() throws Exception { } @Test - void testWithNameOnlyUserProperty() throws Exception { + void withNameOnlyUserProperty() throws Exception { Profile profile = newProfile("prop", null); assertActivation(true, profile, newContext(newProperties("prop", "value"), null)); @@ -76,7 +76,7 @@ void testWithNameOnlyUserProperty() throws Exception { } @Test - void testWithNameOnlySystemProperty() throws Exception { + void withNameOnlySystemProperty() throws Exception { Profile profile = newProfile("prop", null); assertActivation(true, profile, newContext(null, newProperties("prop", "value"))); @@ -87,7 +87,7 @@ void testWithNameOnlySystemProperty() throws Exception { } @Test - void testWithNegatedNameOnlyUserProperty() throws Exception { + void withNegatedNameOnlyUserProperty() throws Exception { Profile profile = newProfile("!prop", null); assertActivation(false, profile, newContext(newProperties("prop", "value"), null)); @@ -98,7 +98,7 @@ void testWithNegatedNameOnlyUserProperty() throws Exception { } @Test - void testWithNegatedNameOnlySystemProperty() throws Exception { + void withNegatedNameOnlySystemProperty() throws Exception { Profile profile = newProfile("!prop", null); assertActivation(false, profile, newContext(null, newProperties("prop", "value"))); @@ -109,7 +109,7 @@ void testWithNegatedNameOnlySystemProperty() throws Exception { } @Test - void testWithValueUserProperty() throws Exception { + void withValueUserProperty() throws Exception { Profile profile = newProfile("prop", "value"); assertActivation(true, profile, newContext(newProperties("prop", "value"), null)); @@ -120,7 +120,7 @@ void testWithValueUserProperty() throws Exception { } @Test - void testWithValueSystemProperty() throws Exception { + void withValueSystemProperty() throws Exception { Profile profile = newProfile("prop", "value"); assertActivation(true, profile, newContext(null, newProperties("prop", "value"))); @@ -131,7 +131,7 @@ void testWithValueSystemProperty() throws Exception { } @Test - void testWithNegatedValueUserProperty() throws Exception { + void withNegatedValueUserProperty() throws Exception { Profile profile = newProfile("prop", "!value"); assertActivation(false, profile, newContext(newProperties("prop", "value"), null)); @@ -142,7 +142,7 @@ void testWithNegatedValueUserProperty() throws Exception { } @Test - void testWithNegatedValueSystemProperty() throws Exception { + void withNegatedValueSystemProperty() throws Exception { Profile profile = newProfile("prop", "!value"); assertActivation(false, profile, newContext(null, newProperties("prop", "value"))); @@ -153,7 +153,7 @@ void testWithNegatedValueSystemProperty() throws Exception { } @Test - void testWithValueUserPropertyDominantOverSystemProperty() throws Exception { + void withValueUserPropertyDominantOverSystemProperty() throws Exception { Profile profile = newProfile("prop", "value"); Map props1 = newProperties("prop", "value"); diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/resolver/DefaultModelResolverTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/resolver/DefaultModelResolverTest.java index e680267895ad..0e779367e5d2 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/resolver/DefaultModelResolverTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/resolver/DefaultModelResolverTest.java @@ -39,11 +39,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; /** * Test cases for the project {@code ModelResolver} implementation. @@ -58,75 +57,74 @@ void setup() { Path localRepoPath = basedir.resolve("target/local-repo"); Path remoteRepoPath = basedir.resolve("src/test/remote-repo"); Session s = ApiRunner.createSession( - injector -> { - injector.bindInstance(DefaultModelResolverTest.class, this); - }, - localRepoPath); + injector -> injector.bindInstance(DefaultModelResolverTest.class, this), localRepoPath); RemoteRepository remoteRepository = s.createRemoteRepository( RemoteRepository.CENTRAL_ID, remoteRepoPath.toUri().toString()); session = s.withRemoteRepositories(List.of(remoteRepository)); } @Test - void testResolveParentThrowsModelResolverExceptionWhenNotFound() throws Exception { + void resolveParentThrowsModelResolverExceptionWhenNotFound() throws Exception { final Parent parent = Parent.newBuilder() .groupId("org.apache") .artifactId("apache") .version("0") .build(); - ModelResolverException e = assertThrows( - ModelResolverException.class, - () -> newModelResolver().resolveModel(session, null, parent, new AtomicReference<>()), - "Expected 'ModelResolverException' not thrown."); - assertNotNull(e.getMessage()); + ModelResolverException e = assertThatExceptionOfType(ModelResolverException.class) + .as("Expected 'ModelResolverException' not thrown.") + .isThrownBy(() -> newModelResolver().resolveModel(session, null, parent, new AtomicReference<>())) + .actual(); + assertThat(e.getMessage()).isNotNull(); assertThat(e.getMessage(), containsString("Could not find artifact org.apache:apache:pom:0 in central")); } @Test - void testResolveParentThrowsModelResolverExceptionWhenNoMatchingVersionFound() throws Exception { + void resolveParentThrowsModelResolverExceptionWhenNoMatchingVersionFound() throws Exception { final Parent parent = Parent.newBuilder() .groupId("org.apache") .artifactId("apache") .version("[2.0,2.1)") .build(); - ModelResolverException e = assertThrows( - ModelResolverException.class, - () -> newModelResolver().resolveModel(session, null, parent, new AtomicReference<>()), - "Expected 'ModelResolverException' not thrown."); - assertEquals("No versions matched the requested parent version range '[2.0,2.1)'", e.getMessage()); + ModelResolverException e = assertThatExceptionOfType(ModelResolverException.class) + .as("Expected 'ModelResolverException' not thrown.") + .isThrownBy(() -> newModelResolver().resolveModel(session, null, parent, new AtomicReference<>())) + .actual(); + assertThat(e.getMessage()).isEqualTo("No versions matched the requested parent version range '[2.0,2.1)'"); } @Test - void testResolveParentThrowsModelResolverExceptionWhenUsingRangesWithoutUpperBound() throws Exception { + void resolveParentThrowsModelResolverExceptionWhenUsingRangesWithoutUpperBound() throws Exception { final Parent parent = Parent.newBuilder() .groupId("org.apache") .artifactId("apache") .version("[1,)") .build(); - ModelResolverException e = assertThrows( - ModelResolverException.class, - () -> newModelResolver().resolveModel(session, null, parent, new AtomicReference<>()), - "Expected 'ModelResolverException' not thrown."); - assertEquals("The requested parent version range '[1,)' does not specify an upper bound", e.getMessage()); + ModelResolverException e = assertThatExceptionOfType(ModelResolverException.class) + .as("Expected 'ModelResolverException' not thrown.") + .isThrownBy(() -> newModelResolver().resolveModel(session, null, parent, new AtomicReference<>())) + .actual(); + assertThat(e.getMessage()) + .isEqualTo("The requested parent version range '[1,)' does not specify an upper bound"); } @Test - void testResolveParentSuccessfullyResolvesExistingParentWithoutRange() throws Exception { + void resolveParentSuccessfullyResolvesExistingParentWithoutRange() throws Exception { final Parent parent = Parent.newBuilder() .groupId("org.apache") .artifactId("apache") .version("1") .build(); - assertNotNull(this.newModelResolver().resolveModel(session, null, parent, new AtomicReference<>())); - assertEquals("1", parent.getVersion()); + assertThat(this.newModelResolver().resolveModel(session, null, parent, new AtomicReference<>())) + .isNotNull(); + assertThat(parent.getVersion()).isEqualTo("1"); } @Test - void testResolveParentSuccessfullyResolvesExistingParentUsingHighestVersion() throws Exception { + void resolveParentSuccessfullyResolvesExistingParentUsingHighestVersion() throws Exception { final Parent parent = Parent.newBuilder() .groupId("org.apache") .artifactId("apache") @@ -134,70 +132,73 @@ void testResolveParentSuccessfullyResolvesExistingParentUsingHighestVersion() th .build(); AtomicReference modified = new AtomicReference<>(); - assertNotNull(this.newModelResolver().resolveModel(session, null, parent, modified)); - assertEquals("1", modified.get().getVersion()); + assertThat(this.newModelResolver().resolveModel(session, null, parent, modified)) + .isNotNull(); + assertThat(modified.get().getVersion()).isEqualTo("1"); } @Test - void testResolveDependencyThrowsModelResolverExceptionWhenNotFound() throws Exception { + void resolveDependencyThrowsModelResolverExceptionWhenNotFound() throws Exception { final Dependency dependency = Dependency.newBuilder() .groupId("org.apache") .artifactId("apache") .version("0") .build(); - ModelResolverException e = assertThrows( - ModelResolverException.class, - () -> newModelResolver().resolveModel(session, null, dependency, new AtomicReference<>()), - "Expected 'ModelResolverException' not thrown."); - assertNotNull(e.getMessage()); + ModelResolverException e = assertThatExceptionOfType(ModelResolverException.class) + .as("Expected 'ModelResolverException' not thrown.") + .isThrownBy(() -> newModelResolver().resolveModel(session, null, dependency, new AtomicReference<>())) + .actual(); + assertThat(e.getMessage()).isNotNull(); assertThat(e.getMessage(), containsString("Could not find artifact org.apache:apache:pom:0 in central")); } @Test - void testResolveDependencyThrowsModelResolverExceptionWhenNoMatchingVersionFound() throws Exception { + void resolveDependencyThrowsModelResolverExceptionWhenNoMatchingVersionFound() throws Exception { final Dependency dependency = Dependency.newBuilder() .groupId("org.apache") .artifactId("apache") .version("[2.0,2.1)") .build(); - ModelResolverException e = assertThrows( - ModelResolverException.class, - () -> newModelResolver().resolveModel(session, null, dependency, new AtomicReference<>()), - "Expected 'ModelResolverException' not thrown."); - assertEquals("No versions matched the requested dependency version range '[2.0,2.1)'", e.getMessage()); + ModelResolverException e = assertThatExceptionOfType(ModelResolverException.class) + .as("Expected 'ModelResolverException' not thrown.") + .isThrownBy(() -> newModelResolver().resolveModel(session, null, dependency, new AtomicReference<>())) + .actual(); + assertThat(e.getMessage()).isEqualTo("No versions matched the requested dependency version range '[2.0,2.1)'"); } @Test - void testResolveDependencyThrowsModelResolverExceptionWhenUsingRangesWithoutUpperBound() throws Exception { + void resolveDependencyThrowsModelResolverExceptionWhenUsingRangesWithoutUpperBound() throws Exception { final Dependency dependency = Dependency.newBuilder() .groupId("org.apache") .artifactId("apache") .version("[1,)") .build(); - ModelResolverException e = assertThrows( - ModelResolverException.class, - () -> newModelResolver().resolveModel(session, null, dependency, new AtomicReference<>()), - "Expected 'ModelResolverException' not thrown."); - assertEquals("The requested dependency version range '[1,)' does not specify an upper bound", e.getMessage()); + ModelResolverException e = assertThatExceptionOfType(ModelResolverException.class) + .as("Expected 'ModelResolverException' not thrown.") + .isThrownBy(() -> newModelResolver().resolveModel(session, null, dependency, new AtomicReference<>())) + .actual(); + assertThat(e.getMessage()) + .isEqualTo("The requested dependency version range '[1,)' does not specify an upper bound"); } @Test - void testResolveDependencySuccessfullyResolvesExistingDependencyWithoutRange() throws Exception { + void resolveDependencySuccessfullyResolvesExistingDependencyWithoutRange() throws Exception { final Dependency dependency = Dependency.newBuilder() .groupId("org.apache") .artifactId("apache") .version("1") .build(); - assertNotNull(this.newModelResolver().resolveModel(session, null, dependency, new AtomicReference<>())); - assertEquals("1", dependency.getVersion()); + assertThat(this.newModelResolver().resolveModel(session, null, dependency, new AtomicReference<>())) + .isNotNull(); + assertThat(dependency.getVersion()).isEqualTo("1"); } @Test - void testResolveDependencySuccessfullyResolvesExistingDependencyUsingHighestVersion() throws Exception { + void resolveDependencySuccessfullyResolvesExistingDependencyUsingHighestVersion() throws Exception { final Dependency dependency = Dependency.newBuilder() .groupId("org.apache") .artifactId("apache") @@ -205,8 +206,9 @@ void testResolveDependencySuccessfullyResolvesExistingDependencyUsingHighestVers .build(); AtomicReference modified = new AtomicReference<>(); - assertNotNull(this.newModelResolver().resolveModel(session, null, dependency, modified)); - assertEquals("1", modified.get().getVersion()); + assertThat(this.newModelResolver().resolveModel(session, null, dependency, modified)) + .isNotNull(); + assertThat(modified.get().getVersion()).isEqualTo("1"); } private ModelResolver newModelResolver() throws Exception { diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/standalone/DiTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/standalone/DiTest.java index 10512a384373..fd02267b7b13 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/standalone/DiTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/standalone/DiTest.java @@ -26,14 +26,14 @@ import org.apache.maven.impl.ExtensibleEnumRegistries; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; class DiTest { @Test - void testGenerics() { + void generics() { Set types = Types.getAllSuperTypes(ExtensibleEnumRegistries.DefaultPathScopeRegistry.class); - assertNotNull(types); + assertThat(types).isNotNull(); Injector injector = Injector.create(); injector.bindImplicit(ExtensibleEnumRegistries.DefaultPathScopeRegistry.class); diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/standalone/RequestTraceTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/standalone/RequestTraceTest.java index 934350477018..d5e75ee059d5 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/standalone/RequestTraceTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/standalone/RequestTraceTest.java @@ -48,14 +48,12 @@ import org.eclipse.aether.transport.file.FileTransporterFactory; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class RequestTraceTest { @Test - void testTraces() { + void traces() { Session session = ApiRunner.createSession(injector -> { injector.bindInstance(RequestTraceTest.class, this); }); @@ -68,7 +66,7 @@ void testTraces() { .requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT) .recursive(true) .build()); - assertNotNull(result.getEffectiveModel()); + assertThat(result.getEffectiveModel()).isNotNull(); List events = new CopyOnWriteArrayList<>(); ((DefaultRepositorySystemSession) InternalSession.from(session).getSession()) @@ -82,9 +80,9 @@ public void artifactResolved(RepositoryEvent event) { ArtifactCoordinates coords = session.createArtifactCoordinates("org.apache.maven:maven-api-core:4.0.0-alpha-13"); DownloadedArtifact res = session.resolveArtifact(coords); - assertNotNull(res); - assertNotNull(res.getPath()); - assertTrue(Files.exists(res.getPath())); + assertThat(res).isNotNull(); + assertThat(res.getPath()).isNotNull(); + assertThat(Files.exists(res.getPath())).isTrue(); Node node = session.getService(DependencyResolver.class) .collect(DependencyResolverRequest.builder() @@ -101,15 +99,15 @@ public void artifactResolved(RepositoryEvent event) { for (RepositoryEvent event : events) { org.eclipse.aether.RequestTrace trace = event.getTrace(); - assertNotNull(trace); + assertThat(trace).isNotNull(); RequestTrace rTrace = RequestTraceHelper.toMaven("collect", trace); - assertNotNull(rTrace); - assertNotNull(rTrace.parent()); + assertThat(rTrace).isNotNull(); + assertThat(rTrace.parent()).isNotNull(); } - assertNotNull(node); - assertEquals(6, node.getChildren().size()); + assertThat(node).isNotNull(); + assertThat(node.getChildren().size()).isEqualTo(6); } @Provides diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/standalone/TestApiStandalone.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/standalone/TestApiStandalone.java index a0c519a9eaf5..e00d504072bb 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/standalone/TestApiStandalone.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/standalone/TestApiStandalone.java @@ -38,14 +38,12 @@ import org.eclipse.aether.transport.file.FileTransporterFactory; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class TestApiStandalone { @Test - void testStandalone() { + void standalone() { Session session = ApiRunner.createSession(injector -> { injector.bindInstance(TestApiStandalone.class, this); }); @@ -58,18 +56,18 @@ void testStandalone() { .requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT) .recursive(true) .build()); - assertNotNull(result.getEffectiveModel()); + assertThat(result.getEffectiveModel()).isNotNull(); ArtifactCoordinates coords = session.createArtifactCoordinates("org.apache.maven:maven-api-core:4.0.0-alpha-13"); DownloadedArtifact res = session.resolveArtifact(coords); - assertNotNull(res); - assertNotNull(res.getPath()); - assertTrue(Files.exists(res.getPath())); + assertThat(res).isNotNull(); + assertThat(res.getPath()).isNotNull(); + assertThat(Files.exists(res.getPath())).isTrue(); Node node = session.collectDependencies(session.createDependencyCoordinates(coords), PathScope.MAIN_RUNTIME); - assertNotNull(node); - assertEquals(6, node.getChildren().size()); + assertThat(node).isNotNull(); + assertThat(node.getChildren().size()).isEqualTo(6); } @Provides diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/util/PhasingExecutorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/util/PhasingExecutorTest.java index 8d234d28a087..581723ba24c6 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/util/PhasingExecutorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/util/PhasingExecutorTest.java @@ -26,7 +26,7 @@ class PhasingExecutorTest { @Test - void testPhaser() { + void phaser() { try (PhasingExecutor p = new PhasingExecutor(Executors.newFixedThreadPool(4))) { p.execute(() -> waitSomeTime(p, 2)); }