Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fba7d56

Browse filesBrowse files
committed
Switch to JUnit5
1 parent 671ba68 commit fba7d56
Copy full SHA for fba7d56

File tree

Expand file treeCollapse file tree

18 files changed

+217
-140
lines changed
Filter options
Expand file treeCollapse file tree

18 files changed

+217
-140
lines changed

‎.github/workflows/maven.yml

Copy file name to clipboardExpand all lines: .github/workflows/maven.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ jobs:
5151
java-version: ${{ matrix.java }}
5252

5353
- name: Build with Maven
54-
run: mvn install javadoc:javadoc -e -B -V -Pno-tests-if-not-on-osx
54+
run: mvn verify javadoc:javadoc -e -B -V -fae -Pno-tests-if-not-on-osx

‎plexus-compiler-api/pom.xml

Copy file name to clipboardExpand all lines: plexus-compiler-api/pom.xml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<artifactId>plexus-utils</artifactId>
2020
</dependency>
2121
<dependency>
22-
<groupId>junit</groupId>
23-
<artifactId>junit</artifactId>
22+
<groupId>org.junit.jupiter</groupId>
23+
<artifactId>junit-jupiter-api</artifactId>
2424
</dependency>
2525
</dependencies>
2626
</project>

‎plexus-compiler-its/pom.xml

Copy file name to clipboardExpand all lines: plexus-compiler-its/pom.xml
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<packaging>pom</packaging>
1313

1414
<name>Plexus Compiler It Tests</name>
15+
16+
<properties>
17+
<junit.version>4.13.2</junit.version>
18+
</properties>
1519

1620
<dependencies>
1721
<dependency>

‎plexus-compiler-test/pom.xml

Copy file name to clipboardExpand all lines: plexus-compiler-test/pom.xml
+13-3Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@
1818
<artifactId>plexus-compiler-api</artifactId>
1919
</dependency>
2020
<dependency>
21-
<groupId>junit</groupId>
22-
<artifactId>junit</artifactId>
23-
<scope>compile</scope>
21+
<groupId>org.junit.jupiter</groupId>
22+
<artifactId>junit-jupiter-api</artifactId>
23+
<scope>compile</scope> <!-- override default test scope -->
24+
</dependency>
25+
<dependency>
26+
<groupId>org.codehaus.plexus</groupId>
27+
<artifactId>plexus-testing</artifactId>
28+
<version>1.1.0</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.assertj</groupId>
32+
<artifactId>assertj-core</artifactId>
33+
<version>3.21.0</version>
2434
</dependency>
2535
<dependency>
2636
<groupId>org.apache.maven</groupId>

‎plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTckTest.java

Copy file name to clipboardExpand all lines: plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTckTest.java
+44-22Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,49 @@
2424
* SOFTWARE.
2525
*/
2626

27-
import org.codehaus.plexus.PlexusTestCase;
28-
import org.codehaus.plexus.util.FileUtils;
27+
import static org.assertj.core.api.Assertions.assertThat;
2928

3029
import java.io.File;
3130
import java.io.IOException;
31+
import java.lang.reflect.Method;
3232
import java.util.List;
33+
import java.util.Map;
34+
35+
import javax.inject.Inject;
36+
37+
import org.codehaus.plexus.testing.PlexusTest;
38+
import org.codehaus.plexus.util.FileUtils;
39+
import org.junit.jupiter.api.BeforeEach;
40+
import org.junit.jupiter.api.Test;
41+
import org.junit.jupiter.api.TestInfo;
3342

