Skip to content

Commit a085081

Browse files
committed
Convert to JUnit 5 with OpenRewrite
1 parent ca1e59b commit a085081

File tree

50 files changed

+1310
-1454
lines changed

Some content is hidden

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

50 files changed

+1310
-1454
lines changed

pom.xml

+6-17
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,26 @@ limitations under the License.
4848
</distributionManagement>
4949

5050
<properties>
51+
<jmhVersion>1.36</jmhVersion>
5152
<project.build.outputTimestamp>2023-03-02T01:23:19Z</project.build.outputTimestamp>
5253
</properties>
5354

5455
<dependencies>
5556
<dependency>
5657
<groupId>org.openjdk.jmh</groupId>
5758
<artifactId>jmh-core</artifactId>
58-
<version>1.36</version>
59+
<version>${jmhVersion}</version>
5960
<scope>test</scope>
6061
</dependency>
6162
<dependency>
6263
<groupId>org.openjdk.jmh</groupId>
6364
<artifactId>jmh-generator-annprocess</artifactId>
64-
<version>1.36</version>
65+
<version>${jmhVersion}</version>
6566
<scope>test</scope>
6667
</dependency>
6768
<dependency>
68-
<groupId>junit</groupId>
69-
<artifactId>junit</artifactId>
70-
<version>4.13.2</version>
69+
<groupId>org.junit.jupiter</groupId>
70+
<artifactId>junit-jupiter-api</artifactId>
7171
<scope>test</scope>
7272
</dependency>
7373
</dependencies>
@@ -97,8 +97,7 @@ limitations under the License.
9797
<goal>compile</goal>
9898
</goals>
9999
<configuration>
100-
<source>1.8</source>
101-
<target>1.8</target>
100+
<release>8</release>
102101
</configuration>
103102
</execution>
104103
</executions>
@@ -131,16 +130,6 @@ limitations under the License.
131130
<exclude>org/codehaus/plexus/util/FileBasedTestCase.java</exclude>
132131
<exclude>**/Test*.java</exclude>
133132
</excludes>
134-
<systemProperties>
135-
<property>
136-
<name>JAVA_HOME</name>
137-
<value>${JAVA_HOME}</value>
138-
</property>
139-
<property>
140-
<name>M2_HOME</name>
141-
<value>${M2_HOME}</value>
142-
</property>
143-
</systemProperties>
144133
</configuration>
145134
</plugin>
146135
<plugin>

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
import java.util.Map;
2323
import java.util.Properties;
2424

25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

27-
import static org.junit.Assert.assertEquals;
28-
import static org.junit.Assert.assertNotNull;
29-
import static org.junit.Assert.assertNull;
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.assertNotNull;
29+
import static org.junit.jupiter.api.Assertions.assertNull;
3030

