From a362a30885e5f8b81643bca25d1843eb173a6614 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 4 Aug 2024 23:11:24 +0200 Subject: [PATCH] Partially migrate to JUnit 5 --- modello-core/pom.xml | 10 +++++ .../modello/core/DefaultModelloCoreTest.java | 42 +++++++++---------- .../modello/core/io/ModelReaderTest.java | 41 +++++++++--------- .../modello/model/VersionDefinitionTest.java | 16 ++++--- .../codehaus/modello/model/VersionTest.java | 35 +++++++++------- modello-maven-plugin/pom.xml | 8 +++- .../src/it/clone-java5/pom.xml | 2 +- modello-maven-plugin/src/it/clone/pom.xml | 2 +- modello-maven-plugin/src/it/javadoc/pom.xml | 2 +- .../src/it/maven-model/pom.xml | 2 +- pom.xml | 16 ++++--- 11 files changed, 101 insertions(+), 75 deletions(-) diff --git a/modello-core/pom.xml b/modello-core/pom.xml index 0c5a8aeea..62755cb89 100644 --- a/modello-core/pom.xml +++ b/modello-core/pom.xml @@ -49,6 +49,16 @@ runtime true + + org.junit.jupiter + junit-jupiter-api + test + + + org.codehaus.plexus + plexus-testing + test + diff --git a/modello-core/src/test/java/org/codehaus/modello/core/DefaultModelloCoreTest.java b/modello-core/src/test/java/org/codehaus/modello/core/DefaultModelloCoreTest.java index 35478370a..e11f6ae38 100644 --- a/modello-core/src/test/java/org/codehaus/modello/core/DefaultModelloCoreTest.java +++ b/modello-core/src/test/java/org/codehaus/modello/core/DefaultModelloCoreTest.java @@ -22,18 +22,27 @@ * SOFTWARE. */ +import javax.inject.Inject; + import org.codehaus.modello.ModelloRuntimeException; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.Test; + +import static org.codehaus.plexus.testing.PlexusExtension.getTestFile; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Trygve Laugstøl */ -public class DefaultModelloCoreTest extends PlexusTestCase { - public void testModelWithDuplicateClasses() throws Exception { - ModelloCore modello = (ModelloCore) lookup(ModelloCore.ROLE); +@PlexusTest +class DefaultModelloCoreTest { + @Inject + ModelloCore modello; + + @Test + void modelWithDuplicateClasses() throws Exception { try { modello.loadModel(getTestFile("src/test/resources/models/duplicate-classes.mdo")); @@ -43,9 +52,8 @@ public void testModelWithDuplicateClasses() throws Exception { } } - public void testModelWithDuplicateFields() throws Exception { - ModelloCore modello = (ModelloCore) lookup(ModelloCore.ROLE); - + @Test + void modelWithDuplicateFields() throws Exception { try { modello.loadModel(getTestFile("src/test/resources/models/duplicate-fields.mdo")); @@ -55,9 +63,8 @@ public void testModelWithDuplicateFields() throws Exception { } } - public void testModelWithDuplicateAssociations() throws Exception { - ModelloCore modello = (ModelloCore) lookup(ModelloCore.ROLE); - + @Test + void modelWithDuplicateAssociations() throws Exception { try { modello.loadModel(getTestFile("src/test/resources/models/duplicate-associations.mdo")); @@ -67,15 +74,8 @@ public void testModelWithDuplicateAssociations() throws Exception { } } - public void testRecursion() throws Exception { - ModelloCore modello = (ModelloCore) lookup(ModelloCore.ROLE); - + @Test + void recursion() throws Exception { modello.loadModel(getTestFile("src/test/resources/models/recursion.mdo")); } - - @Override - protected void customizeContainerConfiguration(ContainerConfiguration configuration) { - configuration.setAutoWiring(true); - configuration.setClassPathScanning(PlexusConstants.SCANNING_INDEX); - } } diff --git a/modello-core/src/test/java/org/codehaus/modello/core/io/ModelReaderTest.java b/modello-core/src/test/java/org/codehaus/modello/core/io/ModelReaderTest.java index 143402a0f..d7687f93d 100644 --- a/modello-core/src/test/java/org/codehaus/modello/core/io/ModelReaderTest.java +++ b/modello-core/src/test/java/org/codehaus/modello/core/io/ModelReaderTest.java @@ -22,6 +22,8 @@ * SOFTWARE. */ +import javax.inject.Inject; + import java.util.List; import org.codehaus.modello.core.ModelloCore; @@ -31,18 +33,24 @@ import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; import org.codehaus.modello.model.VersionRange; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.Test; + +import static org.codehaus.plexus.testing.PlexusExtension.getTestFile; +import static org.junit.jupiter.api.Assertions.*; /** * @author Trygve Laugstøl * @author Emmanuel Venisse */ -public class ModelReaderTest extends PlexusTestCase { - public void testBasic() throws Exception { - ModelloCore modello = (ModelloCore) lookup(ModelloCore.ROLE); +@PlexusTest +class ModelReaderTest { + + @Inject + ModelloCore modello; + @Test + void basic() throws Exception { Model model = modello.loadModel(getTestFile("src/test/resources/models/simple.mdo")); assertNotNull(model); @@ -73,14 +81,13 @@ public void testBasic() throws Exception { assertGirl(model.getClass("Girl", new VersionRange("1.0.0"))); } - public void testAssociationDefaultValues() throws Exception { - ModelloCore modello = (ModelloCore) lookup(ModelloCore.ROLE); - + @Test + void associationDefaultValues() throws Exception { Model model = modello.loadModel(getTestFile("src/test/resources/models/association.mdo")); ModelField field = model.getClass("Foo", new VersionRange("1.0.0")).getField("bars", new VersionRange("1.0.0")); - assertTrue(field instanceof ModelAssociation); + assertInstanceOf(ModelAssociation.class, field); ModelAssociation association = (ModelAssociation) field; @@ -102,7 +109,7 @@ public void testAssociationDefaultValues() throws Exception { } private void assertBoy(Object boyObject) { - assertTrue(boyObject instanceof ModelClass); + assertInstanceOf(ModelClass.class, boyObject); ModelClass boy = (ModelClass) boyObject; @@ -122,7 +129,7 @@ private void assertBoy(Object boyObject) { } private void assertBoyName(Object nameObject) { - assertTrue(nameObject instanceof ModelField); + assertInstanceOf(ModelField.class, nameObject); ModelField name = (ModelField) nameObject; @@ -136,7 +143,7 @@ private void assertBoyName(Object nameObject) { } private void assertGirl(Object girlObject) { - assertTrue(girlObject instanceof ModelClass); + assertInstanceOf(ModelClass.class, girlObject); ModelClass girl = (ModelClass) girlObject; @@ -156,7 +163,7 @@ private void assertGirl(Object girlObject) { } private void assertGirlAge(Object ageObject) { - assertTrue(ageObject instanceof ModelField); + assertInstanceOf(ModelField.class, ageObject); ModelField age = (ModelField) ageObject; @@ -166,10 +173,4 @@ private void assertGirlAge(Object ageObject) { assertEquals("int", age.getType()); } - - @Override - protected void customizeContainerConfiguration(ContainerConfiguration configuration) { - configuration.setAutoWiring(true); - configuration.setClassPathScanning(PlexusConstants.SCANNING_INDEX); - } } diff --git a/modello-core/src/test/java/org/codehaus/modello/model/VersionDefinitionTest.java b/modello-core/src/test/java/org/codehaus/modello/model/VersionDefinitionTest.java index f5968b709..48970a3b2 100644 --- a/modello-core/src/test/java/org/codehaus/modello/model/VersionDefinitionTest.java +++ b/modello-core/src/test/java/org/codehaus/modello/model/VersionDefinitionTest.java @@ -1,24 +1,30 @@ package org.codehaus.modello.model; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; -public class VersionDefinitionTest extends TestCase { +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; - public void testFieldType() { +class VersionDefinitionTest { + + @Test + void fieldType() { VersionDefinition def = new VersionDefinition(); def.setType("field"); assertTrue(def.isFieldType()); assertFalse(def.isNamespaceType()); } - public void testNamespaceType() { + @Test + void namespaceType() { VersionDefinition def = new VersionDefinition(); def.setType("namespace"); assertTrue(def.isNamespaceType()); assertFalse(def.isFieldType()); } - public void testFieldAndNamespaceType() { + @Test + void fieldAndNamespaceType() { VersionDefinition def = new VersionDefinition(); def.setType("field+namespace"); assertTrue(def.isFieldType()); diff --git a/modello-core/src/test/java/org/codehaus/modello/model/VersionTest.java b/modello-core/src/test/java/org/codehaus/modello/model/VersionTest.java index 403364fa5..b86a54abf 100644 --- a/modello-core/src/test/java/org/codehaus/modello/model/VersionTest.java +++ b/modello-core/src/test/java/org/codehaus/modello/model/VersionTest.java @@ -1,5 +1,4 @@ package org.codehaus.modello.model; - /* * Copyright (c) 2004, Jason van Zyl * @@ -21,16 +20,20 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Trygve Laugstøl */ -public class VersionTest extends TestCase { +class VersionTest { // TODO: Add testing for multidigit version numbers // TODO: Add tests for invalid version strings - public void testVersionParsing() { + @Test + void versionParsing() { Version version = new Version("1.2.3"); assertEquals(1, version.getMajor()); @@ -40,7 +43,8 @@ public void testVersionParsing() { assertEquals(3, version.getMicro()); } - public void testVersionRange() { + @Test + void versionRange() { VersionRange range = new VersionRange("2.0.0+"); assertFalse(new Version("1.0.0").inside(range)); @@ -49,24 +53,25 @@ public void testVersionRange() { assertTrue(new Version("3.0.0").inside(range)); - assertTrue(new Version("2.0.0").equals(range.getFromVersion())); + assertEquals(new Version("2.0.0"), range.getFromVersion()); - assertTrue(Version.INFINITE.equals(range.getToVersion())); + assertEquals(Version.INFINITE, range.getToVersion()); range = new VersionRange("1.0.0"); - assertTrue(new Version("1.0.0").equals(range.getFromVersion())); + assertEquals(new Version("1.0.0"), range.getFromVersion()); - assertTrue(new Version("1.0.0").equals(range.getToVersion())); + assertEquals(new Version("1.0.0"), range.getToVersion()); range = new VersionRange("1.0.0/3.0.0"); - assertTrue(new Version("1.0.0").equals(range.getFromVersion())); + assertEquals(new Version("1.0.0"), range.getFromVersion()); - assertTrue(new Version("3.0.0").equals(range.getToVersion())); + assertEquals(new Version("3.0.0"), range.getToVersion()); } - public void testGreaterThanWhenFooIsLessThanBar() { + @Test + void greaterThanWhenFooIsLessThanBar() { assertNotGreaterThan("1.0.0", "2.9.9"); assertNotGreaterThan("1.9.9", "2.0.0"); assertNotGreaterThan("0.1.0", "0.2.9"); @@ -74,11 +79,13 @@ public void testGreaterThanWhenFooIsLessThanBar() { assertNotGreaterThan("0.0.1", "0.0.1"); } - public void testGreaterThanWhenFooIsEqualBar() { + @Test + void greaterThanWhenFooIsEqualBar() { assertNotGreaterThan("1.2.3", "1.2.3"); } - public void testGreaterThanWhenFooIsGreaterThanBar() { + @Test + void greaterThanWhenFooIsGreaterThanBar() { assertGreaterThan("2.0.0", "1.9.9"); assertGreaterThan("2.9.9", "1.0.0"); assertGreaterThan("0.2.9", "0.1.0"); diff --git a/modello-maven-plugin/pom.xml b/modello-maven-plugin/pom.xml index 010c774b5..6d887c08c 100644 --- a/modello-maven-plugin/pom.xml +++ b/modello-maven-plugin/pom.xml @@ -143,6 +143,11 @@ slf4j-simple test + + junit + junit + test + @@ -162,7 +167,6 @@ org.apache.maven.plugins maven-invoker-plugin - 3.9.0 src/it ${project.build.directory}/it @@ -175,7 +179,7 @@ true 3.0.22 - 4.13.2 + ${junit4Version} ${java.version} ${jdom.version} diff --git a/modello-maven-plugin/src/it/clone-java5/pom.xml b/modello-maven-plugin/src/it/clone-java5/pom.xml index caa4c500d..3a01b52ac 100644 --- a/modello-maven-plugin/src/it/clone-java5/pom.xml +++ b/modello-maven-plugin/src/it/clone-java5/pom.xml @@ -21,7 +21,7 @@ junit junit - @junitVersion@ + @junit4Version@ diff --git a/modello-maven-plugin/src/it/clone/pom.xml b/modello-maven-plugin/src/it/clone/pom.xml index e0aa14123..a3600e97c 100644 --- a/modello-maven-plugin/src/it/clone/pom.xml +++ b/modello-maven-plugin/src/it/clone/pom.xml @@ -21,7 +21,7 @@ junit junit - @junitVersion@ + @junit4Version@ diff --git a/modello-maven-plugin/src/it/javadoc/pom.xml b/modello-maven-plugin/src/it/javadoc/pom.xml index a0033aa39..42ea53284 100644 --- a/modello-maven-plugin/src/it/javadoc/pom.xml +++ b/modello-maven-plugin/src/it/javadoc/pom.xml @@ -16,7 +16,7 @@ junit junit - @junitVersion@ + @junit4Version@ diff --git a/modello-maven-plugin/src/it/maven-model/pom.xml b/modello-maven-plugin/src/it/maven-model/pom.xml index ade38bc61..0a52fd390 100644 --- a/modello-maven-plugin/src/it/maven-model/pom.xml +++ b/modello-maven-plugin/src/it/maven-model/pom.xml @@ -51,7 +51,7 @@ junit junit - 4.13.1 + @junit4Version@ diff --git a/pom.xml b/pom.xml index 6ac32a458..4e530d816 100644 --- a/pom.xml +++ b/pom.xml @@ -196,6 +196,7 @@ 2.0.2 1.7.36 3.6.3 + 4.13.2