gnodet commented on code in PR #13263:
URL: https://github.com/apache/maven/pull/13263#discussion_r4093846715


##########
maven-core/src/test/java/org/apache/maven/project/ProjectSorterDependencyManagementTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.project;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Model;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class ProjectSorterDependencyManagementTest {
+    @Test
+    void importedReactorBomPrecedesConsumer() throws Exception {
+        MavenProject bom = createProject("org.example", "test-bom", 
"1-SNAPSHOT");
+        MavenProject consumer = createProject("org.example", "test-consumer", 
"1-SNAPSHOT");
+
+        Dependency importedBom = new Dependency();
+        importedBom.setGroupId("org.example");
+        importedBom.setArtifactId("test-bom");
+        importedBom.setVersion("${project.version}");
+        importedBom.setType("pom");
+        importedBom.setScope("import");
+
+        DependencyManagement dependencyManagement = new DependencyManagement();
+        dependencyManagement.addDependency(importedBom);
+        
consumer.getOriginalModel().setDependencyManagement(dependencyManagement);
+
+        ProjectSorter sorter = new ProjectSorter(Arrays.asList(consumer, bom));
+
+        assertEquals(Arrays.asList(ProjectSorter.getId(bom)), 
sorter.getDependencies(ProjectSorter.getId(consumer)));
+        assertEquals(Arrays.asList(bom, consumer), sorter.getSortedProjects());

Review Comment:
   Fixed in 6631d674fa — added `importedReactorBomWithPropertyVersion()` test 
using `${bom.version}` resolved from `project.getProperties()`.



##########
maven-core/src/test/java/org/apache/maven/project/ProjectSorterDependencyManagementTest.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.project;
+
+import java.util.Arrays;
+
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Model;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class ProjectSorterDependencyManagementTest {
+
+    /**
+     * Verifies that a BOM module imported via {@code <dependencyManagement>} 
is treated as a
+     * reactor graph edge: the BOM must be sorted before its consumer (-am 
direction).
+     */
+    @Test
+    void importedReactorBomPrecedesConsumer() throws Exception {
+        MavenProject bom = createProject("org.example", "test-bom", 
"1-SNAPSHOT");
+        MavenProject consumer = createProject("org.example", "test-consumer", 
"1-SNAPSHOT");
+
+        addBomImport(consumer, "org.example", "test-bom", 
"${project.version}");
+
+        ProjectSorter sorter = new ProjectSorter(Arrays.asList(consumer, bom));
+
+        assertEquals(Arrays.asList(ProjectSorter.getId(bom)), 
sorter.getDependencies(ProjectSorter.getId(consumer)));
+        assertEquals(Arrays.asList(bom, consumer), sorter.getSortedProjects());
+    }
+
+    /**
+     * Verifies the reverse direction (-amd): the consumer is a downstream 
dependent of the BOM,
+     * so the BOM knows about the consumer as one of its dependents.
+     */
+    @Test
+    void importedReactorBomKnowsItsDependents() throws Exception {
+        MavenProject bom = createProject("org.example", "test-bom", 
"1-SNAPSHOT");
+        MavenProject consumer = createProject("org.example", "test-consumer", 
"1-SNAPSHOT");
+
+        addBomImport(consumer, "org.example", "test-bom", 
"${project.version}");
+
+        ProjectSorter sorter = new ProjectSorter(Arrays.asList(consumer, bom));
+
+        assertTrue(
+                
sorter.getDependents(ProjectSorter.getId(bom)).contains(ProjectSorter.getId(consumer)),
+                "BOM should list the importing consumer as a dependent");
+    }
+
+    // 
-------------------------------------------------------------------------

Review Comment:
   Fixed in 6631d674fa.



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