Copilot commented on code in PR #185:
URL: 
https://github.com/apache/maven-toolchains-plugin/pull/185#discussion_r3637578036


##########
src/test/java/org/apache/maven/plugins/toolchain/jdk/SelectJdkToolchainMojoTest.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.plugins.toolchain.jdk;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.maven.toolchain.ToolchainPrivate;
+import org.apache.maven.toolchain.model.ToolchainModel;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class SelectJdkToolchainMojoTest {
+
+    @Test
+    void testGetJdkHomeWithNullModel() throws Exception {
+        ToolchainPrivate toolchain = createStub(null);
+        assertNull(invokeGetJdkHome(toolchain));
+    }
+
+    @Test
+    void testGetJdkHomeWithNullConfiguration() throws Exception {
+        ToolchainModel model = new ToolchainModel();
+        model.setConfiguration(null);
+        ToolchainPrivate toolchain = createStub(model);
+        assertNull(invokeGetJdkHome(toolchain));
+    }
+
+    @Test
+    void testGetJdkHomeWithMissingJdkHomeChild() throws Exception {
+        Xpp3Dom config = new Xpp3Dom("configuration");
+        ToolchainModel model = new ToolchainModel();
+        model.setConfiguration(config);
+        ToolchainPrivate toolchain = createStub(model);
+        assertNull(invokeGetJdkHome(toolchain));
+    }
+
+    @Test
+    void testGetJdkHomeWithValidJdkHome() throws Exception {
+        Xpp3Dom config = new Xpp3Dom("configuration");
+        Xpp3Dom jdkHome = new Xpp3Dom("jdkHome");
+        jdkHome.setValue("/path/to/jdk");
+        config.addChild(jdkHome);
+        ToolchainModel model = new ToolchainModel();
+        model.setConfiguration(config);
+        ToolchainPrivate toolchain = createStub(model);
+        assertEquals("/path/to/jdk", invokeGetJdkHome(toolchain));
+    }
+
+    private Object invokeGetJdkHome(ToolchainPrivate toolchain) throws 
Exception {
+        SelectJdkToolchainMojo mojo = new SelectJdkToolchainMojo();
+        Method method = 
SelectJdkToolchainMojo.class.getDeclaredMethod("getJdkHome", 
ToolchainPrivate.class);
+        method.setAccessible(true);
+        return method.invoke(mojo, toolchain);
+    }

Review Comment:
   `invokeGetJdkHome` returns `Object`, which weakens the test's type-safety 
(the production method returns `String`). Returning `String` here makes the 
test fail at compile time if `getJdkHome`'s contract changes, and avoids 
relying on `assertEquals(String, Object)` overload behavior.



##########
src/test/java/org/apache/maven/plugins/toolchain/jdk/SelectJdkToolchainMojoTest.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.plugins.toolchain.jdk;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.maven.toolchain.ToolchainPrivate;
+import org.apache.maven.toolchain.model.ToolchainModel;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class SelectJdkToolchainMojoTest {
+
+    @Test
+    void testGetJdkHomeWithNullModel() throws Exception {
+        ToolchainPrivate toolchain = createStub(null);
+        assertNull(invokeGetJdkHome(toolchain));
+    }
+
+    @Test
+    void testGetJdkHomeWithNullConfiguration() throws Exception {
+        ToolchainModel model = new ToolchainModel();
+        model.setConfiguration(null);
+        ToolchainPrivate toolchain = createStub(model);
+        assertNull(invokeGetJdkHome(toolchain));
+    }
+
+    @Test
+    void testGetJdkHomeWithMissingJdkHomeChild() throws Exception {
+        Xpp3Dom config = new Xpp3Dom("configuration");
+        ToolchainModel model = new ToolchainModel();
+        model.setConfiguration(config);
+        ToolchainPrivate toolchain = createStub(model);
+        assertNull(invokeGetJdkHome(toolchain));
+    }

Review Comment:
   The new `instanceof Xpp3Dom` guard changes behavior (prevents a potential 
`ClassCastException` when `ToolchainModel#getConfiguration()` isn't an 
`Xpp3Dom`), but the tests don't currently cover this scenario. Add a unit test 
with a non-`Xpp3Dom` configuration to ensure `getJdkHome()` returns null and 
does not throw.



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