anukalp2804 commented on code in PR #11576:
URL: https://github.com/apache/maven/pull/11576#discussion_r3290157408
##########
impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultProjectManagerTest.java:
##########
@@ -20,43 +20,102 @@
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.function.Supplier;
+import org.apache.maven.api.Language;
import org.apache.maven.api.ProducedArtifact;
import org.apache.maven.api.Project;
+import org.apache.maven.api.ProjectScope;
import org.apache.maven.api.services.ArtifactManager;
import org.apache.maven.impl.DefaultModelVersionParser;
+import org.apache.maven.impl.DefaultSourceRoot;
import org.apache.maven.impl.DefaultVersionParser;
import org.apache.maven.project.MavenProject;
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;
class DefaultProjectManagerTest {
+ private DefaultProjectManager projectManager;
+
+ private Project project;
+
+ private ProducedArtifact artifact;
+
+ private Path artifactPath;
+
@Test
void attachArtifact() {
InternalMavenSession session =
Mockito.mock(InternalMavenSession.class);
ArtifactManager artifactManager = Mockito.mock(ArtifactManager.class);
MavenProject mavenProject = new MavenProject();
- Project project = new DefaultProject(session, mavenProject);
- ProducedArtifact artifact = Mockito.mock(ProducedArtifact.class);
- Path path = Paths.get("");
+ project = new DefaultProject(session, mavenProject);
+ artifact = Mockito.mock(ProducedArtifact.class);
+ artifactPath = Paths.get("");
DefaultVersionParser versionParser =
new DefaultVersionParser(new DefaultModelVersionParser(new
GenericVersionScheme()));
- DefaultProjectManager projectManager = new
DefaultProjectManager(session, artifactManager);
+ projectManager = new DefaultProjectManager(session, artifactManager);
mavenProject.setGroupId("myGroup");
mavenProject.setArtifactId("myArtifact");
mavenProject.setVersion("1.0-SNAPSHOT");
when(artifact.getGroupId()).thenReturn("myGroup");
when(artifact.getArtifactId()).thenReturn("myArtifact");
when(artifact.getBaseVersion()).thenReturn(versionParser.parseVersion("1.0-SNAPSHOT"));
- projectManager.attachArtifact(project, artifact, path);
+ projectManager.attachArtifact(project, artifact, artifactPath);
+ // Verify that an exception is thrown when the artifactId differs
when(artifact.getArtifactId()).thenReturn("anotherArtifact");
- assertThrows(IllegalArgumentException.class, () ->
projectManager.attachArtifact(project, artifact, path));
+ assertExceptionMessageContains("myGroup:myArtifact:1.0-SNAPSHOT",
"myGroup:anotherArtifact:1.0-SNAPSHOT");
+
+ // Add a Java module. It should relax the restriction on artifactId.
+ projectManager.addSourceRoot(
+ project,
+ new DefaultSourceRoot(
+ ProjectScope.MAIN,
+ Language.JAVA_FAMILY,
+ "org.foo.bar",
+ null,
+ Path.of("myProject"),
+ null,
+ null,
+ false,
+ null,
+ true));
+
+ // Verify that we get the same exception when the artifactId does not
match the module name
+ assertExceptionMessageContains("", "anotherArtifact");
+
+ // Verify that no exception is thrown when the artifactId is the
module name
+ when(artifact.getArtifactId()).thenReturn("org.foo.bar");
+ projectManager.attachArtifact(project, artifact, artifactPath);
+
+ // Verify that an exception is thrown when the groupId differs
+ when(artifact.getGroupId()).thenReturn("anotherGroup");
+ assertExceptionMessageContains("myGroup:myArtifact:1.0-SNAPSHOT",
"anotherGroup:org.foo.bar:1.0-SNAPSHOT");
+ }
+
+ /**
+ * Verifies that {@code projectManager.attachArtifact(…)} throws an
exception,
+ * and that the expecption message contains the expected and actual
<abbr>GAV</abbr>.
Review Comment:
Hi @gnodet , I have corrected and raise seperate pr for the
`DefaultProjectManagerTest.java` file #12143. So, please review it whenever you
have time and let me know if any changes needed from my side.
Thank you
--
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]