Skip to content

Commit

Permalink
Upgrade to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet authored and slachiewicz committed Nov 11, 2023
1 parent 9d52b5d commit ce021ec
Show file tree
Hide file tree
Showing 50 changed files with 1,300 additions and 1,301 deletions.
5 changes: 2 additions & 3 deletions pom.xml
Expand Up @@ -65,9 +65,8 @@ limitations under the License.
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java
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
81 changes: 43 additions & 38 deletions src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java
Expand Up @@ -18,6 +18,7 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
Expand All @@ -27,18 +28,18 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
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 +49,20 @@
* @since 3.4.0
*/
public class DirectoryScannerTest extends FileBasedTestCase {
@Rule
public TestName name = new TestName();

public String name;

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

/**
* <p>setUp.</p>
*/
@Before
public void setUp() {
@BeforeEach
void setUp(TestInfo testInfo) {
Optional<Method> testMethod = testInfo.getTestMethod();
if (testMethod.isPresent()) {
this.name = testMethod.get().getName();
}
try {
FileUtils.deleteDirectory(testDir);
} catch (IOException e) {
Expand All @@ -72,7 +77,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 +103,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 @@ -163,7 +168,7 @@ private boolean checkTestFilesSymlinks() {
} 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()));
this.getClass().getSimpleName(), name, e.getMessage()));
System.out.println(
String.format("This test requires symlinks files in '%s' directory.", symlinksDirectory.getPath()));
System.out.println("On some OS (like Windows 10), files are present only if the clone/checkout is done"
Expand All @@ -179,18 +184,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 +204,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 +213,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 +258,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 +305,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 +318,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 +327,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 +365,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 +404,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 +438,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 +477,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 +518,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 +587,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 +604,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
24 changes: 12 additions & 12 deletions src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java
Expand Up @@ -18,11 +18,11 @@

import java.io.File;

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.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* <p>DirectoryWalkerTest class.</p>
Expand All @@ -31,12 +31,12 @@
* @version $Id: $Id
* @since 3.4.0
*/
public class DirectoryWalkerTest {
class DirectoryWalkerTest {
/**
* <p>testDirectoryWalk.</p>
*/
@Test
public void testDirectoryWalk() {
void directoryWalk() {
DirectoryWalker walker = new DirectoryWalker();

walker.addSCMExcludes();
Expand All @@ -48,11 +48,11 @@ public void testDirectoryWalk() {

walker.scan();

assertEquals("Walk Collector / Starting Count", 1, collector.startCount);
assertNotNull("Walk Collector / Starting Dir", collector.startingDir);
assertEquals("Walk Collector / Finish Count", 1, collector.finishCount);
assertEquals("Walk Collector / Steps Count", 4, collector.steps.size());
assertTrue("Walk Collector / percentage low >= 0", collector.percentageLow >= 0);
assertTrue("Walk Collector / percentage high <= 100", collector.percentageHigh <= 100);
assertEquals(1, collector.startCount, "Walk Collector / Starting Count");
assertNotNull(collector.startingDir, "Walk Collector / Starting Dir");
assertEquals(1, collector.finishCount, "Walk Collector / Finish Count");
assertEquals(4, collector.steps.size(), "Walk Collector / Steps Count");
assertTrue(collector.percentageLow >= 0, "Walk Collector / percentage low >= 0");
assertTrue(collector.percentageHigh <= 100, "Walk Collector / percentage high <= 100");
}
}

0 comments on commit ce021ec

Please sign in to comment.