This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new 99b98d945a Add tests for resume selector (#13804)
99b98d945a is described below
commit 99b98d945a2bd91e09c03cfff9d92122d5c7c6a6
Author: codewithsinchana <[email protected]>
AuthorDate: Tue Nov 10 19:04:04 2026 +0530
Add tests for resume selector (#13804)
* Add tests for resume selector
* test: add single-project test case for resume selector
---------
Co-authored-by: codewithsinchana <[email protected]>
---
.../maven/cling/invoker/mvn/MavenInvokerTest.java | 141 +++++++++++++++------
1 file changed, 100 insertions(+), 41 deletions(-)
diff --git
a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerTest.java
b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerTest.java
index 18c6f82850..7db6a2770a 100644
---
a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerTest.java
+++
b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerTest.java
@@ -32,6 +32,7 @@
import org.apache.maven.api.cli.InvokerException;
import org.apache.maven.api.cli.Parser;
import org.apache.maven.cling.invoker.ProtoLookup;
+import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Order;
@@ -41,6 +42,7 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
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;
@@ -50,6 +52,21 @@
*/
@Order(200)
public class MavenInvokerTest extends MavenInvokerTestSupport {
+
+ /**
+ * Test invoker exposing the resume selector for unit testing.
+ */
+ private static class TestMavenInvoker extends MavenInvoker {
+
+ TestMavenInvoker() {
+ super(ProtoLookup.builder().build(), null);
+ }
+
+ String resumeSelector(List<MavenProject> projects, MavenProject
failedProject) {
+ return getResumeFromSelector(projects, failedProject);
+ }
+ }
+
@Override
protected Invoker createInvoker(ClassWorld classWorld) {
return new MavenInvoker(
@@ -70,8 +87,9 @@ void defaultFs(
}
/**
- * The invocation replaces the handlers of the {@code java.util.logging}
root logger with {@code SLF4JBridgeHandler};
- * they must be back afterwards, as the root logger belongs to the JVM
Maven runs in (GH-13362).
+ * The invocation replaces the handlers of the {@code java.util.logging}
root logger with
+ * {@code SLF4JBridgeHandler}; they must be back afterwards, as the root
logger belongs to
+ * the JVM Maven runs in (GH-13362).
*/
@Test
void restoresJavaUtilLoggingRootHandlers(
@@ -203,45 +221,45 @@ void conflictingSettings(
@TempDir(cleanup = CleanupMode.ON_SUCCESS) Path userHome)
throws Exception {
String settingsXml = """
-<?xml version="1.0"?>
-<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
- <interactiveMode>false</interactiveMode>
- <profiles>
- <profile>
- <id>oss-development</id>
- <repositories>
- <repository>
- <id>central</id>
- <url>https://repo1.maven.org/maven2/</url>
- <releases>
- <enabled>true</enabled>
- <updatePolicy>never</updatePolicy>
- </releases>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>central</id>
- <url>https://repo1.maven.org/maven2/</url>
- <releases>
- <enabled>true</enabled>
- <updatePolicy>never</updatePolicy>
- </releases>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </pluginRepository>
- </pluginRepositories>
- </profile>
- </profiles>
- <activeProfiles>
- <activeProfile>oss-development</activeProfile>
- </activeProfiles>
-</settings>""";
+ <?xml version="1.0"?>
+ <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
+ <interactiveMode>false</interactiveMode>
+ <profiles>
+ <profile>
+ <id>oss-development</id>
+ <repositories>
+ <repository>
+ <id>central</id>
+ <url>https://repo1.maven.org/maven2/</url>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>central</id>
+ <url>https://repo1.maven.org/maven2/</url>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+ <activeProfiles>
+ <activeProfile>oss-development</activeProfile>
+ </activeProfiles>
+ </settings>""";
Path dotMvn = cwd.resolve(".mvn");
Files.createDirectories(dotMvn);
Path projectExtensions = dotMvn.resolve("settings.xml");
@@ -263,4 +281,45 @@ void conflictingSettings(
assertTrue(log.contains("https://repo1.maven.org/maven2"), log);
assertFalse(log.contains("https://repo.maven.apache.org/maven2"), log);
}
+
+ @Test
+ void getResumeFromSelectorWithUniqueArtifactId() {
+ TestMavenInvoker invoker = new TestMavenInvoker();
+
+ MavenProject first = new MavenProject();
+ first.setGroupId("org.apache.maven");
+ first.setArtifactId("maven-core");
+
+ MavenProject failed = new MavenProject();
+ failed.setGroupId("org.apache.maven");
+ failed.setArtifactId("maven-cli");
+
+ assertEquals(":maven-cli", invoker.resumeSelector(List.of(first,
failed), failed));
+ }
+
+ @Test
+ void getResumeFromSelectorWithDuplicateArtifactId() {
+ TestMavenInvoker invoker = new TestMavenInvoker();
+
+ MavenProject first = new MavenProject();
+ first.setGroupId("org.apache.maven");
+ first.setArtifactId("maven-core");
+
+ MavenProject failed = new MavenProject();
+ failed.setGroupId("org.example");
+ failed.setArtifactId("maven-core");
+
+ assertEquals("org.example:maven-core",
invoker.resumeSelector(List.of(first, failed), failed));
+ }
+
+ @Test
+ void getResumeFromSelectorWithSingleProject() {
+ TestMavenInvoker invoker = new TestMavenInvoker();
+
+ MavenProject failed = new MavenProject();
+ failed.setGroupId("org.apache.maven");
+ failed.setArtifactId("maven-cli");
+
+ assertEquals(":maven-cli", invoker.resumeSelector(List.of(failed),
failed));
+ }
}