gnodet-bot commented on code in PR #499:
URL: 
https://github.com/apache/maven-install-plugin/pull/499#discussion_r4652731336


##########
src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java:
##########
@@ -619,6 +623,220 @@ void dotDotVersionRejected(InstallFileMojo mojo) {
         assertTrue(e.getMessage().contains("not valid"), e.getMessage());
     }
 
+    // 
-------------------------------------------------------------------------------------------------------
+    // Conversions of the src/it integration tests that only exercised 
install:install-file mojo behaviour.
+    // The real ArtifactInstaller is mocked by the harness, so "installed" is 
asserted as the set of
+    // artifacts handed to it (plus the generated POM model captured while the 
install call is in flight).
+    // Checksum files are produced by Maven's ArtifactInstaller, never by this 
mojo; at this level we
+    // assert that no checksum artifact is handed to the installer and that 
none is left in the repo.
+    // 
-------------------------------------------------------------------------------------------------------
+
+    /** Converted from {@code src/it/gav-validation} (invalid coordinates, 
test-invalid.properties). */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "invalid~group")
+    @MojoParameter(name = "artifactId", value = "invalid/artifactId")
+    @MojoParameter(name = "version", value = "1+")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void invalidGavRejectedAndNothingInstalled(InstallFileMojo mojo) {
+        assertNotNull(mojo);
+
+        MojoException e = executeExpectingFailure(mojo);
+
+        assertTrue(e.getMessage().contains("The artifact information is not 
valid"), e.getMessage());
+    }
+
+    /** Converted from {@code src/it/gav-validation} (missing coordinates, 
test-missing.properties). */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "groupId")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void missingCoordinatesRejectedAndNothingInstalled(InstallFileMojo mojo) 
throws Exception {
+        assertNotNull(mojo);
+        // A jar with no embedded POM keeps the coordinates genuinely 
incomplete.
+        Path plainJar = createJarWithEntryBytes(
+                "Manifest-Version: 1.0\n".getBytes(StandardCharsets.UTF_8), 
"META-INF/MANIFEST.MF");
+        setVariableValueToObject(mojo, "file", plainJar);
+
+        MojoException e = executeExpectingFailure(mojo);
+
+        assertTrue(e.getMessage().contains("The artifact information is 
incomplete"), e.getMessage());
+    }
+
+    /** Converted from {@code src/it/generate-pom-auto-1}: with the default 
generatePom, a jar and a POM are installed. */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = 
"org.apache.maven.its.install.gpa1")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void generatePomAutoInstallsJarAndPom(InstallFileMojo mojo) throws 
Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        AtomicReference<Model> model = new AtomicReference<>();
+        ArtifactInstallerRequest request =
+                execute(mojo, air -> model.set(readModelFrom(air, 
getArtifact(null, "pom"))));
+
+        assertNotNull(request);
+        Artifact pom = getArtifact(null, "pom");
+        Artifact jar = getArtifact(null, "jar");
+        assertEquals(new HashSet<>(Arrays.asList(pom, jar)), new 
HashSet<>(request.getArtifacts()));
+        assertFileExists(artifactManager.getPath(jar).orElse(null));
+        assertEquals("4.0.0", model.get().getModelVersion());
+        assertEquals(groupId, model.get().getGroupId());
+        assertEquals(artifactId, model.get().getArtifactId());
+        assertEquals(version, model.get().getVersion());
+        assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO));
+    }
+
+    /** Converted from {@code src/it/generate-pom-auto-2}: a POM already in 
the repo is never overwritten. */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = 
"org.apache.maven.its.install.gpa2")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void existingPomNotOverwrittenWhenGeneratePomAuto(InstallFileMojo mojo) 
throws Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        Path existingPom =
+                Paths.get(getBasedir(), LOCAL_REPO, 
"org/apache/maven/its/install/gpa2/test/0.1/test-0.1.pom");
+        Files.createDirectories(existingPom.getParent());
+        Files.writeString(existingPom, "test");
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        Artifact jar = getArtifact(null, "jar");
+        assertEquals(Collections.singleton(jar), new 
HashSet<>(request.getArtifacts()));
+        assertFileExists(artifactManager.getPath(jar).orElse(null));
+        assertEquals("test", Files.readString(existingPom), "existing POM must 
keep its original 4-byte content");
+        assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO));
+    }
+
+    /** Converted from {@code src/it/local-repo-override-with-checksum}: 
install into a custom local repository. */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "gid")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    @MojoParameter(name = "localRepositoryPath", value = 
"target/local-repo-override")
+    void installFileIntoOverriddenLocalRepositoryNoChecksums(InstallFileMojo 
mojo) throws Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        Artifact jar = getArtifact(null, "jar");
+        assertTrue(request.getArtifacts().contains(jar), "the jar must be 
installed into the overridden repository");
+        assertTrue(request.getArtifacts().stream()
+                .noneMatch(a -> "md5".equals(a.getExtension()) || 
"sha1".equals(a.getExtension())));
+        assertFileExistsInRequest(request, jar);
+        assertEquals(
+                Paths.get(getBasedir(), 
OVERRIDE_REPO).toString().replace(File.separator, "/"),
+                
request.getSession().getLocalRepository().getPath().toString().replace(File.separator,
 "/"));
+        assertNoChecksumFiles(Paths.get(getBasedir(), OVERRIDE_REPO));
+    }
+
+    /**
+     * Converted from {@code 
src/it/local-repo-override-with-checksum-generatePom}: the generated POM is 
installed
+     * into the custom local repository too, and neither jar nor POM gets a 
checksum file.
+     */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "gid")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    @MojoParameter(name = "generatePom", value = "true")
+    @MojoParameter(name = "localRepositoryPath", value = 
"target/local-repo-override")
+    void 
installFileIntoOverriddenLocalRepositoryWithGeneratedPomNoChecksums(InstallFileMojo
 mojo) throws Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        AtomicReference<Model> model = new AtomicReference<>();
