Copilot commented on code in PR #562: URL: https://github.com/apache/maven-ear-plugin/pull/562#discussion_r4360176377
########## src/test/java/org/apache/maven/plugins/ear/AbstractEarMojoTest.java: ########## @@ -0,0 +1,57 @@ +/* + * 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.ear; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +class AbstractEarMojoTest { + + @Test + void missingJbossConfigurationChildrenAreOptional() throws Exception { + TestMojo mojo = new TestMojo(); + Field jboss = AbstractEarMojo.class.getDeclaredField("jboss"); + jboss.setAccessible(true); + XmlPlexusConfiguration configuration = new XmlPlexusConfiguration("jboss"); + configuration.addChild(new XmlPlexusConfiguration(JbossConfiguration.VERSION)); + jboss.set(mojo, configuration); + + Method initialize = AbstractEarMojo.class.getDeclaredMethod("initializeJbossConfiguration"); + initialize.setAccessible(true); + initialize.invoke(mojo); + + assertEquals(JbossConfiguration.VERSION_4, mojo.getJbossConfiguration().getVersion()); + assertNull(mojo.getJbossConfiguration().getSecurityDomain()); + assertNull(mojo.getJbossConfiguration().getUnauthenticatedPrincipal()); + assertNull(mojo.getJbossConfiguration().getJmxName()); + assertNull(mojo.getJbossConfiguration().getLoaderRepository()); + assertNull(mojo.getJbossConfiguration().getModuleOrder()); + assertNull(mojo.getJbossConfiguration().getLibraryDirectory()); + } + Review Comment: This asserts `loaderRepository` is null, but the code change also adds null-safe handling for loader repository *attributes* (e.g., loader repository class and config parser class) and loader repository config text. If `JbossConfiguration` exposes those values via getters, add assertions for them too so the test actually covers the newly protected paths. ########## src/test/java/org/apache/maven/plugins/ear/AbstractEarMojoTest.java: ########## @@ -0,0 +1,57 @@ +/* + * 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.ear; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +class AbstractEarMojoTest { + + @Test + void missingJbossConfigurationChildrenAreOptional() throws Exception { + TestMojo mojo = new TestMojo(); + Field jboss = AbstractEarMojo.class.getDeclaredField("jboss"); + jboss.setAccessible(true); + XmlPlexusConfiguration configuration = new XmlPlexusConfiguration("jboss"); + configuration.addChild(new XmlPlexusConfiguration(JbossConfiguration.VERSION)); Review Comment: The test is meant to cover *omitted* optional children, but it still adds the `<version>` child (just without a value). If the original regression was triggered by a missing child element (not an empty element), this test may not fail when the bug reappears. Consider removing line 38 entirely (or adding a second test) to cover the case where the `<version>` element is not present at all and the default is applied. -- 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]
