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 b4ee91f

Browse filesBrowse files
authored
Switch to junit 5 (#245)
1 parent 60b1b79 commit b4ee91f
Copy full SHA for b4ee91f
Expand file treeCollapse file tree

34 files changed

+428
-522
lines changed

‎pom.xml

Copy file name to clipboardExpand all lines: pom.xml
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ limitations under the License.
6262
<optional>true</optional>
6363
</dependency>
6464
<dependency>
65-
<groupId>junit</groupId>
66-
<artifactId>junit</artifactId>
67-
<version>4.13.2</version>
65+
<groupId>org.junit.jupiter</groupId>
66+
<artifactId>junit-jupiter</artifactId>
67+
<version>5.9.2</version>
6868
<scope>test</scope>
6969
</dependency>
7070
</dependencies>

‎src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
* limitations under the License.
1717
*/
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertNull;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import static org.junit.jupiter.api.Assertions.assertNull;
2222

2323
import java.util.ArrayList;
2424
import java.util.HashMap;
2525
import java.util.List;
2626
import java.util.Map;
2727
import java.util.Properties;
2828

29-
import org.junit.Test;
29+
import org.junit.jupiter.api.Test;
3030

3131
/**
3232
* <p>CollectionUtilsTest class.</p>
@@ -135,7 +135,7 @@ public void testMergeMapArray()
135135
/**
136136
* <p>testMavenPropertiesLoading.</p>
137137
*/
138-
@Test
138+
@org.junit.jupiter.api.Test
139139
public void testMavenPropertiesLoading()
140140
{
141141
// Mimic MavenSession properties loading. Properties listed
@@ -195,7 +195,7 @@ public void testMavenPropertiesLoading()
195195
/**
196196
* <p>testIteratorToListWithAPopulatedList.</p>
197197
*/
198-
@Test
198+
@org.junit.jupiter.api.Test
199199
public void testIteratorToListWithAPopulatedList()
200200
{
201201
List<String> original = new ArrayList<String>();
@@ -218,7 +218,7 @@ public void testIteratorToListWithAPopulatedList()
218218
/**
219219
* <p>testIteratorToListWithAEmptyList.</p>
220220
*/
221-
@Test
221+
@org.junit.jupiter.api.Test
222222
public void testIteratorToListWithAEmptyList()
223223
{
224224
List<String> original = new ArrayList<String>();

‎src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java
+21-27Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
* limitations under the License.
1717
*/
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertFalse;
21-
import static org.junit.Assert.assertTrue;
22-
import static org.junit.Assert.fail;
23-
import static org.junit.Assume.assumeTrue;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
import static org.junit.jupiter.api.Assertions.fail;
23+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2424

2525
import java.io.File;
2626
import java.io.IOException;
@@ -35,10 +35,8 @@
3535
import java.util.List;
3636
import java.util.Set;
3737

38-
import org.junit.Before;
39-
import org.junit.Rule;
40-
import org.junit.Test;
41-
import org.junit.rules.TestName;
38+
import org.junit.jupiter.api.BeforeEach;
39+
import org.junit.jupiter.api.Test;
4240

4341
/**
4442
* Base class for testcases doing tests with files.
@@ -50,15 +48,12 @@
5048
public class DirectoryScannerTest
5149
extends FileBasedTestCase
5250
{
53-
@Rule
54-
public TestName name = new TestName();
55-
5651
private static String testDir = getTestDirectory().getPath();
5752

5853
/**
5954
* <p>setUp.</p>
6055
*/
61-
@Before
56+
@BeforeEach
6257
public void setUp()
6358
{
6459
try
@@ -190,7 +185,7 @@ private boolean checkTestFilesSymlinks()
190185
catch ( IOException e )
191186
{
192187
System.err.println( String.format( "The unit test '%s.%s' will be skipped, reason: %s",
193-
this.getClass().getSimpleName(), name.getMethodName(),
188+
this.getClass().getSimpleName(), getTestMethodName(),
194189
e.getMessage() ) );
195190
System.out.println( String.format( "This test requires symlinks files in '%s' directory.",
196191
symlinksDirectory.getPath() ) );
@@ -217,11 +212,10 @@ public void testGeneral()
217212

218213
List<File> fileNames = FileUtils.getFiles( new File( testDir ), includes, excludes, false );
219214

220-
assertEquals( "Wrong number of results.", 3, fileNames.size() );
221-
assertTrue( "3 not found.", fileNames.contains( new File( "scanner3.dat" ) ) );
222-
assertTrue( "4 not found.", fileNames.contains( new File( "scanner4.dat" ) ) );
223-
assertTrue( "5 not found.", fileNames.contains( new File( "scanner5.dat" ) ) );
224-
215+
assertEquals( 3, fileNames.size(), "Wrong number of results." );
216+
assertTrue( fileNames.contains( new File( "scanner3.dat" ) ), "3 not found." );
217+
assertTrue( fileNames.contains( new File( "scanner4.dat" ) ), "4 not found." );
218+
assertTrue( fileNames.contains( new File( "scanner5.dat" ) ), "5 not found." );
225219
}
226220

227221
/**
@@ -241,10 +235,10 @@ public void testIncludesExcludesWithWhiteSpaces()
241235

242236
List<File> fileNames = FileUtils.getFiles( new File( testDir ), includes, excludes, false );
243237

244-
assertEquals( "Wrong number of results.", 3, fileNames.size() );
245-
assertTrue( "3 not found.", fileNames.contains( new File( "scanner3.dat" ) ) );
246-
assertTrue( "4 not found.", fileNames.contains( new File( "scanner4.dat" ) ) );
247-
assertTrue( "5 not found.", fileNames.contains( new File( "scanner5.dat" ) ) );
238+
assertEquals( 3, fileNames.size(), "Wrong number of results." );
239+
assertTrue( fileNames.contains( new File( "scanner3.dat" ) ), "3 not found." );
240+
assertTrue( fileNames.contains( new File( "scanner4.dat" ) ), "4 not found." );
241+
assertTrue( fileNames.contains( new File( "scanner5.dat" ) ), "5 not found." );
248242
}
249243

250244
/**
@@ -347,7 +341,7 @@ public void testDirectoriesWithHyphens()
347341
ds.scan();
348342

349343
String[] files = ds.getIncludedFiles();
350-
assertEquals( "Wrong number of results.", 3, files.length );
344+
assertEquals( 3, files.length, "Wrong number of results." );
351345
}
352346

353347
/**
@@ -395,7 +389,7 @@ public void testAntExcludesOverrideIncludes()
395389
*
396390
* @throws java.io.IOException if any.
397391
*/
398-
@Test
392+
@org.junit.jupiter.api.Test
399393
public void testAntExcludesOverrideIncludesWithExplicitAntPrefix()
400394
throws IOException
401395
{
@@ -436,7 +430,7 @@ public void testAntExcludesOverrideIncludesWithExplicitAntPrefix()
436430
*
437431
* @throws java.io.IOException if any.
438432
*/
439-
@Test
433+
@org.junit.jupiter.api.Test
440434
public void testRegexIncludeWithExcludedPrefixDirs()
441435
throws IOException
442436
{
@@ -472,7 +466,7 @@ public void testRegexIncludeWithExcludedPrefixDirs()
472466
*
473467
* @throws java.io.IOException if any.
474468
*/
475-
@Test
469+
@org.junit.jupiter.api.Test
476470
public void testRegexExcludeWithNegativeLookahead()
477471
throws IOException
478472
{

‎src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
* limitations under the License.
1717
*/
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertTrue;
19+
import org.junit.jupiter.api.Test;
2220

23-
import java.io.File;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2424

25-
import org.junit.Test;
25+
import java.io.File;
2626

2727
/**
2828
* <p>DirectoryWalkerTest class.</p>
@@ -50,11 +50,11 @@ public void testDirectoryWalk()
5050

5151
walker.scan();
5252

53-
assertEquals( "Walk Collector / Starting Count", 1, collector.startCount );
54-
assertNotNull( "Walk Collector / Starting Dir", collector.startingDir );
55-
assertEquals( "Walk Collector / Finish Count", 1, collector.finishCount );
56-
assertEquals( "Walk Collector / Steps Count", 4, collector.steps.size() );
57-
assertTrue( "Walk Collector / percentage low >= 0", collector.percentageLow >= 0 );
58-
assertTrue( "Walk Collector / percentage high <= 100", collector.percentageHigh <= 100 );
53+
assertEquals( 1, collector.startCount, "Walk Collector / Starting Count" );
54+
assertNotNull( collector.startingDir, "Walk Collector / Starting Dir" );
55+
assertEquals( 1, collector.finishCount, "Walk Collector / Finish Count" );
56+
assertEquals( 4, collector.steps.size(), "Walk Collector / Steps Count" );
57+
assertTrue( collector.percentageLow >= 0, "Walk Collector / percentage low >= 0" );
58+
assertTrue( collector.percentageHigh <= 100, "Walk Collector / percentage high <= 100" );
5959
}
6060
}

‎src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java
+34-56Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
* limitations under the License.
1717
*/
1818

19-
import static org.junit.Assert.assertTrue;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.TestInfo;
21+
22+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
import static org.junit.jupiter.api.Assertions.fail;
2026

2127
import java.io.BufferedOutputStream;
2228
import java.io.ByteArrayOutputStream;
@@ -27,11 +33,10 @@
2733
import java.io.PrintStream;
2834
import java.io.PrintWriter;
2935
import java.io.Writer;
36+
import java.lang.reflect.Method;
3037
import java.nio.file.Files;
3138
import java.util.Arrays;
3239

33-
import junit.framework.AssertionFailedError;
34-
3540
/**
3641
* Base class for testcases doing tests with files.
3742
*
@@ -43,6 +48,8 @@ public abstract class FileBasedTestCase
4348
{
4449
private static File testDir;
4550

51+
private TestInfo testInfo;
52+
4653
/**
4754
* <p>getTestDirectory.</p>
4855
*
@@ -186,7 +193,7 @@ protected File newFile( String filename )
186193
protected void checkFile( final File file, final File referenceFile )
187194
throws Exception
188195
{
189-
assertTrue( "Check existence of output file", file.exists() );
196+
assertTrue( file.exists(), "Check existence of output file" );
190197
assertEqualContent( referenceFile, file );
191198
}
192199

@@ -205,7 +212,7 @@ protected void checkWrite( final OutputStream output )
205212
}
206213
catch ( final Throwable t )
207214
{
208-
throw new AssertionFailedError( "The copy() method closed the stream " + "when it shouldn't have. "
215+
fail( "The copy() method closed the stream " + "when it shouldn't have. "
209216
+ t.getMessage() );
210217
}
211218
}
@@ -225,7 +232,7 @@ protected void checkWrite( final Writer output )
225232
}
226233
catch ( final Throwable t )
227234
{
228-
throw new AssertionFailedError( "The copy() method closed the stream " + "when it shouldn't have. "
235+
fail( "The copy() method closed the stream " + "when it shouldn't have. "
229236
+ t.getMessage() );
230237
}
231238
}
@@ -241,7 +248,7 @@ protected void deleteFile( final File file )
241248
{
242249
if ( file.exists() )
243250
{
244-
assertTrue( "Couldn't delete file: " + file, file.delete() );
251+
assertTrue( file.delete(), "Couldn't delete file: " + file );
245252
}
246253
}
247254

@@ -258,37 +265,10 @@ private void assertEqualContent( final File f0, final File f1 )
258265
* + " and " + f1 + " have differing file sizes (" + f0.length() + " vs " + f1.length() + ")", ( f0.length() ==
259266
* f1.length() ) );
260267
*/
261-
final InputStream is0 = Files.newInputStream( f0.toPath() );
262-
try
263-
{
264-
final InputStream is1 = Files.newInputStream( f1.toPath() );
265-
try
266-
{
267-
final byte[] buf0 = new byte[1024];
268-
final byte[] buf1 = new byte[1024];
269-
int n0 = 0;
270-
int n1 = 0;
271-
272-
while ( -1 != n0 )
273-
{
274-
n0 = is0.read( buf0 );
275-
n1 = is1.read( buf1 );
276-
assertTrue( "The files " + f0 + " and " + f1 + " have differing number of bytes available (" + n0
277-
+ " vs " + n1 + ")", ( n0 == n1 ) );
278-
279-
assertTrue( "The files " + f0 + " and " + f1 + " have different content",
280-
Arrays.equals( buf0, buf1 ) );
281-
}
282-
}
283-
finally
284-
{
285-
is1.close();
286-
}
287-
}
288-
finally
289-
{
290-
is0.close();
291-
}
268+
byte[] buf0 = Files.readAllBytes( f0.toPath() );
269+
byte[] buf1 = Files.readAllBytes( f0.toPath() );
270+
assertArrayEquals( buf0, buf1,
271+
"The files " + f0 + " and " + f1 + " have different content" );
292272
}
293273

294274
/**
@@ -301,20 +281,8 @@ private void assertEqualContent( final File f0, final File f1 )
301281
protected void assertEqualContent( final byte[] b0, final File file )
302282
throws IOException
303283
{
304-
final InputStream is = Files.newInputStream( file.toPath() );
305-
try
306-
{
307-
byte[] b1 = new byte[b0.length];
308-
int numRead = is.read( b1 );
309-
assertTrue( "Different number of bytes", numRead == b0.length && is.available() == 0 );
310-
for ( int i = 0; i < numRead; assertTrue( "Byte " + i + " differs (" + b0[i] + " != " + b1[i] + ")",
311-
b0[i] == b1[i] ), i++ )
312-
;
313-
}
314-
finally
315-
{
316-
is.close();
317-
}
284+
byte[] b1 = Files.readAllBytes( file.toPath() );
285+
assertArrayEquals(b0, b1, "Content differs");
318286
}
319287

320288
/**
@@ -324,9 +292,9 @@ protected void assertEqualContent( final byte[] b0, final File file )
324292
*/
325293
protected void assertIsDirectory( File file )
326294
{
327-
assertTrue( "The File doesn't exists: " + file.getAbsolutePath(), file.exists() );
295+
assertTrue( file.exists(), "The File doesn't exists: " + file.getAbsolutePath() );
328296

329-
assertTrue( "The File isn't a directory: " + file.getAbsolutePath(), file.isDirectory() );
297+
assertTrue( file.isDirectory(), "The File isn't a directory: " + file.getAbsolutePath() );
330298
}
331299

332300
/**
@@ -336,8 +304,18 @@ protected void assertIsDirectory( File file )
336304
*/
337305
protected void assertIsFile( File file )
338306
{
339-
assertTrue( "The File doesn't exists: " + file.getAbsolutePath(), file.exists() );
307+
assertTrue( file.exists(), "The File doesn't exists: " + file.getAbsolutePath() );
308+
309+
assertTrue( file.isFile(), "The File isn't a file: " + file.getAbsolutePath() );
310+
}
340311

341-
assertTrue( "The File isn't a file: " + file.getAbsolutePath(), file.isFile() );
312+
@BeforeEach
313+
void init(TestInfo testInfo) {
314+
this.testInfo = testInfo;
342315
}
316+
317+
protected String getTestMethodName() {
318+
return testInfo.getTestMethod().map(Method::getName).orElse(null);
319+
}
320+
343321
}

0 commit comments

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