You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/09/19 22:25:00 UTC

(maven-resolver-ant-tasks) branch master updated: Drop Hamcrest from tests

This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver-ant-tasks.git


The following commit(s) were added to refs/heads/master by this push:
     new dd4b531  Drop Hamcrest from tests
dd4b531 is described below

commit dd4b531d3caec18e0f3bb99fa0b0c77c20b24388
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Sat Sep 19 23:56:23 2026 +0200

    Drop Hamcrest from tests
---
 pom.xml                                            |   2 +
 .../resolver/internal/ant/ActiveProfileTest.java   |   9 +-
 .../maven/resolver/internal/ant/DeployTest.java    |  20 ++--
 .../maven/resolver/internal/ant/InstallTest.java   |  13 +--
 .../internal/ant/ProjectWorkspaceReaderTest.java   |  11 ++-
 .../maven/resolver/internal/ant/ResolveTest.java   | 107 +++++++++------------
 .../maven/resolver/internal/ant/SettingsTest.java  |  37 +++----
 7 files changed, 90 insertions(+), 109 deletions(-)

diff --git a/pom.xml b/pom.xml
index cd927a5..f0a90cf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -212,6 +212,8 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <!-- JUnit 4's own internals (e.g. AssumptionViolatedException implements SelfDescribing) need an
+           org.hamcrest implementation at runtime; hamcrest-core is excluded above, so this supplies it. -->
       <groupId>org.hamcrest</groupId>
       <artifactId>hamcrest</artifactId>
       <version>${hamcrestVersion}</version>