+        ArtifactInstallerRequest request =
+                execute(mojo, air -> model.set(readModelFrom(air, 
getArtifact(null, "pom"))));
+
+        assertNotNull(request);
+        Artifact pom = getArtifact(null, "pom");
+        Artifact jar = getArtifact(null, "jar");
+        assertEquals(new HashSet<>(Arrays.asList(pom, jar)), new 
HashSet<>(request.getArtifacts()));
+        assertFileExistsInRequest(request, jar);
+        assertEquals(
+                Paths.get(getBasedir(), 
OVERRIDE_REPO).toString().replace(File.separator, "/"),
+                
request.getSession().getLocalRepository().getPath().toString().replace(File.separator,
 "/"));
+        assertEquals(groupId, model.get().getGroupId());
+        assertEquals(artifactId, model.get().getArtifactId());
+        assertEquals(version, model.get().getVersion());
+        assertNoChecksumFiles(Paths.get(getBasedir(), OVERRIDE_REPO));
+    }
+
+    private void assertFileExistsInRequest(ArtifactInstallerRequest request, 
Artifact artifact) {
+        ArtifactManager requestArtifactManager = 
request.getSession().getService(ArtifactManager.class);
+        
assertFileExists(requestArtifactManager.getPath(artifact).orElse(null));
+    }
+
+    private Model readModelFrom(ArtifactInstallerRequest request, Artifact 
pom) {
+        try {
+            ArtifactManager requestArtifactManager = 
request.getSession().getService(ArtifactManager.class);
+            Path pomPath = requestArtifactManager.getPath(pom).orElse(null);
+            assertNotNull(pomPath);
+            return session.getService(ModelXmlFactory.class).read(pomPath);
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private MojoException executeExpectingFailure(InstallFileMojo mojo) {
+        AtomicReference<ArtifactInstallerRequest> request = new 
AtomicReference<>();
+        doAnswer(iom -> {
+                    request.set(iom.getArgument(0, 
ArtifactInstallerRequest.class));
+                    return null;
+                })
+                .when(artifactInstaller)
+                .install(any(ArtifactInstallerRequest.class));
+        MojoException e = assertThrows(MojoException.class, mojo::execute);
+        assertNull(request.get(), "nothing should be installed on validation 
failure");
+        return e;
+    }
+
+    private static void assertNoChecksumFiles(Path repositoryRoot) throws 
Exception {

Review Comment:
   💬 **Duplication:** Same `assertNoChecksumFiles` helper as in 
`InstallMojoPomPackagingTest` and `InstallMojoTest`. See first occurrence for 
extraction suggestion.



##########
src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java:
##########
@@ -269,6 +272,103 @@ void deferredInstallRunsExactlyOncePerProject(InstallMojo 
mojo) throws Exception
         verify(artifactInstaller, 
times(2)).install(any(ArtifactInstallerRequest.class));
     }
 
+    // 
-------------------------------------------------------------------------------------------------------
+    // Conversions of the src/it integration tests that exercised the install 
mojo's project processing.
+    // 
-------------------------------------------------------------------------------------------------------
+
+    private static final String MAIN_ARTIFACT_WITHOUT_ATTACHMENTS_MESSAGE =
+            "The packaging plugin for this project did not assign a main file 
to the project but it has attachments."
+                    + " Change packaging to 'pom'.";
+
+    private static final Path ATTACHED_ARTIFACT_JAR =
+            
Paths.get("target/test-classes/unit/attached-artifact-test-1.0-SNAPSHOT.jar");
+
+    /** Converted from {@code src/it/no-main-artifact-1}: target/classes is 
absent. */
+    @Test
+    @InjectMojo(goal = "install")
+    @MojoParameter(name = "installAtEnd", value = "false")
+    void noMainArtifactWithAttachmentsFailsWhenOutputDirMissing(InstallMojo 
mojo) throws Exception {
+        assertNotNull(mojo);
+        Project project = (Project) getVariableValueFromObject(mojo, 
"project");
+        
assertFalse(artifactManager.getPath(project.getMainArtifact().get()).isPresent());
+        attachClassifiedJar(project, "it");
+
+        MojoException e = assertThrows(MojoException.class, mojo::execute);
+
+        
assertTrue(e.getMessage().contains(MAIN_ARTIFACT_WITHOUT_ATTACHMENTS_MESSAGE), 
e.getMessage());
+    }
+
+    /** Converted from {@code src/it/no-main-artifact-2}: target/classes 
exists (as a directory, not a file). */
+    @Test
+    @InjectMojo(goal = "install")
+    @MojoParameter(name = "installAtEnd", value = "false")
+    void noMainArtifactWithAttachmentsFailsWhenOutputDirPresent(InstallMojo 
mojo) throws Exception {
+        assertNotNull(mojo);
+        Project project = (Project) getVariableValueFromObject(mojo, 
"project");
+        Path outputDir = Paths.get(getBasedir(), 
"target/no-main-artifact-output-dir");
+        Files.createDirectories(outputDir);
+        artifactManager.setPath(project.getMainArtifact().get(), outputDir);
+        assertFalse(Files.isRegularFile(
+                
artifactManager.getPath(project.getMainArtifact().get()).get()));
+        attachClassifiedJar(project, "it");
+
+        MojoException e = assertThrows(MojoException.class, mojo::execute);
+
+        
assertTrue(e.getMessage().contains(MAIN_ARTIFACT_WITHOUT_ATTACHMENTS_MESSAGE), 
e.getMessage());
+    }
+
+    /** Converted from {@code src/it/attach-jar-checksum}: pom, jar and 
attached sources are installed, no checksums. */
+    @Test
+    @InjectMojo(goal = "install")
+    @MojoParameter(name = "installAtEnd", value = "false")
+    void attachedJarInstalledWithoutChecksums(InstallMojo mojo) throws 
Exception {
+        assertNotNull(mojo);
+        Project project = (Project) getVariableValueFromObject(mojo, 
"project");
+        artifactManager.setPath(
+                project.getMainArtifact().get(),
+                Paths.get(getBasedir(), 
"target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar"));
+        projectManager.attachArtifact(
+                project,
+                new ProducedArtifactStub(
+                        "org.apache.maven.test", "maven-install-test", 
"sources", "1.0-SNAPSHOT", "jar"),
+                Paths.get(getBasedir()).resolve(ATTACHED_ARTIFACT_JAR));
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        assertEquals(
+                Arrays.asList(
+                        
"org.apache.maven.test:maven-install-test:pom:1.0-SNAPSHOT",
+                        
"org.apache.maven.test:maven-install-test:jar:1.0-SNAPSHOT",
+                        
"org.apache.maven.test:maven-install-test:jar:sources:1.0-SNAPSHOT"),
+                request.getArtifacts().stream().map(Artifact::key).toList());
+        assertTrue(request.getArtifacts().stream()
+                .noneMatch(a -> "md5".equals(a.getExtension()) || 
"sha1".equals(a.getExtension())));
+        assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO));
+    }
+
+    private void attachClassifiedJar(Project project, String classifier) {
+        projectManager.attachArtifact(
+                project,
+                new ProducedArtifactStub(
+                        "org.apache.maven.test", "attached-artifact-test", 
classifier, "1.0-SNAPSHOT", "jar"),
+                Paths.get(getBasedir()).resolve(ATTACHED_ARTIFACT_JAR));
+    }
+
+    private static void assertNoChecksumFiles(Path repositoryRoot) throws 
Exception {

Review Comment:
   💬 **Duplication:** Same `assertNoChecksumFiles` helper as in 
`InstallMojoPomPackagingTest` and `InstallFileMojoTest`. See first occurrence 
for extraction suggestion.



##########
src/test/java/org/apache/maven/plugins/install/InstallMojoPomPackagingTest.java:
##########
@@ -103,6 +107,40 @@ void installIfPackagingIsPom(InstallMojo mojo) throws 
Exception {
                 artifacts.stream().map(Artifact::key).toList());
     }
 
+    /** Converted from {@code src/it/pom-checksum}: the POM is installed and 
no checksum files are created. */
+    @Test
+    @InjectMojo(goal = "install")
+    @MojoParameter(name = "installAtEnd", value = "false")
+    void pomPackagingInstalledWithoutChecksums(InstallMojo mojo) throws 
Exception {
+        assertNotNull(mojo);
+        Project project = (Project) getVariableValueFromObject(mojo, 
"project");
+        artifactManager.setPath(project.getPomArtifact(), 
project.getPomPath());
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        assertEquals(
+                
List.of("org.apache.maven.test:maven-install-test:pom:1.0-SNAPSHOT"),
+                request.getArtifacts().stream().map(Artifact::key).toList());
+        assertTrue(request.getArtifacts().stream()
+                .noneMatch(a -> "md5".equals(a.getExtension()) || 
"sha1".equals(a.getExtension())));
+        assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO));
+    }
+
+    private static void assertNoChecksumFiles(Path repositoryRoot) throws 
Exception {

Review Comment:
   💬 **Duplication:** `assertNoChecksumFiles` is defined with identical 
implementation in all three test classes (`InstallFileMojoTest`, 
`InstallMojoPomPackagingTest`, `InstallMojoTest`). Consider extracting it to a 
package-private static utility class (e.g. `InstallTestUtils` or 
`InstallTestHelper`) shared across the three:
   
   ```java
   // InstallTestUtils.java (new package-private utility)
   static void assertNoChecksumFiles(Path repositoryRoot) throws Exception {
       try (Stream<Path> stream = Files.walk(repositoryRoot)) {
           List<Path> checksumFiles = stream
                   .filter(p -> {
                       String name = p.getFileName().toString();
                       return name.endsWith(".md5") || name.endsWith(".sha1");
                   })
                   .collect(Collectors.toList());
           assertTrue(checksumFiles.isEmpty(), "Expected no checksum files but 
found: " + checksumFiles);
       }
   }
   ```
   
   The `@MojoTest` harness doesn't require a base class — a utility class with 
static methods is the right place for shared test helpers. Not a blocker.



##########
src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java:
##########
@@ -619,6 +623,220 @@ void dotDotVersionRejected(InstallFileMojo mojo) {
         assertTrue(e.getMessage().contains("not valid"), e.getMessage());
     }
 
+    // 
-------------------------------------------------------------------------------------------------------
+    // Conversions of the src/it integration tests that only exercised 
install:install-file mojo behaviour.
+    // The real ArtifactInstaller is mocked by the harness, so "installed" is 
asserted as the set of
+    // artifacts handed to it (plus the generated POM model captured while the 
install call is in flight).
+    // Checksum files are produced by Maven's ArtifactInstaller, never by this 
mojo; at this level we
+    // assert that no checksum artifact is handed to the installer and that 
none is left in the repo.
+    // 
-------------------------------------------------------------------------------------------------------
+
+    /** Converted from {@code src/it/gav-validation} (invalid coordinates, 
test-invalid.properties). */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "invalid~group")
+    @MojoParameter(name = "artifactId", value = "invalid/artifactId")
+    @MojoParameter(name = "version", value = "1+")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void invalidGavRejectedAndNothingInstalled(InstallFileMojo mojo) {
+        assertNotNull(mojo);
+
+        MojoException e = executeExpectingFailure(mojo);
+
+        assertTrue(e.getMessage().contains("The artifact information is not 
valid"), e.getMessage());
+    }
+
+    /** Converted from {@code src/it/gav-validation} (missing coordinates, 
test-missing.properties). */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "groupId")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void missingCoordinatesRejectedAndNothingInstalled(InstallFileMojo mojo) 
throws Exception {
+        assertNotNull(mojo);
+        // A jar with no embedded POM keeps the coordinates genuinely 
incomplete.
+        Path plainJar = createJarWithEntryBytes(
+                "Manifest-Version: 1.0\n".getBytes(StandardCharsets.UTF_8), 
"META-INF/MANIFEST.MF");
+        setVariableValueToObject(mojo, "file", plainJar);
+
+        MojoException e = executeExpectingFailure(mojo);
+
+        assertTrue(e.getMessage().contains("The artifact information is 
incomplete"), e.getMessage());
+    }
+
+    /** Converted from {@code src/it/generate-pom-auto-1}: with the default 
generatePom, a jar and a POM are installed. */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = 
"org.apache.maven.its.install.gpa1")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void generatePomAutoInstallsJarAndPom(InstallFileMojo mojo) throws 
Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        AtomicReference<Model> model = new AtomicReference<>();
+        ArtifactInstallerRequest request =
+                execute(mojo, air -> model.set(readModelFrom(air, 
getArtifact(null, "pom"))));
+
+        assertNotNull(request);
+        Artifact pom = getArtifact(null, "pom");
+        Artifact jar = getArtifact(null, "jar");
+        assertEquals(new HashSet<>(Arrays.asList(pom, jar)), new 
HashSet<>(request.getArtifacts()));
+        assertFileExists(artifactManager.getPath(jar).orElse(null));
+        assertEquals("4.0.0", model.get().getModelVersion());
+        assertEquals(groupId, model.get().getGroupId());
+        assertEquals(artifactId, model.get().getArtifactId());
+        assertEquals(version, model.get().getVersion());
+        assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO));
+    }
+
+    /** Converted from {@code src/it/generate-pom-auto-2}: a POM already in 
the repo is never overwritten. */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = 
"org.apache.maven.its.install.gpa2")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void existingPomNotOverwrittenWhenGeneratePomAuto(InstallFileMojo mojo) 
throws Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        Path existingPom =
+                Paths.get(getBasedir(), LOCAL_REPO, 
"org/apache/maven/its/install/gpa2/test/0.1/test-0.1.pom");
+        Files.createDirectories(existingPom.getParent());
+        Files.writeString(existingPom, "test");
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        Artifact jar = getArtifact(null, "jar");
+        assertEquals(Collections.singleton(jar), new 
HashSet<>(request.getArtifacts()));
+        assertFileExists(artifactManager.getPath(jar).orElse(null));
+        assertEquals("test", Files.readString(existingPom), "existing POM must 
keep its original 4-byte content");
+        assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO));
+    }
+
+    /** Converted from {@code src/it/local-repo-override-with-checksum}: 
install into a custom local repository. */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "gid")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    @MojoParameter(name = "localRepositoryPath", value = 
"target/local-repo-override")
+    void installFileIntoOverriddenLocalRepositoryNoChecksums(InstallFileMojo 
mojo) throws Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        Artifact jar = getArtifact(null, "jar");
+        assertTrue(request.getArtifacts().contains(jar), "the jar must be 
installed into the overridden repository");
+        assertTrue(request.getArtifacts().stream()
+                .noneMatch(a -> "md5".equals(a.getExtension()) || 
"sha1".equals(a.getExtension())));
+        assertFileExistsInRequest(request, jar);
+        assertEquals(
+                Paths.get(getBasedir(), 
OVERRIDE_REPO).toString().replace(File.separator, "/"),
+                
request.getSession().getLocalRepository().getPath().toString().replace(File.separator,
 "/"));
+        assertNoChecksumFiles(Paths.get(getBasedir(), OVERRIDE_REPO));
+    }
+
+    /**
+     * Converted from {@code 
src/it/local-repo-override-with-checksum-generatePom}: the generated POM is 
installed
+     * into the custom local repository too, and neither jar nor POM gets a 
checksum file.
+     */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "gid")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    @MojoParameter(name = "generatePom", value = "true")
+    @MojoParameter(name = "localRepositoryPath", value = 
"target/local-repo-override")
+    void 
installFileIntoOverriddenLocalRepositoryWithGeneratedPomNoChecksums(InstallFileMojo
 mojo) throws Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        AtomicReference<Model> model = new AtomicReference<>();
