Skip to content

Commit

Permalink
Convert to JUnit 5 with OpenRewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Dec 15, 2024
1 parent ca1e59b commit 1d4f135
Show file tree
Hide file tree
Showing 50 changed files with 1,310 additions and 1,454 deletions.
23 changes: 6 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,26 @@ limitations under the License.
</distributionManagement>

<properties>
<jmhVersion>1.36</jmhVersion>
<project.build.outputTimestamp>2023-03-02T01:23:19Z</project.build.outputTimestamp>
</properties>

<dependencies>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.36</version>
<version>${jmhVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.36</version>
<version>${jmhVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -97,8 +97,7 @@ limitations under the License.
<goal>compile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
<release>8</release>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -131,16 +130,6 @@ limitations under the License.
<exclude>org/codehaus/plexus/util/FileBasedTestCase.java</exclude>
<exclude>**/Test*.java</exclude>
</excludes>
<systemProperties>
<property>
<name>JAVA_HOME</name>
<value>${JAVA_HOME}</value>
</property>
<property>
<name>M2_HOME</name>
<value>${M2_HOME}</value>
</property>
</systemProperties>
</configuration>
</plugin>
<plugin>
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import java.util.Map;
import java.util.Properties;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

/**
* <p>CollectionUtilsTest class.</p>
Expand All @@ -35,12 +35,12 @@
* @version $Id: $Id
* @since 3.4.0
*/
public class CollectionUtilsTest {
class CollectionUtilsTest {
/**
* <p>testMergeMaps.</p>
*/
@Test
public void testMergeMaps() {
void mergeMaps() {
Map<String, String> dominantMap = new HashMap<String, String>();
dominantMap.put("a", "a");
dominantMap.put("b", "b");
Expand Down Expand Up @@ -79,7 +79,7 @@ public void testMergeMaps() {
*/
@SuppressWarnings("unchecked")
@Test
public void testMergeMapArray() {
void mergeMapArray() {
// Test empty array of Maps
Map<String, String> result0 = CollectionUtils.mergeMaps(new Map[] {});

Expand Down Expand Up @@ -133,7 +133,7 @@ public void testMergeMapArray() {
* <p>testMavenPropertiesLoading.</p>
*/
@Test
public void testMavenPropertiesLoading() {
void mavenPropertiesLoading() {
// Mimic MavenSession properties loading. Properties listed
// in dominant order.
Properties systemProperties = new Properties();
Expand Down Expand Up @@ -193,7 +193,7 @@ public void testMavenPropertiesLoading() {
* <p>testIteratorToListWithAPopulatedList.</p>
*/
@Test
public void testIteratorToListWithAPopulatedList() {
void iteratorToListWithAPopulatedList() {
List<String> original = new ArrayList<String>();

original.add("en");
Expand All @@ -215,7 +215,7 @@ public void testIteratorToListWithAPopulatedList() {
* <p>testIteratorToListWithAEmptyList.</p>
*/
@Test
public void testIteratorToListWithAEmptyList() {
void iteratorToListWithAEmptyList() {
List<String> original = new ArrayList<String>();

List<String> copy = CollectionUtils.iteratorToList(original.iterator());
Expand Down
85 changes: 42 additions & 43 deletions src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@
import java.util.List;
import java.util.Set;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

/**
* Base class for testcases doing tests with files.
Expand All @@ -48,16 +47,17 @@
* @since 3.4.0
*/
public class DirectoryScannerTest extends FileBasedTestCase {
@Rule
public TestName name = new TestName();

private static String testDir = getTestDirectory().getPath();
public String name;

private static final String testDir = getTestDirectory().getPath();

/**
* <p>setUp.</p>
*/
@Before
public void setUp() {
@BeforeEach
void setUp(TestInfo testInfo) {
testInfo.getTestMethod().ifPresent(method -> this.name = method.getName());
try {
FileUtils.deleteDirectory(testDir);
} catch (IOException e) {
Expand All @@ -72,7 +72,7 @@ public void setUp() {
* @throws java.net.URISyntaxException if any.
*/
@Test
public void testCrossPlatformIncludesString() throws IOException, URISyntaxException {
void crossPlatformIncludesString() throws IOException, URISyntaxException {
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(new File(getTestResourcesDir() + File.separator + "directory-scanner").getCanonicalFile());

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

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

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

assertEquals("Wrong number of results.", 3, fileNames.size());
assertTrue("3 not found.", fileNames.contains(new File("scanner3.dat")));
assertTrue("4 not found.", fileNames.contains(new File("scanner4.dat")));
assertTrue("5 not found.", fileNames.contains(new File("scanner5.dat")));
assertEquals(3, fileNames.size(), "Wrong number of results.");
assertTrue(fileNames.contains(new File("scanner3.dat")), "3 not found.");
assertTrue(fileNames.contains(new File("scanner4.dat")), "4 not found.");
assertTrue(fileNames.contains(new File("scanner5.dat")), "5 not found.");
}

/**
Expand All @@ -199,7 +198,7 @@ public void testGeneral() throws IOException {
* @throws java.io.IOException if any.
*/
@Test
public void testIncludesExcludesWithWhiteSpaces() throws IOException {
void includesExcludesWithWhiteSpaces() throws IOException {
this.createTestFiles();

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

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

assertEquals("Wrong number of results.", 3, fileNames.size());
assertTrue("3 not found.", fileNames.contains(new File("scanner3.dat")));
assertTrue("4 not found.", fileNames.contains(new File("scanner4.dat")));
assertTrue("5 not found.", fileNames.contains(new File("scanner5.dat")));
assertEquals(3, fileNames.size(), "Wrong number of results.");
assertTrue(fileNames.contains(new File("scanner3.dat")), "3 not found.");
assertTrue(fileNames.contains(new File("scanner4.dat")), "4 not found.");
assertTrue(fileNames.contains(new File("scanner5.dat")), "5 not found.");
}

/**
* <p>testFollowSymlinksFalse.</p>
*/
@Test
public void testFollowSymlinksFalse() {
void followSymlinksFalse() {
assumeTrue(checkTestFilesSymlinks());

DirectoryScanner ds = new DirectoryScanner();
Expand Down Expand Up @@ -253,7 +252,7 @@ private void assertAlwaysIncluded(List<String> included) {
* <p>testFollowSymlinks.</p>
*/
@Test
public void testFollowSymlinks() {
void followSymlinks() {
assumeTrue(checkTestFilesSymlinks());

DirectoryScanner ds = new DirectoryScanner();
Expand Down Expand Up @@ -300,7 +299,7 @@ private void createTestDirectories() throws IOException {
* @throws java.io.IOException if any.
*/
@Test
public void testDirectoriesWithHyphens() throws IOException {
void directoriesWithHyphens() throws IOException {
this.createTestDirectories();

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

String[] files = ds.getIncludedFiles();
assertEquals("Wrong number of results.", 3, files.length);
assertEquals(3, files.length, "Wrong number of results.");
}

/**
Expand All @@ -322,7 +321,7 @@ public void testDirectoriesWithHyphens() throws IOException {
* @throws java.io.IOException if any.
*/
@Test
public void testAntExcludesOverrideIncludes() throws IOException {
void antExcludesOverrideIncludes() throws IOException {
printTestHeader();

File dir = new File(testDir, "regex-dir");
Expand Down Expand Up @@ -360,7 +359,7 @@ public void testAntExcludesOverrideIncludes() throws IOException {
* @throws java.io.IOException if any.
*/
@Test
public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException {
void antExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException {
printTestHeader();

File dir = new File(testDir, "regex-dir");
Expand Down Expand Up @@ -399,7 +398,7 @@ public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOExce
* @throws java.io.IOException if any.
*/
@Test
public void testRegexIncludeWithExcludedPrefixDirs() throws IOException {
void regexIncludeWithExcludedPrefixDirs() throws IOException {
printTestHeader();

File dir = new File(testDir, "regex-dir");
Expand Down Expand Up @@ -433,7 +432,7 @@ public void testRegexIncludeWithExcludedPrefixDirs() throws IOException {
* @throws java.io.IOException if any.
*/
@Test
public void testRegexExcludeWithNegativeLookahead() throws IOException {
void regexExcludeWithNegativeLookahead() throws IOException {
printTestHeader();

File dir = new File(testDir, "regex-dir");
Expand Down Expand Up @@ -472,7 +471,7 @@ public void testRegexExcludeWithNegativeLookahead() throws IOException {
* @throws java.io.IOException if any.
*/
@Test
public void testRegexWithSlashInsideCharacterClass() throws IOException {
void regexWithSlashInsideCharacterClass() throws IOException {
printTestHeader();

File dir = new File(testDir, "regex-dir");
Expand Down Expand Up @@ -513,7 +512,7 @@ public void testRegexWithSlashInsideCharacterClass() throws IOException {
* @throws java.io.IOException if occurs an I/O error.
*/
@Test
public void testDoNotScanUnnecesaryDirectories() throws IOException {
void doNotScanUnnecesaryDirectories() throws IOException {
createTestDirectories();

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

final File directory = new File("src/test/resources/symlinks/src");
Expand All @@ -599,7 +598,7 @@ public void testIsSymbolicLink() throws IOException {
* @throws java.io.IOException if any.
*/
@Test
public void testIsParentSymbolicLink() throws IOException {
void isParentSymbolicLink() throws IOException {
assumeTrue(checkTestFilesSymlinks());

final File directory = new File("src/test/resources/symlinks/src");
Expand Down
Loading

0 comments on commit 1d4f135

Please sign in to comment.