Skip to content

Partially migrate to JUnit 5 #489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions modello-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-testing</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a>
*/
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"));

Expand All @@ -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"));

Expand All @@ -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"));

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* SOFTWARE.
*/

import javax.inject.Inject;

import java.util.List;

import org.codehaus.modello.core.ModelloCore;
Expand All @@ -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 <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a>
* @author <a href="mailto:[email protected]">Emmanuel Venisse</a>
*/
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);
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package org.codehaus.modello.model;

/*
* Copyright (c) 2004, Jason van Zyl
*
Expand All @@ -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 <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a>
*/
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());
Expand All @@ -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));
Expand All @@ -49,36 +53,39 @@ 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");
assertNotGreaterThan("0.1.1", "0.2.0");
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");
Expand Down
8 changes: 6 additions & 2 deletions modello-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<reporting>
Expand All @@ -162,7 +167,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.9.0</version>
<configuration>
<projectsDirectory>src/it</projectsDirectory>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
Expand All @@ -175,7 +179,7 @@
<debug>true</debug>
<filterProperties>
<plexusUtilsVersion>3.0.22</plexusUtilsVersion>
<junitVersion>4.13.2</junitVersion>
<junit4Version>${junit4Version}</junit4Version>
<java.version>${java.version}</java.version>
<jdom.version>${jdom.version}</jdom.version>
</filterProperties>
Expand Down
2 changes: 1 addition & 1 deletion modello-maven-plugin/src/it/clone-java5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>@junitVersion@</version>
<version>@junit4Version@</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion modello-maven-plugin/src/it/clone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>@junitVersion@</version>
<version>@junit4Version@</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion modello-maven-plugin/src/it/javadoc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>@junitVersion@</version>
<version>@junit4Version@</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion modello-maven-plugin/src/it/maven-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>@junit4Version@</version>
</dependency>
</dependencies>
</project>
Loading
Loading