+        ArtifactInstallerRequest request =
+                execute(mojo, air -> model.set(readModelFrom(air, 
getArtifact(null, "pom"))));
+
+        assertNotNull(request);
+        Artifact pom = getArtifact(null, "pom");
+        Artifact jar = getArtifact(null, "jar");
+        assertEquals(new HashSet<>(Arrays.asList(pom, jar)), new 
HashSet<>(request.getArtifacts()));
+        assertFileExistsInRequest(request, jar);
+        assertEquals(
+                Paths.get(getBasedir(), 
OVERRIDE_REPO).toString().replace(File.separator, "/"),
+                
request.getSession().getLocalRepository().getPath().toString().replace(File.separator,
 "/"));
+        assertEquals(groupId, model.get().getGroupId());
+        assertEquals(artifactId, model.get().getArtifactId());
+        assertEquals(version, model.get().getVersion());
+        assertNoChecksumFiles(Paths.get(getBasedir(), OVERRIDE_REPO));
+    }
+
+    private void assertFileExistsInRequest(ArtifactInstallerRequest request, 
Artifact artifact) {
+        ArtifactManager requestArtifactManager = 
request.getSession().getService(ArtifactManager.class);
+        
assertFileExists(requestArtifactManager.getPath(artifact).orElse(null));
+    }
+
+    private Model readModelFrom(ArtifactInstallerRequest request, Artifact 
pom) {
+        try {
+            ArtifactManager requestArtifactManager = 
request.getSession().getService(ArtifactManager.class);
+            Path pomPath = requestArtifactManager.getPath(pom).orElse(null);
+            assertNotNull(pomPath);
+            return session.getService(ModelXmlFactory.class).read(pomPath);
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private MojoException executeExpectingFailure(InstallFileMojo mojo) {
+        AtomicReference<ArtifactInstallerRequest> request = new 
AtomicReference<>();
+        doAnswer(iom -> {
+                    request.set(iom.getArgument(0, 
ArtifactInstallerRequest.class));
+                    return null;
+                })
+                .when(artifactInstaller)
+                .install(any(ArtifactInstallerRequest.class));
+        MojoException e = assertThrows(MojoException.class, mojo::execute);
+        assertNull(request.get(), "nothing should be installed on validation 
failure");
+        return e;
+    }
+
+    private static void assertNoChecksumFiles(Path repositoryRoot) throws 
Exception {

Review Comment:
   🔁 **`assertNoChecksumFiles` is duplicated in three test classes** — 
`InstallFileMojoTest` (here), `InstallMojoPomPackagingTest` (line 130), and 
`InstallMojoTest` (line 358) all carry an identical implementation.
   
   Consider extracting to a package-private static helper, e.g.:
   ```java
   // new file: InstallTestHelper.java
   package org.apache.maven.plugins.install;
   
   import java.nio.file.Files;
   import java.nio.file.Path;
   import java.util.stream.Stream;
   import static org.junit.jupiter.api.Assertions.assertTrue;
   
   class InstallTestHelper {
       static void assertNoChecksumFiles(Path repositoryRoot) throws Exception {
           if (!Files.exists(repositoryRoot)) return;
           try (Stream<Path> paths = Files.walk(repositoryRoot)) {
               assertTrue(
                   paths.noneMatch(p -> {
                       String name = p.getFileName().toString();
                       return name.endsWith(".md5") || name.endsWith(".sha1");
                   }),
                   "no .md5/.sha1 checksum files should be created");
           }
       }
   }
   ```
   Not a blocker — happy for this to be a follow-up.



##########
src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java:
##########
@@ -619,6 +623,220 @@ void dotDotVersionRejected(InstallFileMojo mojo) {
         assertTrue(e.getMessage().contains("not valid"), e.getMessage());
     }
 
+    // 
-------------------------------------------------------------------------------------------------------
+    // Conversions of the src/it integration tests that only exercised 
install:install-file mojo behaviour.
+    // The real ArtifactInstaller is mocked by the harness, so "installed" is 
asserted as the set of
+    // artifacts handed to it (plus the generated POM model captured while the 
install call is in flight).
+    // Checksum files are produced by Maven's ArtifactInstaller, never by this 
mojo; at this level we
+    // assert that no checksum artifact is handed to the installer and that 
none is left in the repo.
+    // 
-------------------------------------------------------------------------------------------------------
+
+    /** Converted from {@code src/it/gav-validation} (invalid coordinates, 
test-invalid.properties). */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "invalid~group")
+    @MojoParameter(name = "artifactId", value = "invalid/artifactId")
+    @MojoParameter(name = "version", value = "1+")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void invalidGavRejectedAndNothingInstalled(InstallFileMojo mojo) {
+        assertNotNull(mojo);
+
+        MojoException e = executeExpectingFailure(mojo);
+
+        assertTrue(e.getMessage().contains("The artifact information is not 
valid"), e.getMessage());
+    }
+
+    /** Converted from {@code src/it/gav-validation} (missing coordinates, 
test-missing.properties). */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "groupId")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void missingCoordinatesRejectedAndNothingInstalled(InstallFileMojo mojo) 
throws Exception {
+        assertNotNull(mojo);
+        // A jar with no embedded POM keeps the coordinates genuinely 
incomplete.
+        Path plainJar = createJarWithEntryBytes(
+                "Manifest-Version: 1.0\n".getBytes(StandardCharsets.UTF_8), 
"META-INF/MANIFEST.MF");
+        setVariableValueToObject(mojo, "file", plainJar);
+
+        MojoException e = executeExpectingFailure(mojo);
+
+        assertTrue(e.getMessage().contains("The artifact information is 
incomplete"), e.getMessage());
+    }
+
+    /** Converted from {@code src/it/generate-pom-auto-1}: with the default 
generatePom, a jar and a POM are installed. */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = 
"org.apache.maven.its.install.gpa1")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void generatePomAutoInstallsJarAndPom(InstallFileMojo mojo) throws 
Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        AtomicReference<Model> model = new AtomicReference<>();
+        ArtifactInstallerRequest request =
+                execute(mojo, air -> model.set(readModelFrom(air, 
getArtifact(null, "pom"))));
+
+        assertNotNull(request);
+        Artifact pom = getArtifact(null, "pom");
+        Artifact jar = getArtifact(null, "jar");
+        assertEquals(new HashSet<>(Arrays.asList(pom, jar)), new 
HashSet<>(request.getArtifacts()));
+        assertFileExists(artifactManager.getPath(jar).orElse(null));
+        assertEquals("4.0.0", model.get().getModelVersion());
+        assertEquals(groupId, model.get().getGroupId());
+        assertEquals(artifactId, model.get().getArtifactId());
+        assertEquals(version, model.get().getVersion());
+        assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO));
+    }
+
+    /** Converted from {@code src/it/generate-pom-auto-2}: a POM already in 
the repo is never overwritten. */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = 
"org.apache.maven.its.install.gpa2")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void existingPomNotOverwrittenWhenGeneratePomAuto(InstallFileMojo mojo) 
throws Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        Path existingPom =
+                Paths.get(getBasedir(), LOCAL_REPO, 
"org/apache/maven/its/install/gpa2/test/0.1/test-0.1.pom");
+        Files.createDirectories(existingPom.getParent());
+        Files.writeString(existingPom, "test");
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        Artifact jar = getArtifact(null, "jar");
+        assertEquals(Collections.singleton(jar), new 
HashSet<>(request.getArtifacts()));
+        assertFileExists(artifactManager.getPath(jar).orElse(null));
+        assertEquals("test", Files.readString(existingPom), "existing POM must 
keep its original 4-byte content");
+        assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO));
+    }
+
+    /** Converted from {@code src/it/local-repo-override-with-checksum}: 
install into a custom local repository. */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "gid")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    @MojoParameter(name = "localRepositoryPath", value = 
"target/local-repo-override")
+    void installFileIntoOverriddenLocalRepositoryNoChecksums(InstallFileMojo 
mojo) throws Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        Artifact jar = getArtifact(null, "jar");
+        assertTrue(request.getArtifacts().contains(jar), "the jar must be 
installed into the overridden repository");
+        assertTrue(request.getArtifacts().stream()
+                .noneMatch(a -> "md5".equals(a.getExtension()) || 
"sha1".equals(a.getExtension())));
+        assertFileExistsInRequest(request, jar);
+        assertEquals(
+                Paths.get(getBasedir(), 
OVERRIDE_REPO).toString().replace(File.separator, "/"),
+                
request.getSession().getLocalRepository().getPath().toString().replace(File.separator,
 "/"));
+        assertNoChecksumFiles(Paths.get(getBasedir(), OVERRIDE_REPO));
+    }
+
+    /**
+     * Converted from {@code 
src/it/local-repo-override-with-checksum-generatePom}: the generated POM is 
installed
+     * into the custom local repository too, and neither jar nor POM gets a 
checksum file.
+     */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "gid")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    @MojoParameter(name = "generatePom", value = "true")
+    @MojoParameter(name = "localRepositoryPath", value = 
"target/local-repo-override")
+    void 
installFileIntoOverriddenLocalRepositoryWithGeneratedPomNoChecksums(InstallFileMojo
 mojo) throws Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        AtomicReference<Model> model = new AtomicReference<>();
