From 6d031789e97f40676474a0f57d9d2234f097cc1b Mon Sep 17 00:00:00 2001 From: TheRealHaui Date: Mon, 1 Dec 2025 17:32:30 +0100 Subject: [PATCH 1/5] Add tests --- .../apache/maven/plugin/CacheUtilsTest.java | 130 ++++++++++++++++++ .../internal/xml/XmlNodeBuilderTest.java | 6 + 2 files changed, 136 insertions(+) create mode 100644 impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java diff --git a/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java b/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java new file mode 100644 index 000000000000..12c1e489d07c --- /dev/null +++ b/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java @@ -0,0 +1,130 @@ +/* + * 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.plugin; + +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Plugin; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class CacheUtilsTest { + + private Plugin pluginOne; + private Plugin pluginTwo; + + @BeforeEach + void doBeforeEachTest() { + pluginOne = new Plugin(); + pluginTwo = new Plugin(); + } + + @Test + void testPluginEqualsEmptyPlugins() { + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + } + + @Test + void testPluginEqualsSetArtifactId() { + pluginOne.setArtifactId("myArtifact"); + + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertFalse(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + + pluginTwo.setArtifactId("myArtifact"); + + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + } + + @Test + void testPluginEqualsSetGroupId() { + pluginOne.setGroupId("myGroupId"); + + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertFalse(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + + pluginTwo.setGroupId("myGroupId"); + + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + } + + @Test + void testPluginEqualsSetVersion() { + pluginOne.setVersion("myVersion"); + + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertFalse(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + + pluginTwo.setVersion("myVersion"); + + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + } + + @Test + void testPluginEqualsSetExtension() { + pluginOne.setExtensions("true"); + + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertFalse(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + + pluginTwo.setExtensions("TRUE"); + } + + @Test + void testPluginEqualsSetDependency() { + Dependency dependencyOne = new Dependency(); + pluginOne.addDependency(dependencyOne); + + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertFalse(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + + Dependency dependencyTwo = new Dependency(); + pluginTwo.addDependency(dependencyTwo); + + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + + dependencyTwo.setGroupId("myDependencyGroupId"); + + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertFalse(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + + dependencyOne.setGroupId("myDependencyGroupId"); + dependencyTwo.setArtifactId("myDependencyArtifactId"); + + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertFalse(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + + dependencyTwo.setVersion("myDependencyVersion"); + + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertFalse(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + + dependencyOne.setArtifactId("myDependencyArtifactId"); + dependencyTwo.setVersion("myDependencyVersion"); + + assertTrue(CacheUtils.pluginEquals(pluginOne, pluginOne)); + assertFalse(CacheUtils.pluginEquals(pluginOne, pluginTwo)); + } +} diff --git a/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeBuilderTest.java b/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeBuilderTest.java index 7dfd0f9de803..6816b24e0c98 100644 --- a/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeBuilderTest.java +++ b/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeBuilderTest.java @@ -21,8 +21,10 @@ import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.StringReader; +import java.nio.charset.StandardCharsets; import org.apache.maven.api.xml.XmlNode; import org.apache.maven.api.xml.XmlService; @@ -44,6 +46,10 @@ public int read(char[] cbuf, int off, int len) throws IOException { XmlNode node1 = XmlService.read(r); XmlNode node2 = XmlService.read(r); assertEquals(node1, node2); + + node1 = XmlService.read(new ByteArrayInputStream(doc.getBytes(StandardCharsets.UTF_8)), null); + node2 = XmlService.read(new ByteArrayInputStream(doc.getBytes(StandardCharsets.UTF_8)), null); + assertEquals(node1, node2); } @Test From db76418924390789475197de9b35c510ae65d80e Mon Sep 17 00:00:00 2001 From: TheRealHaui Date: Mon, 1 Dec 2025 18:06:48 +0100 Subject: [PATCH 2/5] Removed added star import --- .../src/test/java/org/apache/maven/plugin/CacheUtilsTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java b/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java index 12c1e489d07c..e71d2785ff93 100644 --- a/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java +++ b/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java @@ -23,7 +23,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + class CacheUtilsTest { From 2e87007e334c11f6817ca6909eb914cfee212a4a Mon Sep 17 00:00:00 2001 From: TheRealHaui Date: Thu, 4 Dec 2025 17:29:28 +0100 Subject: [PATCH 3/5] Merged remote --- .../src/test/java/org/apache/maven/plugin/CacheUtilsTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java b/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java index e71d2785ff93..4d6ed9725754 100644 --- a/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java +++ b/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java @@ -26,7 +26,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; - class CacheUtilsTest { private Plugin pluginOne; From 65b2a0e979f57e6eb0f62df7b8657197e9ef49ce Mon Sep 17 00:00:00 2001 From: TheRealHaui Date: Fri, 5 Dec 2025 19:46:02 +0100 Subject: [PATCH 4/5] Introduced new variables for test method instead of re-using existing --- .../org/apache/maven/internal/xml/XmlNodeBuilderTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeBuilderTest.java b/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeBuilderTest.java index 6816b24e0c98..3463be67134a 100644 --- a/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeBuilderTest.java +++ b/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeBuilderTest.java @@ -47,9 +47,9 @@ public int read(char[] cbuf, int off, int len) throws IOException { XmlNode node2 = XmlService.read(r); assertEquals(node1, node2); - node1 = XmlService.read(new ByteArrayInputStream(doc.getBytes(StandardCharsets.UTF_8)), null); - node2 = XmlService.read(new ByteArrayInputStream(doc.getBytes(StandardCharsets.UTF_8)), null); - assertEquals(node1, node2); + XmlNode node3 = XmlService.read(new ByteArrayInputStream(doc.getBytes(StandardCharsets.UTF_8)), null); + XmlNode node4 = XmlService.read(new ByteArrayInputStream(doc.getBytes(StandardCharsets.UTF_8)), null); + assertEquals(node3, node4); } @Test From d562ed79229234cdb0a6702b6f01b0c15b20cb97 Mon Sep 17 00:00:00 2001 From: TheRealHaui Date: Sat, 6 Dec 2025 17:26:03 +0100 Subject: [PATCH 5/5] Improved CacheUtilsTest --- .../org/apache/maven/plugin/CacheUtilsTest.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java b/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java index 4d6ed9725754..fc8b72285a4e 100644 --- a/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java +++ b/impl/maven-core/src/test/java/org/apache/maven/plugin/CacheUtilsTest.java @@ -20,22 +20,14 @@ import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; class CacheUtilsTest { - private Plugin pluginOne; - private Plugin pluginTwo; - - @BeforeEach - void doBeforeEachTest() { - pluginOne = new Plugin(); - pluginTwo = new Plugin(); - } + private Plugin pluginOne = new Plugin(); + private Plugin pluginTwo = new Plugin(); @Test void testPluginEqualsEmptyPlugins() {