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


##########
src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java:
##########
@@ -346,6 +346,115 @@ void attachedJarInstalledWithoutChecksums(InstallMojo 
mojo) throws Exception {
         InstallTestHelper.assertNoChecksumFiles(Paths.get(getBasedir(), 
LOCAL_REPO));
     }
 
+    /** Converted from {@code src/it/release-jar}: a plain release JAR 
installs its POM and JAR. */
+    @Test
+    @InjectMojo(goal = "install")
+    @MojoParameter(name = "installAtEnd", value = "false")
+    void releaseJarInstallsPomAndJar(InstallMojo mojo) throws Exception {
+        assertNotNull(mojo);
+        ProjectStub project = (ProjectStub) getVariableValueFromObject(mojo, 
"project");
+        project.setGroupId("org.apache.maven.its.install.rj");
+        project.setArtifactId("test");
+        project.setVersion("1.0");
+        ProducedArtifactStub main =
+                new ProducedArtifactStub("org.apache.maven.its.install.rj", 
"test", "", "1.0", "jar");
+        project.setMainArtifact(main);
+        artifactManager.setPath(
+                main, Paths.get(getBasedir(), 
"target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar"));
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        assertEquals(
+                Arrays.asList(
+                        "org.apache.maven.its.install.rj:test:pom:1.0", 
"org.apache.maven.its.install.rj:test:jar:1.0"),
+                request.getArtifacts().stream().map(Artifact::key).toList());
+        assertMetadataCoordinates(request, 
"org/apache/maven/its/install/rj/test", "1.0");
+    }
+
+    /**
+     * Converted from {@code src/it/attach-release-jar}: a release JAR with an 
attached sources JAR installs the
+     * POM, the main JAR and the classified sources JAR. {@code 
basicInstallWithAttachedArtifacts} covers the
+     * attachment mechanics, but used a different artifactId for the 
attachment and a snapshot version; this test
+     * preserves the IT's same-GAV sources classifier on a release version.
+     */
+    @Test
+    @InjectMojo(goal = "install")
+    @MojoParameter(name = "installAtEnd", value = "false")
+    void releaseJarWithAttachedSourcesInstallsPomJarAndSources(InstallMojo 
mojo) throws Exception {
+        assertNotNull(mojo);
+        ProjectStub project = (ProjectStub) getVariableValueFromObject(mojo, 
"project");
+        project.setGroupId("org.apache.maven.its.install.arj");
+        project.setArtifactId("test");
+        project.setVersion("1.0");
+        ProducedArtifactStub main =
+                new ProducedArtifactStub("org.apache.maven.its.install.arj", 
"test", "", "1.0", "jar");
+        project.setMainArtifact(main);
+        artifactManager.setPath(
+                main, Paths.get(getBasedir(), 
"target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar"));
+        projectManager.attachArtifact(
+                project,
+                new ProducedArtifactStub("org.apache.maven.its.install.arj", 
"test", "sources", "1.0", "jar"),
+                Paths.get(getBasedir()).resolve(ATTACHED_ARTIFACT_JAR));
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        assertEquals(
+                Arrays.asList(
+                        "org.apache.maven.its.install.arj:test:pom:1.0",
+                        "org.apache.maven.its.install.arj:test:jar:1.0",
+                        
"org.apache.maven.its.install.arj:test:jar:sources:1.0"),
+                request.getArtifacts().stream().map(Artifact::key).toList());
+        assertMetadataCoordinates(request, 
"org/apache/maven/its/install/arj/test", "1.0");
+    }
+
+    /** Converted from {@code src/it/snapshot-jar}: a snapshot JAR installs 
its POM and JAR at the version path. */
+    @Test
+    @InjectMojo(goal = "install")
+    @MojoParameter(name = "installAtEnd", value = "false")
+    void snapshotJarInstallsPomAndJarWithVersionedMetadata(InstallMojo mojo) 
throws Exception {
+        assertNotNull(mojo);
+        ProjectStub project = (ProjectStub) getVariableValueFromObject(mojo, 
"project");
+        project.setGroupId("org.apache.maven.its.install.sj");
+        project.setArtifactId("test");
+        project.setVersion("1.0-SNAPSHOT");
+        ProducedArtifactStub main =
+                new ProducedArtifactStub("org.apache.maven.its.install.sj", 
"test", "", "1.0-SNAPSHOT", "jar");
+        project.setMainArtifact(main);
+        artifactManager.setPath(
+                main, Paths.get(getBasedir(), 
"target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar"));
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        assertEquals(
+                Arrays.asList(
+                        
"org.apache.maven.its.install.sj:test:pom:1.0-SNAPSHOT",
+                        
"org.apache.maven.its.install.sj:test:jar:1.0-SNAPSHOT"),
+                request.getArtifacts().stream().map(Artifact::key).toList());
+        assertMetadataCoordinates(request, 
"org/apache/maven/its/install/sj/test", "1.0-SNAPSHOT");
+    }
+
+    /**
+     * Asserts the group-level and version-level {@code 
maven-metadata-local.xml} locations that the IT checked as
+     * files. The harness mocks the real {@link ArtifactInstaller}, which 
writes that metadata, so the paths are
+     * derived from the installed POM's coordinates handed to the session (see 
{@link InstallTestHelper}).
+     */
+    private void assertMetadataCoordinates(ArtifactInstallerRequest request, 
String groupArtifactPath, String version) {

Review Comment:
   ๐Ÿ” **Duplication:** Same method as 
`InstallMojoPomPackagingTest.assertMetadataCoordinates` (3-parameter version). 
Could be extracted to `InstallTestHelper` as a package-private static.



##########
src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java:
##########
@@ -909,6 +911,135 @@ record PackagingCase(
             String classifier,
             String extension) {}
 
+    /**
+     * Converted from {@code src/it/install-file-generated-pom}: install-file 
is given only {@code file} and
+     * {@code pomFile}; groupId/artifactId/version are inherited from the 
supplied POM's parent. The IT asserted
+     * that the POM and JAR land at the inherited 1.0 coordinates, that the 
group-level metadata exists, and that
+     * the original {@code pomFile} is still on disk. The harness mocks the 
real {@link ArtifactInstaller} (which
+     * writes the metadata), so the metadata path is expressed through the 
install request's coordinates.
+     */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void 
installFileWithPomFileInheritsCoordinatesAndKeepsSourcePom(InstallFileMojo 
mojo) throws Exception {
+        assertNotNull(mojo);
+        Path pomFile = Files.createTempFile("install-file-generated-pom", 
".pom");

Review Comment:
   ๐Ÿงน **Temp file leak:** `Files.createTempFile(...)` creates a file in the 
system temp directory that is never cleaned up. Consider using `@TempDir` 
injection or a `try/finally { Files.deleteIfExists(pomFile); }` to ensure the 
file is removed after the test completes.



##########
src/test/java/org/apache/maven/plugins/install/InstallMojoPomPackagingTest.java:
##########
@@ -124,6 +125,71 @@ void pomPackagingInstalledWithoutChecksums(InstallMojo 
mojo) throws Exception {
         InstallTestHelper.assertNoChecksumFiles(Paths.get(getBasedir(), 
LOCAL_REPO));
     }
 
+    /** Converted from {@code src/it/release-pom}: a plain release POM 
installs only its POM. */
+    @Test
+    @InjectMojo(goal = "install")
+    @MojoParameter(name = "installAtEnd", value = "false")
+    void releasePomInstallsPom(InstallMojo mojo) throws Exception {
+        assertNotNull(mojo);
+        ProjectStub project = (ProjectStub) getVariableValueFromObject(mojo, 
"project");
+        project.setGroupId("org.apache.maven.its.install.rp");
+        project.setArtifactId("test");
+        project.setVersion("1.0");
+        artifactManager.setPath(project.getPomArtifact(), 
project.getPomPath());
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        assertEquals(
+                List.of("org.apache.maven.its.install.rp:test:pom:1.0"),
+                request.getArtifacts().stream().map(Artifact::key).toList());
+        assertMetadataCoordinates(request, 
"org/apache/maven/its/install/rp/test", "1.0");
+    }
+
+    /**
+     * Converted from {@code src/it/snapshot-pom}: a snapshot POM installs its 
POM at the version path and the IT's
+     * two metadata locations. {@code installIfPackagingIsPom} covers the 
artifact part; this adds the metadata
+     * coordinates, which are the only assertion that IT had beyond it.
+     */
+    @Test
+    @InjectMojo(goal = "install")
+    @MojoParameter(name = "installAtEnd", value = "false")
+    void snapshotPomInstallsPomWithVersionedMetadata(InstallMojo mojo) throws 
Exception {
+        assertNotNull(mojo);
+        ProjectStub project = (ProjectStub) getVariableValueFromObject(mojo, 
"project");
+        project.setGroupId("org.apache.maven.its.install.sp");
+        project.setArtifactId("test");
+        project.setVersion("1.0-SNAPSHOT");
+        artifactManager.setPath(project.getPomArtifact(), 
project.getPomPath());
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        assertEquals(
+                
List.of("org.apache.maven.its.install.sp:test:pom:1.0-SNAPSHOT"),
+                request.getArtifacts().stream().map(Artifact::key).toList());
+        assertMetadataCoordinates(request, 
"org/apache/maven/its/install/sp/test", "1.0-SNAPSHOT");
+    }
+
+    /**
+     * Asserts the group-level and version-level {@code 
maven-metadata-local.xml} locations that the IT checked as
+     * files. The harness mocks the real {@link ArtifactInstaller}, which 
writes that metadata, so the paths are
+     * derived from the installed POM's coordinates handed to the session (see 
{@link InstallTestHelper}).
+     */
+    private void assertMetadataCoordinates(ArtifactInstallerRequest request, 
String groupArtifactPath, String version) {

Review Comment:
   ๐Ÿ” **Duplication:** This method body is byte-identical to 
`assertMetadataCoordinates` in `InstallMojoTest`. Since `InstallTestHelper` is 
already the shared utility class (expanded in this PR), consider extracting 
this as a `static` method there.



-- 
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