Skip to content

Commit 10d118f

Browse files
authored
chore: migrate junit 3 test to junit4 (#523)
* chore: migrate junit 3 test to junit4 * chore: migrate plexus test case based test to Plexusextension * chore: migrate custom configuration to use plexustestconfiguration * chore: remove junit 3 and plexus testcase specific code --------- Signed-off-by: Sandra Parsick <[email protected]>
1 parent 25e6590 commit 10d118f

File tree

71 files changed

+660
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+660
-184
lines changed

modello-maven-plugin/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@
148148
<artifactId>junit</artifactId>
149149
<scope>test</scope>
150150
</dependency>
151+
<dependency>
152+
<groupId>org.codehaus.plexus</groupId>
153+
<artifactId>plexus-testing</artifactId>
154+
<scope>test</scope>
155+
</dependency>
156+
<dependency>
157+
<groupId>org.junit.jupiter</groupId>
158+
<artifactId>junit-jupiter-api</artifactId>
159+
<scope>test</scope>
160+
</dependency>
161+
<dependency>
162+
<groupId>org.junit.jupiter</groupId>
163+
<artifactId>junit-jupiter-params</artifactId>
164+
<scope>test</scope>
165+
</dependency>
151166
</dependencies>
152167

153168
<reporting>

modello-maven-plugin/src/it/clone-java5/src/test/java/test/CloneTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
import org.codehaus.plexus.util.xml.Xpp3Dom;
66

7-
import junit.framework.TestCase;
7+
import org.junit.Test;
8+
9+
import static org.junit.Assert.assertEquals;
10+
import static org.junit.Assert.assertNotNull;
11+
import static org.junit.Assert.assertNotSame;
12+
import static org.junit.Assert.assertSame;
813

914
public class CloneTest
10-
extends TestCase
1115
{
12-
16+
@Test
1317
public void testNullSafe()
1418
throws Exception
1519
{
@@ -20,7 +24,7 @@ public void testNullSafe()
2024
assertNotNull( copy );
2125
assertNotSame( orig, copy );
2226
}
23-
27+
@Test
2428
public void testClone()
2529
throws Exception
2630
{

modello-maven-plugin/src/it/clone/src/test/java/test/CloneTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
import org.codehaus.plexus.util.xml.Xpp3Dom;
66

7-
import junit.framework.TestCase;
7+
import org.junit.Test;
8+
9+
import static org.junit.Assert.assertEquals;
10+
import static org.junit.Assert.assertNotNull;
11+
import static org.junit.Assert.assertNotSame;
12+
import static org.junit.Assert.assertSame;
813

914
public class CloneTest
10-
extends TestCase
1115
{
12-
16+
@Test
1317
public void testNullSafe()
1418
throws Exception
1519
{
@@ -20,7 +24,7 @@ public void testNullSafe()
2024
assertNotNull( copy );
2125
assertNotSame( orig, copy );
2226
}
23-
27+
@Test
2428
public void testClone()
2529
throws Exception
2630
{

modello-maven-plugin/src/test/java/org/codehaus/modello/maven/ModelloConvertersMojoTest.java

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,44 @@
2222
* SOFTWARE.
2323
*/
2424

25+
import javax.inject.Inject;
26+
2527
import java.io.File;
2628
import java.util.Arrays;
2729

2830
import org.apache.maven.project.MavenProject;
2931
import org.codehaus.modello.core.ModelloCore;
3032
import org.codehaus.plexus.ContainerConfiguration;
31-
import org.codehaus.plexus.PlexusTestCase;
3233
import org.codehaus.plexus.build.BuildContext;
34+
import org.codehaus.plexus.testing.PlexusExtension;
35+
import org.codehaus.plexus.testing.PlexusTest;
36+
import org.codehaus.plexus.testing.PlexusTestConfiguration;
3337
import org.codehaus.plexus.util.FileUtils;
38+
import org.junit.jupiter.api.Test;
39+
40+
import static org.codehaus.plexus.testing.PlexusExtension.getTestFile;
41+
import static org.junit.jupiter.api.Assertions.assertFalse;
42+
import static org.junit.jupiter.api.Assertions.assertTrue;
3443

3544
/**
3645
* @author <a href="mailto:[email protected]">Brett Porter</a>
3746
*/
38-
public class ModelloConvertersMojoTest extends PlexusTestCase {
39-
public void testModelloConvertersMojo() throws Exception {
40-
ModelloCore modelloCore = (ModelloCore) lookup(ModelloCore.ROLE);
47+
@PlexusTest
48+
public class ModelloConvertersMojoTest implements PlexusTestConfiguration {
49+
50+
@Inject
51+
private ModelloCore modelloCore;
4152

42-
BuildContext buildContext = (BuildContext) lookup(BuildContext.class);
53+
@Inject
54+
private BuildContext buildContext;
4355

56+
@Override
57+
public void customizeConfiguration(ContainerConfiguration containerConfiguration) {
58+
containerConfiguration.setClassPathScanning("cache");
59+
}
60+
61+
@Test
62+
public void testModelloConvertersMojo() throws Exception {
4463
ModelloConvertersMojo mojo = new ModelloConvertersMojo();
4564

4665
File outputDirectory = getTestFile("target/converters-test");
@@ -54,7 +73,7 @@ public void testModelloConvertersMojo() throws Exception {
5473
mojo.setOutputDirectory(outputDirectory);
5574

5675
String models[] = new String[1];
57-
models[0] = getTestPath("src/test/resources/java-model.mdo");
76+
models[0] = PlexusExtension.getTestPath("src/test/resources/java-model.mdo");
5877
mojo.setModels(models);
5978

6079
mojo.setVersion("1.0.0");
@@ -78,33 +97,28 @@ public void testModelloConvertersMojo() throws Exception {
7897
File javaFile =
7998
new File(outputDirectory, "org/codehaus/mojo/modello/javatest/v1_0_0/convert/VersionConverter.java");
8099

81-
assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
100+
assertTrue(javaFile.exists(), "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.");
82101

83102
javaFile = new File(
84103
outputDirectory, "org/codehaus/mojo/modello/javatest/v1_0_0/convert/BasicVersionConverter.java");
85104

86-
assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
105+
assertTrue(javaFile.exists(), "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.");
87106

88107
javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/v0_9_0/convert/VersionConverter.java");
89108

90-
assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
109+
assertTrue(javaFile.exists(), "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.");
91110

92111
javaFile = new File(
93112
outputDirectory, "org/codehaus/mojo/modello/javatest/v0_9_0/convert/BasicVersionConverter.java");
94113

95-
assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
114+
assertTrue(javaFile.exists(), "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.");
96115

97116
javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/convert/VersionConverter.java");
98117

99-
assertFalse("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
118+
assertFalse(javaFile.exists(), "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.");
100119

101120
javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/convert/BasicVersionConverter.java");
102121

103-
assertFalse("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
104-
}
105-
106-
@Override
107-
protected void customizeContainerConfiguration(ContainerConfiguration containerConfiguration) {
108-
containerConfiguration.setClassPathScanning("cache");
122+
assertFalse(javaFile.exists(), "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.");
109123
}
110124
}

modello-maven-plugin/src/test/java/org/codehaus/modello/maven/ModelloJavaMojoTest.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,38 @@
2222
* SOFTWARE.
2323
*/
2424

25+
import javax.inject.Inject;
26+
2527
import java.io.File;
2628
import java.util.Arrays;
2729

2830
import org.apache.maven.project.MavenProject;
2931
import org.codehaus.modello.core.ModelloCore;
3032
import org.codehaus.plexus.ContainerConfiguration;
31-
import org.codehaus.plexus.PlexusTestCase;
3233
import org.codehaus.plexus.build.BuildContext;
34+
import org.codehaus.plexus.testing.PlexusTest;
35+
import org.codehaus.plexus.testing.PlexusTestConfiguration;
3336
import org.codehaus.plexus.util.FileUtils;
37+
import org.junit.jupiter.api.Test;
38+
39+
import static org.codehaus.plexus.testing.PlexusExtension.getTestFile;
40+
import static org.codehaus.plexus.testing.PlexusExtension.getTestPath;
41+
import static org.junit.jupiter.api.Assertions.assertFalse;
42+
import static org.junit.jupiter.api.Assertions.assertTrue;
3443

3544
/**
3645
* @author <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a>
3746
*/
38-
public class ModelloJavaMojoTest extends PlexusTestCase {
39-
public void testModelloJavaMojo() throws Exception {
40-
ModelloCore modelloCore = (ModelloCore) lookup(ModelloCore.ROLE);
47+
@PlexusTest
48+
public class ModelloJavaMojoTest implements PlexusTestConfiguration {
49+
@Inject
50+
private BuildContext buildContext;
4151

42-
BuildContext buildContext = (BuildContext) lookup(BuildContext.class);
52+
@Inject
53+
private ModelloCore modelloCore;
54+
55+
@Test
56+
public void testModelloJavaMojo() throws Exception {
4357

4458
ModelloJavaMojo mojo = new ModelloJavaMojo();
4559

@@ -76,32 +90,32 @@ public void testModelloJavaMojo() throws Exception {
7690

7791
File javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/Model.java");
7892

79-
assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
93+
assertTrue(javaFile.exists(), "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.");
8094

8195
javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/NewModel.java");
8296

83-
assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
97+
assertTrue(javaFile.exists(), "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.");
8498

8599
javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/v1_0_0/Model.java");
86100

87-
assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
101+
assertTrue(javaFile.exists(), "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.");
88102

89103
javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/v1_0_0/NewModel.java");
90104

91-
assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
105+
assertTrue(javaFile.exists(), "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.");
92106

93107
javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/v0_9_0/Model.java");
94108

95-
assertTrue("The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
109+
assertTrue(javaFile.exists(), "The generated java file doesn't exist: '" + javaFile.getAbsolutePath() + "'.");
96110

97111
javaFile = new File(outputDirectory, "org/codehaus/mojo/modello/javatest/v0_9_0/NewModel.java");
98112

99113
assertFalse(
100-
"The generated java file shouldn't exist: '" + javaFile.getAbsolutePath() + "'.", javaFile.exists());
114+
javaFile.exists(), "The generated java file shouldn't exist: '" + javaFile.getAbsolutePath() + "'.");
101115
}
102116

103117
@Override
104-
protected void customizeContainerConfiguration(ContainerConfiguration containerConfiguration) {
118+
public void customizeConfiguration(ContainerConfiguration containerConfiguration) {
105119
containerConfiguration.setClassPathScanning("cache");
106120
}
107121
}

modello-plugins/modello-plugin-converters/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
<version>7.1.1</version>
3838
<scope>test</scope>
3939
</dependency>
40+
<!-- needed for modello compiler test(inside)-->
41+
<dependency>
42+
<groupId>junit</groupId>
43+
<artifactId>junit</artifactId>
44+
<scope>test</scope>
45+
</dependency>
4046
</dependencies>
4147

4248
<build>

modello-plugins/modello-plugin-converters/src/test/java/org/codehaus/modello/plugin/converters/ConverterGeneratorTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* SOFTWARE.
2323
*/
2424

25+
import javax.inject.Inject;
26+
2527
import java.io.Reader;
2628
import java.util.HashMap;
2729
import java.util.Map;
@@ -31,14 +33,22 @@
3133
import org.codehaus.modello.ModelloParameterConstants;
3234
import org.codehaus.modello.core.ModelloCore;
3335
import org.codehaus.modello.model.Model;
36+
import org.codehaus.plexus.testing.PlexusTest;
37+
import org.junit.jupiter.api.Test;
3438

3539
/**
3640
*/
41+
@PlexusTest
3742
public class ConverterGeneratorTest extends AbstractModelloJavaGeneratorTest {
43+
44+
@Inject
45+
private ModelloCore modello;
46+
3847
public ConverterGeneratorTest() {
3948
super("converters");
4049
}
4150

51+
@Test
4252
public void testConverterGenerator() throws Throwable {
4353
generateConverterClasses(getXmlResourceReader("/models/maven.mdo"), "3.0.0", "4.0.0");
4454

@@ -53,8 +63,6 @@ public void testConverterGenerator() throws Throwable {
5363
}
5464

5565
private void generateConverterClasses(Reader modelReader, String fromVersion, String toVersion) throws Throwable {
56-
ModelloCore modello = (ModelloCore) lookup(ModelloCore.ROLE);
57-
5866
Model model = modello.loadModel(modelReader);
5967

6068
Map<String, Object> parameters = new HashMap<>();

modello-plugins/modello-plugin-dom4j/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
<artifactId>xmlunit-core</artifactId>
3838
<scope>test</scope>
3939
</dependency>
40+
<!-- needed for modello compiler test(inside)-->
41+
<dependency>
42+
<groupId>junit</groupId>
43+
<artifactId>junit</artifactId>
44+
<scope>test</scope>
45+
</dependency>
4046
</dependencies>
4147

4248
<build>

modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/dom4j/Dom4jGeneratorTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* SOFTWARE.
2323
*/
2424

25+
import javax.inject.Inject;
26+
2527
import java.util.List;
2628
import java.util.Map;
2729

@@ -32,20 +34,27 @@
3234
import org.codehaus.modello.model.ModelField;
3335
import org.codehaus.modello.model.Version;
3436
import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata;
37+
import org.codehaus.plexus.testing.PlexusTest;
38+
import org.junit.jupiter.api.Test;
39+
40+
import static org.junit.jupiter.api.Assertions.*;
3541

3642
/**
3743
* Test the generators.
3844
*
3945
* @author <a href="mailto:[email protected]">Brett Porter</a>
4046
*/
47+
@PlexusTest
4148
public class Dom4jGeneratorTest extends AbstractModelloJavaGeneratorTest {
49+
@Inject
50+
private ModelloCore modello;
51+
4252
public Dom4jGeneratorTest() {
4353
super("dom4j");
4454
}
4555

56+
@Test
4657
public void testDom4jGenerator() throws Throwable {
47-
ModelloCore modello = (ModelloCore) lookup(ModelloCore.ROLE);
48-
4958
Model model = modello.loadModel(getXmlResourceReader("/maven.mdo"));
5059

5160
List<ModelClass> classesList = model.getClasses(new Version("4.0.0"));

0 commit comments

Comments
 (0)