3443
/**
3544
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
3645
*/
46+
@PlexusTest
3747
public abstract class AbstractCompilerTckTest
38-
extends PlexusTestCase
3948
{
4049
private static final String EOL = System.lineSeparator();
4150

42-
private String roleHint;
51+
private final String roleHint;
52+
53+
private TestInfo testInfo;
54+
55+
@Inject
56+
private Map<String, Compiler> compilers;
4357

4458
protected AbstractCompilerTckTest( String roleHint )
4559
{
4660
this.roleHint = roleHint;
4761
}
62+
63+
@BeforeEach
64+
final void setup( TestInfo testInfo )
65+
{
66+
this.testInfo = testInfo;
67+
}
4868

69+
@Test
4970
public void testDeprecation()
5071
throws Exception
5172
{
@@ -69,19 +90,18 @@ public void testDeprecation()
6990
//
7091
// ----------------------------------------------------------------------
7192

72-
assertEquals( 1, result.size() );
93+
assertThat( result.size() ).isEqualTo( 1 );
7394

7495
CompilerMessage error = result.get( 0 );
7596

76-
System.out.println( error.getMessage() );
77-
78-
assertFalse( error.isError() );
97+
assertThat( error.isError() ).isFalse();
7998

80-
assertTrue( error.getMessage().contains( "Date" ) );
99+
assertThat( error.getMessage() ).contains( "Date" );
81100

82-
assertTrue( error.getMessage().contains( "deprecated" ) );
101+
assertThat( error.getMessage() ).contains( "deprecated" );
83102
}
84103

104+
@Test
85105
public void testWarning()
86106
throws Exception
87107
{
@@ -105,15 +125,15 @@ public void testWarning()
105125
//
106126
// ----------------------------------------------------------------------
107127

108-
assertEquals( 1, result.size() );
128+
assertThat( result.size() ).isEqualTo( 1 );
109129

110130
CompilerMessage error = result.get( 0 );
111131

112-
assertFalse( error.isError() );
132+
assertThat( error.isError() ).isFalse();
113133

114-
assertTrue( error.getMessage().contains( "finally block does not complete normally" ) );
134+
assertThat( error.getMessage() ).contains( "finally block does not complete normally" );
115135
}
116-
136+
117137
protected List<CompilerMessage> compile( CompilerConfiguration configuration )
118138
throws Exception
119139
{
@@ -134,23 +154,25 @@ protected List<CompilerMessage> compile( CompilerConfiguration configuration )
134154
// Compile!
135155
// ----------------------------------------------------------------------
136156

137-
Compiler compiler = (Compiler) lookup( Compiler.ROLE, roleHint );
157+
List<CompilerMessage> result = getCompiler().performCompile( configuration ).getCompilerMessages();
138158

139-
List<CompilerMessage> result = compiler.performCompile( configuration ).getCompilerMessages();
140-
141-
assertNotNull( result );
159+
assertThat( result ).isNotNull();
142160

143161
return result;
144162
}
145163

164+
private Compiler getCompiler() {
165+
return compilers.get( roleHint );
166+
}
167+
146168
private File getCompilerOutput()
147169
{
148-
return getTestFile( "target/compiler-output/" + getName() );
170+
return new File( "target/compiler-output/" + testInfo.getTestMethod().map( Method::getName ).orElseThrow( null ) );
149171
}
150172

151173
private File getSrc()
152174
{
153-
return getTestFile( "target/compiler-src/" + getName() );
175+
return new File( "target/compiler-src/" + testInfo.getTestMethod().map( Method::getName ).orElseThrow( null ) );
154176
}
155177

156178
protected void writeFileWithDeprecatedApi( File path, String className )
@@ -160,7 +182,7 @@ protected void writeFileWithDeprecatedApi( File path, String className )
160182

161183
if ( !parent.exists() )
162184
{
163-
assertTrue( parent.mkdirs() );
185+
assertThat( parent.mkdirs() ).isTrue();
164186
}
165187

166188
String source = "import java.util.Date;" + EOL +
@@ -186,7 +208,7 @@ protected void writeFileWithWarning( File path, String className )
186208

187209
if ( !parent.exists() )
188210
{
189-
assertTrue( parent.mkdirs() );
211+
assertThat( parent.mkdirs() ).isTrue();
190212
}
191213

192214
String source = "public class " + className + "" + EOL +

‎plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java

Copy file name to clipboardExpand all lines: plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java
+68-17Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,80 @@
2424
* SOFTWARE.
2525
*/
2626

27+
import static org.assertj.core.api.Assertions.assertThat;
28+
2729
import org.apache.maven.artifact.Artifact;
2830
import org.apache.maven.artifact.DefaultArtifact;
2931
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
30-
import org.apache.maven.artifact.test.ArtifactTestCase;
32+
import org.apache.maven.artifact.repository.ArtifactRepository;
33+
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
34+
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
3135
import org.apache.maven.artifact.versioning.VersionRange;
32-
36+
import org.apache.maven.settings.Settings;
37+
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
38+
import org.codehaus.plexus.testing.PlexusTest;
3339
import org.codehaus.plexus.util.FileUtils;
40+
import org.codehaus.plexus.util.ReaderFactory;
3441
import org.codehaus.plexus.util.StringUtils;
42+
import org.junit.jupiter.api.BeforeEach;
43+
import org.junit.jupiter.api.Test;
3544

3645
import java.io.File;
3746
import java.util.ArrayList;
3847
import java.util.Collection;
3948
import java.util.Collections;
4049
import java.util.Iterator;
4150
import java.util.List;
51+
import java.util.Map;
4252
import java.util.TreeSet;
4353

54+
import javax.inject.Inject;
55+
4456
/**
4557
*
4658
*/
59+
@PlexusTest
4760
public abstract class AbstractCompilerTest
48-
extends ArtifactTestCase
4961
{
5062
private boolean compilerDebug = false;
5163

5264
private boolean compilerDeprecationWarnings = false;
5365

5466
private boolean forceJavacCompilerUse = false;
55-
67+
68+
@Inject
69+
private Map<String, Compiler> compilers;
70+
71+
@Inject
72+
private ArtifactRepositoryLayout repositoryLayout;
73+
74+
private ArtifactRepository localRepository;
75+
5676
protected abstract String getRoleHint();
5777

78+
@BeforeEach
79+
final void setUpLocalRepo()
80+
throws Exception
81+
{
82+
String localRepo = System.getProperty( "maven.repo.local" );
83+
84+
if ( localRepo == null )
85+
{
86+
File settingsFile = new File( System.getProperty( "user.home" ), ".m2/settings.xml" );
87+
if ( settingsFile.exists() )
88+
{
89+
Settings settings = new SettingsXpp3Reader().read( ReaderFactory.newXmlReader( settingsFile ) );
90+
localRepo = settings.getLocalRepository();
91+
}
92+
}
93+
if ( localRepo == null )
94+
{
95+
localRepo = System.getProperty( "user.home" ) + "/.m2/repository";
96+
}
97+
98+
localRepository = new DefaultArtifactRepository( "local", "file://" + localRepo, repositoryLayout );
99+
}
100+
58101
protected void setCompilerDebug( boolean flag )
59102
{
60103
compilerDebug = flag;
@@ -69,6 +112,11 @@ public void setForceJavacCompilerUse( boolean forceJavacCompilerUse )
69112
{
70113
this.forceJavacCompilerUse = forceJavacCompilerUse;
71114
}
115+
116+
protected final Compiler getCompiler()
117+
{
118+
return compilers.get( getRoleHint() );
119+
}
72120

73121
protected List<String> getClasspath()
74122
throws Exception
@@ -77,8 +125,8 @@ protected List<String> getClasspath()
77125

78126
File file = getLocalArtifactPath( "commons-lang", "commons-lang", "2.0", "jar" );
79127

80-
assertTrue( "test prerequisite: commons-lang library must be available in local repository, expected "
81-
+ file.getAbsolutePath(), file.canRead() );
128+
assertThat( file.canRead() ).as( "test prerequisite: commons-lang library must be available in local repository, expected "
129+
+ file.getAbsolutePath() ).isTrue();
82130

83131
cp.add( file.getAbsolutePath() );
84132

@@ -90,6 +138,7 @@ protected void configureCompilerConfig( CompilerConfiguration compilerConfig )
90138

91139
}
92140

141+
@Test
93142
public void testCompilingSources()
94143
throws Exception
95144
{
@@ -100,9 +149,7 @@ public void testCompilingSources()
100149
{
101150
File outputDir = new File( compilerConfig.getOutputLocation() );
102151

103-
Compiler compiler = (Compiler) lookup( Compiler.ROLE, getRoleHint() );
104-
105-
messages.addAll( compiler.performCompile( compilerConfig ).getCompilerMessages() );
152+
messages.addAll( getCompiler().performCompile( compilerConfig ).getCompilerMessages() );
106153

107154
if ( outputDir.isDirectory() )
108155
{
@@ -134,8 +181,8 @@ public void testCompilingSources()
134181
errors.add( error.getMessage() );
135182
}
136183

137-
assertEquals( "Wrong number of compilation errors (" + numCompilerErrors + "/" + expectedErrors //
138-
+ ") : " + displayLines( errors ), expectedErrors, numCompilerErrors );
184+
assertThat( numCompilerErrors ).as( "Wrong number of compilation errors (" + numCompilerErrors + "/" + expectedErrors //
185+
+ ") : " + displayLines( errors ) ).isEqualTo( expectedErrors );
139186
}
140187

141188
int expectedWarnings = expectedWarnings();
@@ -157,12 +204,12 @@ public void testCompilingSources()
157204
warnings.add( error.getMessage() );
158205
}
159206

160-
assertEquals( "Wrong number (" + numCompilerWarnings + "/"
161-
+ expectedWarnings + ") of compilation warnings: " + displayLines( warnings ), //
162-
expectedWarnings, numCompilerWarnings);
207+
assertThat( numCompilerWarnings ).as( "Wrong number ("
208+
+ numCompilerWarnings + "/" + expectedWarnings + ") of compilation warnings: "
209+
+ displayLines( warnings ) ).isEqualTo( expectedWarnings );
163210
}
164211

165-
assertEquals( new TreeSet<>( normalizePaths( expectedOutputFiles() ) ), files );
212+
assertThat( files ).isEqualTo( new TreeSet<>( normalizePaths( expectedOutputFiles() ) ) );
166213
}
167214

168215
protected String displayLines( List<String> warnings)
@@ -179,7 +226,7 @@ protected String displayLines( List<String> warnings)
179226
private List<CompilerConfiguration> getCompilerConfigurations()
180227
throws Exception
181228
{
182-
String sourceDir = getBasedir() + "/src/test-input/src/main";
229+
String sourceDir = "src/test-input/src/main";
183230

184231
List<String> filenames =
185232
FileUtils.getFileNames( new File( sourceDir ), "**/*.java", null, false, true );
@@ -202,7 +249,7 @@ private List<CompilerConfiguration> getCompilerConfigurations()
202249

203250
compilerConfig.addSourceLocation( sourceDir );
204251

205-
compilerConfig.setOutputLocation( getBasedir() + "/target/" + getRoleHint() + "/classes-" + index );
252+
compilerConfig.setOutputLocation( "target/" + getRoleHint() + "/classes-" + index );
206253

207254
FileUtils.deleteDirectory( compilerConfig.getOutputLocation() );
208255

@@ -315,4 +362,8 @@ protected String getJavaVersion()
315362
return javaVersion;
316363
}
317364

365+
protected File getLocalArtifactPath( Artifact artifact )
366+
{
367+
return new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
368+
}
318369
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.