diff --git a/src/test/java/org/apache/maven/resolver/internal/ant/ActiveProfileTest.java b/src/test/java/org/apache/maven/resolver/internal/ant/ActiveProfileTest.java
index 0c67f16..b6e31e2 100644
--- a/src/test/java/org/apache/maven/resolver/internal/ant/ActiveProfileTest.java
+++ b/src/test/java/org/apache/maven/resolver/internal/ant/ActiveProfileTest.java
@@ -21,8 +21,7 @@ package org.apache.maven.resolver.internal.ant;
 import junit.framework.JUnit4TestAdapter;
 import org.junit.Test;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertNotNull;
 
 public class ActiveProfileTest extends AntBuildsTest {
     public static junit.framework.Test suite() {
@@ -32,9 +31,7 @@ public class ActiveProfileTest extends AntBuildsTest {
     @Test
     public void testActiveProfileNotDefinedInSettingsIsIgnored() {
         executeTarget("testActiveProfileNotDefinedInSettingsIsIgnored");
-        assertThat(
-                "repository of defined profile not registered",
-                getProject().getReference("defined-repo"),
-                notNullValue());
+        assertNotNull(
+                "repository of defined profile not registered", getProject().getReference("defined-repo"));
     }
 }
diff --git a/src/test/java/org/apache/maven/resolver/internal/ant/DeployTest.java b/src/test/java/org/apache/maven/resolver/internal/ant/DeployTest.java
index 74b38ef..2e1fc10 100644
--- a/src/test/java/org/apache/maven/resolver/internal/ant/DeployTest.java
+++ b/src/test/java/org/apache/maven/resolver/internal/ant/DeployTest.java
@@ -25,12 +25,7 @@ import junit.framework.JUnit4TestAdapter;
 import org.apache.tools.ant.BuildException;
 import org.junit.Test;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.endsWith;
-import static org.hamcrest.Matchers.greaterThanOrEqualTo;
-import static org.hamcrest.Matchers.hasItemInArray;
-import static org.hamcrest.Matchers.lessThanOrEqualTo;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 /*
@@ -84,19 +79,18 @@ public class DeployTest extends AntBuildsTest {
 
         File dir = new File(distRepoDir, "test/dummy/0.1-SNAPSHOT/");
         String[] files = dir.list();
-        assertThat(
-                "attached artifact not found: " + Arrays.toString(files), files, hasItemInArray(endsWith("-ant.xml")));
+        assertTrue(
+                "attached artifact not found: " + Arrays.toString(files),
+                Arrays.stream(files).anyMatch(f -> f.endsWith("-ant.xml")));
     }
 
     private void assertUpdatedFile(long min, long max, File repoPath, String path) {
         File file = new File(repoPath, path);
         min = (min / 1000) * 1000;
         max = ((max + 999) / 1000) * 1000;
-        assertThat("File does not exist in default repo: " + file.getAbsolutePath(), file.exists());
-        assertThat(
-                "Files were not updated for 1s before/after timestamp",
-                file.lastModified(),
-                allOf(greaterThanOrEqualTo(min), lessThanOrEqualTo(max)));
+        assertTrue("File does not exist in default repo: " + file.getAbsolutePath(), file.exists());
+        long lastModified = file.lastModified();
+        assertTrue("Files were not updated for 1s before/after timestamp", lastModified >= min && lastModified <= max);
     }
 
     /**
diff --git a/src/test/java/org/apache/maven/resolver/internal/ant/InstallTest.java b/src/test/java/org/apache/maven/resolver/internal/ant/InstallTest.java
index 3fcbc5d..ec0bfb0 100644
--- a/src/test/java/org/apache/maven/resolver/internal/ant/InstallTest.java
+++ b/src/test/java/org/apache/maven/resolver/internal/ant/InstallTest.java
@@ -24,10 +24,7 @@ import java.io.IOException;
 import junit.framework.JUnit4TestAdapter;
 import org.junit.Test;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.greaterThanOrEqualTo;
-import static org.hamcrest.Matchers.lessThanOrEqualTo;
+import static org.junit.Assert.assertTrue;
 
 public class InstallTest extends AntBuildsTest {
     public static junit.framework.Test suite() {
@@ -92,10 +89,10 @@ public class InstallTest extends AntBuildsTest {
 
     private void assertUpdatedFile(long tstamp, File repoPath, String path) {
         File file = new File(repoPath, path);
-        assertThat("File does not exist in default repo: " + file.getAbsolutePath(), file.exists());
-        assertThat(
+        assertTrue("File does not exist in default repo: " + file.getAbsolutePath(), file.exists());
+        long lastModified = file.lastModified();
+        assertTrue(
                 "Files were not updated for 1s before/after timestamp",
-                file.lastModified(),
-                allOf(greaterThanOrEqualTo(((tstamp - 500) / 1000) * 1000), lessThanOrEqualTo(tstamp + 2000)));
+                lastModified >= ((tstamp - 500) / 1000) * 1000 && lastModified <= tstamp + 2000);
     }
 }
diff --git a/src/test/java/org/apache/maven/resolver/internal/ant/ProjectWorkspaceReaderTest.java b/src/test/java/org/apache/maven/resolver/internal/ant/ProjectWorkspaceReaderTest.java
index aa8e88c..0da1539 100644
--- a/src/test/java/org/apache/maven/resolver/internal/ant/ProjectWorkspaceReaderTest.java
+++ b/src/test/java/org/apache/maven/resolver/internal/ant/ProjectWorkspaceReaderTest.java
@@ -19,6 +19,10 @@
 package org.apache.maven.resolver.internal.ant;
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
 
 import junit.framework.JUnit4TestAdapter;
 import org.apache.maven.resolver.internal.ant.types.Pom;
@@ -28,8 +32,6 @@ import org.eclipse.aether.artifact.DefaultArtifact;
 import org.junit.Before;
 import org.junit.Test;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsInAnyOrder;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
@@ -127,7 +129,8 @@ public class ProjectWorkspaceReaderTest {
 
         reader.addArtifact(artifact2);
 
-        assertThat(
-                reader.findVersions(artifact("test:dummy:txt:[0,)")), containsInAnyOrder("1-SNAPSHOT", "2-SNAPSHOT"));
+        List<String> versions = new ArrayList<>(reader.findVersions(artifact("test:dummy:txt:[0,)")));
+        Collections.sort(versions);
+        assertEquals(Arrays.asList("1-SNAPSHOT", "2-SNAPSHOT"), versions);
     }
 }
diff --git a/src/test/java/org/apache/maven/resolver/internal/ant/ResolveTest.java b/src/test/java/org/apache/maven/resolver/internal/ant/ResolveTest.java
index 3bf9418..00c9ccf 100644
--- a/src/test/java/org/apache/maven/resolver/internal/ant/ResolveTest.java
+++ b/src/test/java/org/apache/maven/resolver/internal/ant/ResolveTest.java
@@ -30,16 +30,10 @@ import org.apache.tools.ant.types.ResourceCollection;
 import org.apache.tools.ant.types.resources.FileResource;
 import org.junit.Test;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.endsWith;
-import static org.hamcrest.Matchers.everyItem;
-import static org.hamcrest.Matchers.hasItemInArray;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 public class ResolveTest extends AntBuildsTest {
     public static junit.framework.Test suite() {
@@ -51,11 +45,10 @@ public class ResolveTest extends AntBuildsTest {
         executeTarget("testResolveGlobalPom");
 
         String prop = getProject().getProperty("test.resolve.path.org.eclipse.aether:aether-api:jar");
-        assertThat("aether-api was not resolved as a property", prop, notNullValue());
-        assertThat(
+        assertNotNull("aether-api was not resolved as a property", prop);
+        assertTrue(
                 "aether-api was not resolved to default local repository",
-                prop,
-                allOf(containsString("aether-api"), endsWith(".jar")));
+                prop.contains("aether-api") && prop.endsWith(".jar"));
     }
 
     @Test
@@ -63,11 +56,10 @@ public class ResolveTest extends AntBuildsTest {
         executeTarget("testResolveOverrideGlobalPom");
 
         String prop = getProject().getProperty("test.resolve.path.org.eclipse.aether:aether-api:jar");
-        assertThat("aether-api was not resolved as a property", prop, notNullValue());
-        assertThat(
+        assertNotNull("aether-api was not resolved as a property", prop);
+        assertTrue(
                 "aether-api was not resolved to default local repository",
-                prop,
-                allOf(containsString("aether-api"), endsWith(".jar")));
+                prop.contains("aether-api") && prop.endsWith(".jar"));
     }
 
     @Test
@@ -75,11 +67,11 @@ public class ResolveTest extends AntBuildsTest {
         executeTarget("testResolveGlobalPomIntoOtherLocalRepo");
 
         String prop = getProject().getProperty("test.resolve.path.org.eclipse.aether:aether-api:jar");
-        assertThat("aether-api was not resolved as a property", prop, notNullValue());
-        assertThat(
+        assertNotNull("aether-api was not resolved as a property", prop);
+        assertTrue(
                 "aether-api was not resolved to default local repository",
-                prop.replace('\\', '/'),
-                endsWith("local-repo-custom/org/eclipse/aether/aether-api/0.9.0.M3/aether-api-0.9.0.M3.jar"));
+                prop.replace('\\', '/')
+                        .endsWith("local-repo-custom/org/eclipse/aether/aether-api/0.9.0.M3/aether-api-0.9.0.M3.jar"));
     }
 
     @Test
@@ -87,7 +79,7 @@ public class ResolveTest extends AntBuildsTest {
         File dir = new File(BUILD_DIR, "resolve-custom-layout");
         executeTarget("testResolveCustomFileLayout");
 
-        assertThat(
+        assertTrue(
                 "aether-api was not saved with custom file layout",
                 new File(dir, "org.eclipse.aether/aether-api/org/eclipse/aether/jar").exists());
     }
@@ -99,17 +91,18 @@ public class ResolveTest extends AntBuildsTest {
 
         File jdocDir = new File(dir, "javadoc");
 
-        assertThat(
+        assertTrue(
                 "aether-api-javadoc was not saved with custom file layout",
                 new File(jdocDir, "org.eclipse.aether-aether-api-javadoc.jar").exists());
 
-        assertThat("found non-javadoc files", Arrays.asList(jdocDir.list()), everyItem(endsWith("javadoc.jar")));
+        assertTrue("found non-javadoc files", Arrays.stream(jdocDir.list()).allMatch(f -> f.endsWith("javadoc.jar")));
 
         File sourcesDir = new File(dir, "sources");
-        assertThat(
+        assertTrue(
                 "aether-api-sources was not saved with custom file layout",
                 new File(sourcesDir, "org.eclipse.aether-aether-api-sources.jar").exists());
-        assertThat("found non-sources files", Arrays.asList(sourcesDir.list()), everyItem(endsWith("sources.jar")));
+        assertTrue(
+                "found non-sources files", Arrays.stream(sourcesDir.list()).allMatch(f -> f.endsWith("sources.jar")));
     }
 
     @Test
@@ -117,13 +110,12 @@ public class ResolveTest extends AntBuildsTest {
         executeTarget("testResolvePath");
         Map<?, ?> refs = getProject().getReferences();
         Object obj = refs.get("out");
-        assertThat("ref 'out' is no path", obj, instanceOf(Path.class));
+        assertTrue("ref 'out' is no path", obj instanceof Path);
         Path path = (Path) obj;
         String[] elements = path.list();
-        assertThat(
+        assertTrue(
                 "no aether-api on classpath",
-                elements,
-                hasItemInArray(allOf(containsString("aether-api"), endsWith(".jar"))));
+                Arrays.stream(elements).anyMatch(e -> e.contains("aether-api") && e.endsWith(".jar")));
     }
 
     @Test
@@ -131,13 +123,12 @@ public class ResolveTest extends AntBuildsTest {
         executeTarget("testResolveDepsFromFile");
 
         String prop = getProject().getProperty("test.resolve.path.org.eclipse.aether:aether-spi:jar");
-        assertThat("aether-spi was not resolved as a property", prop, notNullValue());
-        assertThat(
+        assertNotNull("aether-spi was not resolved as a property", prop);
+        assertTrue(
                 "aether-spi was not resolved to default local repository",
-                prop,
-                allOf(containsString("aether-spi"), endsWith(".jar")));
+                prop.contains("aether-spi") && prop.endsWith(".jar"));
         prop = getProject().getProperty("test.resolve.path.org.eclipse.aether:aether-api:jar");
-        assertThat("aether-api was resolved as a property", prop, nullValue());
+        assertNull("aether-api was resolved as a property", prop);
     }
 
     @Test
@@ -145,11 +136,11 @@ public class ResolveTest extends AntBuildsTest {
         executeTarget("testResolveNestedDependencyCollections");
 
         String prop = getProject().getProperty("test.resolve.path.org.eclipse.aether:aether-spi:jar");
-        assertThat("aether-spi was not resolved as a property", prop, notNullValue());
+        assertNotNull("aether-spi was not resolved as a property", prop);
         prop = getProject().getProperty("test.resolve.path.org.eclipse.aether:aether-util:jar");
-        assertThat("aether-util was not resolved as a property", prop, notNullValue());
+        assertNotNull("aether-util was not resolved as a property", prop);
         prop = getProject().getProperty("test.resolve.path.org.eclipse.aether:aether-api:jar");
-        assertThat("aether-api was resolved as a property", prop, nullValue());
+        assertNull("aether-api was resolved as a property", prop);
     }
 
     @Test
@@ -157,14 +148,14 @@ public class ResolveTest extends AntBuildsTest {
         executeTarget("testResolveResourceCollectionOnly");
 
         ResourceCollection resources = (ResourceCollection) getProject().getReference("files");
-        assertThat(resources, is(notNullValue()));
-        assertThat(resources.size(), is(2));
-        assertThat(resources.isFilesystemOnly(), is(true));
+        assertNotNull(resources);
+        assertEquals(2, resources.size());
+        assertTrue(resources.isFilesystemOnly());
         Iterator<?> it = resources.iterator();
         FileResource file = (FileResource) it.next();
-        assertThat(file.getFile().getName(), is("aether-spi-0.9.0.v20140226.jar"));
+        assertEquals("aether-spi-0.9.0.v20140226.jar", file.getFile().getName());
         file = (FileResource) it.next();
-        assertThat(file.getFile().getName(), is("aether-api-0.9.0.v20140226.jar"));
+        assertEquals("aether-api-0.9.0.v20140226.jar", file.getFile().getName());
     }
 
     @Test
@@ -172,18 +163,16 @@ public class ResolveTest extends AntBuildsTest {
         executeTarget("testResolveTransitiveDependencyManagement");
 
         String prop = getProject().getProperty("test.resolve.path.org.slf4j:slf4j-api:jar");
-        assertThat("slf4j-api was not resolved as a property", prop, notNullValue());
-        assertThat(
+        assertNotNull("slf4j-api was not resolved as a property", prop);
+        assertTrue(
                 "slf4j-api was not resolved to default local repository",
-                prop,
-                allOf(containsString("slf4j-api"), endsWith("slf4j-api-2.0.6.jar")));
+                prop.contains("slf4j-api") && prop.endsWith("slf4j-api-2.0.6.jar"));
 
         prop = getProject().getProperty("test.resolve.path.org.apiguardian:apiguardian-api:jar");
-        assertThat("apiguardian-api was not resolved as a property", prop, notNullValue());
-        assertThat(
+        assertNotNull("apiguardian-api was not resolved as a property", prop);
+        assertTrue(
                 "apiguardian-api was not resolved to default local repository",
-                prop,
-                allOf(containsString("apiguardian-api"), endsWith("apiguardian-api-1.1.1.jar")));
+                prop.contains("apiguardian-api") && prop.endsWith("apiguardian-api-1.1.1.jar"));
     }
 
     @Test
@@ -191,17 +180,15 @@ public class ResolveTest extends AntBuildsTest {
         executeTarget("testResolveTransitiveDependencyManagementTestScope");
 
         String prop = getProject().getProperty("test.compile.resolve.path.org.slf4j:slf4j-api:jar");
-        assertThat("slf4j-api was not resolved as a property", prop, notNullValue());
-        assertThat(
+        assertNotNull("slf4j-api was not resolved as a property", prop);
+        assertTrue(
                 "slf4j-api was not resolved to default local repository",
-                prop,
-                allOf(containsString("slf4j-api"), endsWith("slf4j-api-2.0.6.jar")));
+                prop.contains("slf4j-api") && prop.endsWith("slf4j-api-2.0.6.jar"));
 
         prop = getProject().getProperty("test.resolve.path.org.apiguardian:apiguardian-api:jar");
-        assertThat("apiguardian-api was not resolved as a property", prop, notNullValue());
-        assertThat(
+        assertNotNull("apiguardian-api was not resolved as a property", prop);
+        assertTrue(
                 "apiguardian-api was not resolved to default local repository",
-                prop,
-                allOf(containsString("apiguardian-api"), endsWith("apiguardian-api-1.1.1.jar")));
+                prop.contains("apiguardian-api") && prop.endsWith("apiguardian-api-1.1.1.jar"));
     }
 }
diff --git a/src/test/java/org/apache/maven/resolver/internal/ant/SettingsTest.java b/src/test/java/org/apache/maven/resolver/internal/ant/SettingsTest.java
index 597e3ef..4687f3b 100644
--- a/src/test/java/org/apache/maven/resolver/internal/ant/SettingsTest.java
+++ b/src/test/java/org/apache/maven/resolver/internal/ant/SettingsTest.java
@@ -24,9 +24,8 @@ import java.io.IOException;
 import junit.framework.JUnit4TestAdapter;
 import org.junit.Test;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.endsWith;
-import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 public class SettingsTest extends AntBuildsTest {
     public static junit.framework.Test suite() {
@@ -36,40 +35,42 @@ public class SettingsTest extends AntBuildsTest {
     @Test
     public void testUserSettings() {
         executeTarget("testUserSettings");
-        assertThat(
+        assertEquals(
                 "user settings not set",
-                AntRepoSys.getInstance(getProject()).getUserSettings().getName(),
-                equalTo("userSettings.xml"));
+                "userSettings.xml",
+                AntRepoSys.getInstance(getProject()).getUserSettings().getName());
     }
 
     @Test
     public void testGlobalSettings() {
         executeTarget("testGlobalSettings");
-        assertThat(
+        assertEquals(
                 "global settings not set",
-                AntRepoSys.getInstance(getProject()).getGlobalSettings().getName(),
-                equalTo("globalSettings.xml"));
+                "globalSettings.xml",
+                AntRepoSys.getInstance(getProject()).getGlobalSettings().getName());
     }
 
     @Test
     public void testBothSettings() {
         executeTarget("testBothSettings");
-        assertThat(
+        assertEquals(
                 "global settings not set",
-                AntRepoSys.getInstance(getProject()).getGlobalSettings().getName(),
-                equalTo("globalSettings.xml"));
-        assertThat(
+                "globalSettings.xml",
+                AntRepoSys.getInstance(getProject()).getGlobalSettings().getName());
+        assertEquals(
                 "user settings not set",
-                AntRepoSys.getInstance(getProject()).getUserSettings().getName(),
-                equalTo("userSettings.xml"));
+                "userSettings.xml",
+                AntRepoSys.getInstance(getProject()).getUserSettings().getName());
     }
 
     @Test
     public void testFallback() throws IOException {
         executeTarget("setUp");
-        assertThat(
+        assertTrue(
                 "no fallback to local settings",
-                AntRepoSys.getInstance(getProject()).getUserSettings().getAbsolutePath(),
-                endsWith(".m2" + File.separator + "settings.xml"));
+                AntRepoSys.getInstance(getProject())
+                        .getUserSettings()
+                        .getAbsolutePath()
+                        .endsWith(".m2" + File.separator + "settings.xml"));
     }
 }