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


##########
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultDependencyResolverResultTest.java:
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.impl;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.jar.Attributes;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import org.apache.maven.api.Dependency;
+import org.apache.maven.api.JavaPathType;
+import org.apache.maven.api.Node;
+import org.apache.maven.api.PathType;
+import org.apache.maven.api.services.DependencyResolverRequest;
+import org.apache.maven.impl.resolver.type.DefaultType;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/** Unit tests for {@link DefaultDependencyResolverResult}. */
+public class DefaultDependencyResolverResultTest {

Review Comment:
   The project convention for test classes in this package is package-private 
visibility (`class DefaultNodeTest`, `class DefaultProblemCollectorTest`, 
etc.). Consider dropping `public` to stay consistent:
   ```suggestion
   class DefaultDependencyResolverResultTest {
   ```



##########
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultDependencyResolverResultTest.java:
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.impl;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.jar.Attributes;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import org.apache.maven.api.Dependency;
+import org.apache.maven.api.JavaPathType;
+import org.apache.maven.api.Node;
+import org.apache.maven.api.PathType;
+import org.apache.maven.api.services.DependencyResolverRequest;
+import org.apache.maven.impl.resolver.type.DefaultType;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/** Unit tests for {@link DefaultDependencyResolverResult}. */
+public class DefaultDependencyResolverResultTest {
+
+    private static DefaultType createJarType(PathType pathType) {
+        return new DefaultType("jar", 
org.apache.maven.api.Language.JAVA_FAMILY, "jar", null, false, pathType);
+    }
+
+    @Test
+    public void testAddDependencyWithNullDependencyAddsNodeOnly() throws 
Exception {
+        DependencyResolverRequest req = mock(DependencyResolverRequest.class);
+        List<Exception> exceptions = new ArrayList<>();
+        Node root = mock(Node.class);
+        PathModularizationCache cache = new 
PathModularizationCache(Runtime.version());
+
+        DefaultDependencyResolverResult result = new 
DefaultDependencyResolverResult(req, cache, exceptions, root, 4);
+
+        Node node = mock(Node.class);
+        // addDependency with null dependency should only add the node
+        result.addDependency(node, null, (Predicate<PathType>) (t) -> true, 
null);
+
+        assertEquals(1, result.getNodes().size());
+        assertEquals(0, result.getDependencies().size());
+        assertEquals(0, result.getPaths().size());
+        assertTrue(result.getDispatchedPaths().isEmpty());
+    }
+
+    @Test
+    public void testAddDependencyDuplicateThrows() throws Exception {
+        DependencyResolverRequest req = mock(DependencyResolverRequest.class);
+        List<Exception> exceptions = new ArrayList<>();
+        Node root = mock(Node.class);
+        PathModularizationCache cache = new 
PathModularizationCache(Runtime.version());
+
+        DefaultDependencyResolverResult result = new 
DefaultDependencyResolverResult(req, cache, exceptions, root, 4);
+
+        Dependency dep = mock(Dependency.class);
+        when(dep.getGroupId()).thenReturn("g");
+        when(dep.getArtifactId()).thenReturn("a");
+        when(dep.getType()).thenReturn(createJarType(JavaPathType.MODULES));
+
+        Node node = mock(Node.class);
+        Path p = Files.createTempFile("dup", ".jar");

Review Comment:
   All temp files and directories created in the tests (`Files.createTempFile`, 
`Files.createTempDirectory`) are never cleaned up. The project convention is to 
use JUnit 5's `@TempDir` annotation (see `DefaultPathMatcherFactoryTest` and 
`PathSelectorTest` in this same package). For example:
   ```java
   @TempDir
   Path tempDir;
   ```
   then use `tempDir.resolve("dup.jar")` instead of 
`Files.createTempFile("dup", ".jar")`. This ensures automatic cleanup after 
each test.



##########
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultDependencyResolverResultTest.java:
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.impl;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.jar.Attributes;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import org.apache.maven.api.Dependency;
+import org.apache.maven.api.JavaPathType;
+import org.apache.maven.api.Node;
+import org.apache.maven.api.PathType;
+import org.apache.maven.api.services.DependencyResolverRequest;
+import org.apache.maven.impl.resolver.type.DefaultType;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/** Unit tests for {@link DefaultDependencyResolverResult}. */
+public class DefaultDependencyResolverResultTest {
+
+    private static DefaultType createJarType(PathType pathType) {
+        return new DefaultType("jar", 
org.apache.maven.api.Language.JAVA_FAMILY, "jar", null, false, pathType);
+    }
+
+    @Test
+    public void testAddDependencyWithNullDependencyAddsNodeOnly() throws 
Exception {
+        DependencyResolverRequest req = mock(DependencyResolverRequest.class);
+        List<Exception> exceptions = new ArrayList<>();
+        Node root = mock(Node.class);
+        PathModularizationCache cache = new 
PathModularizationCache(Runtime.version());
+
+        DefaultDependencyResolverResult result = new 
DefaultDependencyResolverResult(req, cache, exceptions, root, 4);
+
+        Node node = mock(Node.class);
+        // addDependency with null dependency should only add the node

Review Comment:
   Consider also testing the returned collections from `getExceptions()`, 
`getRoot()`, `getRequest()`, and `getDependencies()` (the `Map<Dependency, 
Path>` return). These are all public API methods on the 
`DependencyResolverResult` interface. Additionally, 
`warningForFilenameBasedAutomodules()` is untested. Even though some of these 
are simple, verifying them in the unit test ensures they stay correctly wired.



##########
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultDependencyResolverResultTest.java:
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.impl;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.jar.Attributes;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import org.apache.maven.api.Dependency;
+import org.apache.maven.api.JavaPathType;
+import org.apache.maven.api.Node;
+import org.apache.maven.api.PathType;
+import org.apache.maven.api.services.DependencyResolverRequest;
+import org.apache.maven.impl.resolver.type.DefaultType;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/** Unit tests for {@link DefaultDependencyResolverResult}. */
+public class DefaultDependencyResolverResultTest {
+
+    private static DefaultType createJarType(PathType pathType) {
+        return new DefaultType("jar", 
org.apache.maven.api.Language.JAVA_FAMILY, "jar", null, false, pathType);
+    }
+
+    @Test
+    public void testAddDependencyWithNullDependencyAddsNodeOnly() throws 
Exception {
+        DependencyResolverRequest req = mock(DependencyResolverRequest.class);
+        List<Exception> exceptions = new ArrayList<>();
+        Node root = mock(Node.class);

Review Comment:
   This 5-line construction block (mock request, empty exceptions list, mock 
root, cache, result) is repeated identically in every test method. Consider 
extracting it into a `@BeforeEach` setup method with instance fields, or at 
least a small `createResult(int count)` helper. That would cut approximately 50 
lines of duplication and make each test focus on the behavior it is verifying 
rather than boilerplate setup.



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