3131
/**
3232
* <p>CollectionUtilsTest class.</p>
@@ -35,12 +35,12 @@
3535
* @version $Id: $Id
3636
* @since 3.4.0
3737
*/
38-
public class CollectionUtilsTest {
38+
class CollectionUtilsTest {
3939
/**
4040
* <p>testMergeMaps.</p>
4141
*/
4242
@Test
43-
public void testMergeMaps() {
43+
void mergeMaps() {
4444
Map<String, String> dominantMap = new HashMap<String, String>();
4545
dominantMap.put("a", "a");
4646
dominantMap.put("b", "b");
@@ -79,7 +79,7 @@ public void testMergeMaps() {
7979
*/
8080
@SuppressWarnings("unchecked")
8181
@Test
82-
public void testMergeMapArray() {
82+
void mergeMapArray() {
8383
// Test empty array of Maps
8484
Map<String, String> result0 = CollectionUtils.mergeMaps(new Map[] {});
8585

@@ -133,7 +133,7 @@ public void testMergeMapArray() {
133133
* <p>testMavenPropertiesLoading.</p>
134134
*/
135135
@Test
136-
public void testMavenPropertiesLoading() {
136+
void mavenPropertiesLoading() {
137137
// Mimic MavenSession properties loading. Properties listed
138138
// in dominant order.
139139
Properties systemProperties = new Properties();
@@ -193,7 +193,7 @@ public void testMavenPropertiesLoading() {
193193
* <p>testIteratorToListWithAPopulatedList.</p>
194194
*/
195195
@Test
196-
public void testIteratorToListWithAPopulatedList() {
196+
void iteratorToListWithAPopulatedList() {
197197
List<String> original = new ArrayList<String>();
198198

199199
original.add("en");
@@ -215,7 +215,7 @@ public void testIteratorToListWithAPopulatedList() {
215215
* <p>testIteratorToListWithAEmptyList.</p>
216216
*/
217217
@Test
218-
public void testIteratorToListWithAEmptyList() {
218+
void iteratorToListWithAEmptyList() {
219219
List<String> original = new ArrayList<String>();
220220

221221
List<String> copy = CollectionUtils.iteratorToList(original.iterator());

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

+42-43
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@
2929
import java.util.List;
3030
import java.util.Set;
3131

32-
import org.junit.Before;
33-
import org.junit.Rule;
34-
import org.junit.Test;
35-
import org.junit.rules.TestName;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.TestInfo;
3635

37-
import static org.junit.Assert.assertEquals;
38-
import static org.junit.Assert.assertFalse;
39-
import static org.junit.Assert.assertTrue;
40-
import static org.junit.Assert.fail;
41-
import static org.junit.Assume.assumeTrue;
36+
import static org.junit.jupiter.api.Assertions.assertEquals;
37+
import static org.junit.jupiter.api.Assertions.assertFalse;
38+
import static org.junit.jupiter.api.Assertions.assertTrue;
39+
import static org.junit.jupiter.api.Assertions.fail;
40+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
4241

4342
/**
4443
* Base class for testcases doing tests with files.
@@ -48,16 +47,17 @@
4847
* @since 3.4.0
4948
*/
5049
public class DirectoryScannerTest extends FileBasedTestCase {
51-
@Rule
52-
public TestName name = new TestName();
5350

54-
private static String testDir = getTestDirectory().getPath();
51+
public String name;
52+
53+
private static final String testDir = getTestDirectory().getPath();
5554

5655
/**
5756
* <p>setUp.</p>
5857
*/
59-
@Before
60-
public void setUp() {
58+
@BeforeEach
59+
void setUp(TestInfo testInfo) {
60+
testInfo.getTestMethod().ifPresent(method -> this.name = method.getName());
6161
try {
6262
FileUtils.deleteDirectory(testDir);
6363
} catch (IOException e) {
@@ -72,7 +72,7 @@ public void setUp() {
7272
* @throws java.net.URISyntaxException if any.
7373
*/
7474
@Test
75-
public void testCrossPlatformIncludesString() throws IOException, URISyntaxException {
75+
void crossPlatformIncludesString() throws IOException, URISyntaxException {
7676
DirectoryScanner ds = new DirectoryScanner();
7777
ds.setBasedir(new File(getTestResourcesDir() + File.separator + "directory-scanner").getCanonicalFile());
7878

@@ -98,7 +98,7 @@ public void testCrossPlatformIncludesString() throws IOException, URISyntaxExcep
9898
* @throws java.net.URISyntaxException if any.
9999
*/
100100
@Test
101-
public void testCrossPlatformExcludesString() throws IOException, URISyntaxException {
101+
void crossPlatformExcludesString() throws IOException, URISyntaxException {
102102
DirectoryScanner ds = new DirectoryScanner();
103103
ds.setBasedir(new File(getTestResourcesDir() + File.separator + "directory-scanner").getCanonicalFile());
104104
ds.setIncludes(new String[] {"**"});
@@ -161,11 +161,10 @@ private boolean checkTestFilesSymlinks() {
161161
}
162162
return true;
163163
} catch (IOException e) {
164-
System.err.println(String.format(
165-
"The unit test '%s.%s' will be skipped, reason: %s",
166-
this.getClass().getSimpleName(), name.getMethodName(), e.getMessage()));
167-
System.out.println(
168-
String.format("This test requires symlinks files in '%s' directory.", symlinksDirectory.getPath()));
164+
System.err.printf(
165+
"The unit test '%s.%s' will be skipped, reason: %s%n",
166+
this.getClass().getSimpleName(), name, e.getMessage());
167+
System.out.printf("This test requires symlinks files in '%s' directory.%n", symlinksDirectory.getPath());
169168
System.out.println("On some OS (like Windows 10), files are present only if the clone/checkout is done"
170169
+ " in administrator mode, and correct (symlinks and not flat file/directory)"
171170
+ " if symlinks option are used (for git: git clone -c core.symlinks=true [url])");
@@ -179,18 +178,18 @@ private boolean checkTestFilesSymlinks() {
179178
* @throws java.io.IOException if any.
180179
*/
181180
@Test
182-
public void testGeneral() throws IOException {
181+
void general() throws IOException {
183182
this.createTestFiles();
184183

185184
String includes = "scanner1.dat,scanner2.dat,scanner3.dat,scanner4.dat,scanner5.dat";
186185
String excludes = "scanner1.dat,scanner2.dat";
187186

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

190-
assertEquals("Wrong number of results.", 3, fileNames.size());
191-
assertTrue("3 not found.", fileNames.contains(new File("scanner3.dat")));
192-
assertTrue("4 not found.", fileNames.contains(new File("scanner4.dat")));
193-
assertTrue("5 not found.", fileNames.contains(new File("scanner5.dat")));
189+
assertEquals(3, fileNames.size(), "Wrong number of results.");
190+
assertTrue(fileNames.contains(new File("scanner3.dat")), "3 not found.");
191+
assertTrue(fileNames.contains(new File("scanner4.dat")), "4 not found.");
192+
assertTrue(fileNames.contains(new File("scanner5.dat")), "5 not found.");
194193
}
195194

196195
/**
@@ -199,7 +198,7 @@ public void testGeneral() throws IOException {
199198
* @throws java.io.IOException if any.
200199
*/
201200
@Test
202-
public void testIncludesExcludesWithWhiteSpaces() throws IOException {
201+
void includesExcludesWithWhiteSpaces() throws IOException {
203202
this.createTestFiles();
204203

205204
String includes = "scanner1.dat,\n \n,scanner2.dat \n\r, scanner3.dat\n, \tscanner4.dat,scanner5.dat\n,";
@@ -208,17 +207,17 @@ public void testIncludesExcludesWithWhiteSpaces() throws IOException {
208207

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

211-
assertEquals("Wrong number of results.", 3, fileNames.size());
212-
assertTrue("3 not found.", fileNames.contains(new File("scanner3.dat")));
213-
assertTrue("4 not found.", fileNames.contains(new File("scanner4.dat")));
214-
assertTrue("5 not found.", fileNames.contains(new File("scanner5.dat")));
210+
assertEquals(3, fileNames.size(), "Wrong number of results.");
211+
assertTrue(fileNames.contains(new File("scanner3.dat")), "3 not found.");
212+
assertTrue(fileNames.contains(new File("scanner4.dat")), "4 not found.");
213+
assertTrue(fileNames.contains(new File("scanner5.dat")), "5 not found.");
215214
}
216215

217216
/**
218217
* <p>testFollowSymlinksFalse.</p>
219218
*/
220219
@Test
221-
public void testFollowSymlinksFalse() {
220+
void followSymlinksFalse() {
222221
assumeTrue(checkTestFilesSymlinks());
223222

224223
DirectoryScanner ds = new DirectoryScanner();
@@ -253,7 +252,7 @@ private void assertAlwaysIncluded(List<String> included) {
253252
* <p>testFollowSymlinks.</p>
254253
*/
255254
@Test
256-
public void testFollowSymlinks() {
255+
void followSymlinks() {
257256
assumeTrue(checkTestFilesSymlinks());
258257

259258
DirectoryScanner ds = new DirectoryScanner();
@@ -300,7 +299,7 @@ private void createTestDirectories() throws IOException {
300299
* @throws java.io.IOException if any.
301300
*/
302301
@Test
303-
public void testDirectoriesWithHyphens() throws IOException {
302+
void directoriesWithHyphens() throws IOException {
304303
this.createTestDirectories();
305304

306305
DirectoryScanner ds = new DirectoryScanner();
@@ -313,7 +312,7 @@ public void testDirectoriesWithHyphens() throws IOException {
313312
ds.scan();
314313

315314
String[] files = ds.getIncludedFiles();
316-
assertEquals("Wrong number of results.", 3, files.length);
315+
assertEquals(3, files.length, "Wrong number of results.");
317316
}
318317

319318
/**
@@ -322,7 +321,7 @@ public void testDirectoriesWithHyphens() throws IOException {
322321
* @throws java.io.IOException if any.
323322
*/
324323
@Test
325-
public void testAntExcludesOverrideIncludes() throws IOException {
324+
void antExcludesOverrideIncludes() throws IOException {
326325
printTestHeader();
327326

328327
File dir = new File(testDir, "regex-dir");
@@ -360,7 +359,7 @@ public void testAntExcludesOverrideIncludes() throws IOException {
360359
* @throws java.io.IOException if any.
361360
*/
362361
@Test
363-
public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException {
362+
void antExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException {
364363
printTestHeader();
365364

366365
File dir = new File(testDir, "regex-dir");
@@ -399,7 +398,7 @@ public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOExce
399398
* @throws java.io.IOException if any.
400399
*/
401400
@Test
402-
public void testRegexIncludeWithExcludedPrefixDirs() throws IOException {
401+
void regexIncludeWithExcludedPrefixDirs() throws IOException {
403402
printTestHeader();
404403

405404
File dir = new File(testDir, "regex-dir");
@@ -433,7 +432,7 @@ public void testRegexIncludeWithExcludedPrefixDirs() throws IOException {
433432
* @throws java.io.IOException if any.
434433
*/
435434
@Test
436-
public void testRegexExcludeWithNegativeLookahead() throws IOException {
435+
void regexExcludeWithNegativeLookahead() throws IOException {
437436
printTestHeader();
438437

439438
File dir = new File(testDir, "regex-dir");
@@ -472,7 +471,7 @@ public void testRegexExcludeWithNegativeLookahead() throws IOException {
472471
* @throws java.io.IOException if any.
473472
*/
474473
@Test
475-
public void testRegexWithSlashInsideCharacterClass() throws IOException {
474+
void regexWithSlashInsideCharacterClass() throws IOException {
476475
printTestHeader();
477476

478477
File dir = new File(testDir, "regex-dir");
@@ -513,7 +512,7 @@ public void testRegexWithSlashInsideCharacterClass() throws IOException {
513512
* @throws java.io.IOException if occurs an I/O error.
514513
*/
515514
@Test
516-
public void testDoNotScanUnnecesaryDirectories() throws IOException {
515+
void doNotScanUnnecesaryDirectories() throws IOException {
517516
createTestDirectories();
518517

519518
// create additional directories 'anotherDir1', 'anotherDir2' and 'anotherDir3' with a 'file1.dat' file
@@ -582,7 +581,7 @@ protected void scandir(File dir, String vpath, boolean fast) {
582581
* @throws java.io.IOException if any.
583582
*/
584583
@Test
585-
public void testIsSymbolicLink() throws IOException {
584+
void isSymbolicLink() throws IOException {
586585
assumeTrue(checkTestFilesSymlinks());
587586

588587
final File directory = new File("src/test/resources/symlinks/src");
@@ -599,7 +598,7 @@ public void testIsSymbolicLink() throws IOException {
599598
* @throws java.io.IOException if any.
600599
*/
601600
@Test
602-
public void testIsParentSymbolicLink() throws IOException {
601+
void isParentSymbolicLink() throws IOException {
603602
assumeTrue(checkTestFilesSymlinks());
604603

605604
final File directory = new File("src/test/resources/symlinks/src");

0 commit comments

Comments
 (0)