+        ArtifactInstallerRequest request =
+                execute(mojo, air -> model.set(readModelFrom(air, 
getArtifact(null, "pom"))));
+
+        assertNotNull(request);
+        Artifact pom = getArtifact(null, "pom");
+        Artifact jar = getArtifact(null, "jar");
+        assertEquals(new HashSet<>(Arrays.asList(pom, jar)), new 
HashSet<>(request.getArtifacts()));
+        assertFileExistsInRequest(request, jar);
+        assertEquals(
+                Paths.get(getBasedir(), 
OVERRIDE_REPO).toString().replace(File.separator, "/"),
+                
request.getSession().getLocalRepository().getPath().toString().replace(File.separator,
 "/"));
+        assertEquals(groupId, model.get().getGroupId());
+        assertEquals(artifactId, model.get().getArtifactId());
+        assertEquals(version, model.get().getVersion());
+        assertNoChecksumFiles(Paths.get(getBasedir(), OVERRIDE_REPO));
+    }
+
+    private void assertFileExistsInRequest(ArtifactInstallerRequest request, 
Artifact artifact) {
+        ArtifactManager requestArtifactManager = 
request.getSession().getService(ArtifactManager.class);
+        
assertFileExists(requestArtifactManager.getPath(artifact).orElse(null));
+    }
+
+    private Model readModelFrom(ArtifactInstallerRequest request, Artifact 
pom) {
+        try {
+            ArtifactManager requestArtifactManager = 
request.getSession().getService(ArtifactManager.class);
+            Path pomPath = requestArtifactManager.getPath(pom).orElse(null);
+            assertNotNull(pomPath);
+            return session.getService(ModelXmlFactory.class).read(pomPath);
+        } catch (Exception e) {

Review Comment:
   ⚠️ **`catch (Exception e)` is too broad.** `ModelXmlFactory.read(Path)` 
declares only `throws XmlReaderException`, so the broader catch hides any 
unexpected exception behind `IllegalStateException`. Narrow to:
   ```suggestion
           } catch (XmlReaderException e) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to