Skip to content

Cleanup tests #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,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
46 changes: 23 additions & 23 deletions src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@
* @version $Id: $Id
* @since 3.4.0
*/
public class CollectionUtilsTest {
class CollectionUtilsTest {
/**
* <p>testMergeMaps.</p>
*/
@Test
public void testMergeMaps() {
Map<String, String> dominantMap = new HashMap<String, String>();
void mergeMaps() {
Map<String, String> dominantMap = new HashMap<>();
dominantMap.put("a", "a");
dominantMap.put("b", "b");
dominantMap.put("c", "c");
dominantMap.put("d", "d");
dominantMap.put("e", "e");
dominantMap.put("f", "f");

Map<String, String> recessiveMap = new HashMap<String, String>();
Map<String, String> recessiveMap = new HashMap<>();
recessiveMap.put("a", "invalid");
recessiveMap.put("b", "invalid");
recessiveMap.put("c", "invalid");
Expand All @@ -60,7 +60,7 @@ public void testMergeMaps() {
Map<String, String> result = CollectionUtils.mergeMaps(dominantMap, recessiveMap);

// We should have 9 elements
assertEquals(9, result.keySet().size());
assertEquals(9, result.size());

// Check the elements.
assertEquals("a", result.get("a"));
Expand All @@ -79,22 +79,22 @@ public void testMergeMaps() {
*/
@SuppressWarnings("unchecked")
@Test
public void testMergeMapArray() {
void mergeMapArray() {
// Test empty array of Maps
Map<String, String> result0 = CollectionUtils.mergeMaps(new Map[] {});

assertNull(result0);

// Test with an array with a single element.
Map<String, String> map1 = new HashMap<String, String>();
Map<String, String> map1 = new HashMap<>();
map1.put("a", "a");

Map<String, String> result1 = CollectionUtils.mergeMaps(new Map[] {map1});

assertEquals("a", result1.get("a"));

// Test with an array with two elements.
Map<String, String> map2 = new HashMap<String, String>();
Map<String, String> map2 = new HashMap<>();
map2.put("a", "aa");
map2.put("b", "bb");

Expand All @@ -110,7 +110,7 @@ public void testMergeMapArray() {
assertEquals("bb", result3.get("b"));

// Test with an array with three elements.
Map<String, String> map3 = new HashMap<String, String>();
Map<String, String> map3 = new HashMap<>();
map3.put("a", "aaa");
map3.put("b", "bbb");
map3.put("c", "ccc");
Expand All @@ -132,8 +132,8 @@ public void testMergeMapArray() {
/**
* <p>testMavenPropertiesLoading.</p>
*/
@org.junit.jupiter.api.Test
public void testMavenPropertiesLoading() {
@Test
void mavenPropertiesLoading() {
// Mimic MavenSession properties loading. Properties listed
// in dominant order.
Properties systemProperties = new Properties();
Expand Down Expand Up @@ -175,26 +175,26 @@ public void testMavenPropertiesLoading() {
});

// Values that should be taken from systemProperties.
assertEquals("/projects/maven", (String) result.get("maven.home"));
assertEquals("/projects/maven", result.get("maven.home"));

// Values that should be taken from userBuildProperties.
assertEquals("/opt/maven/artifact", (String) result.get("maven.repo.local"));
assertEquals("false", (String) result.get("maven.repo.remote.enabled"));
assertEquals("jvanzyl", (String) result.get("maven.username"));
assertEquals("/opt/maven/artifact", result.get("maven.repo.local"));
assertEquals("false", result.get("maven.repo.remote.enabled"));
assertEquals("jvanzyl", result.get("maven.username"));

// Values take from projectBuildProperties.
assertEquals("maven", (String) result.get("maven.final.name"));
assertEquals("maven", result.get("maven.final.name"));

// Values take from projectProperties.
assertEquals(mavenRepoRemote, (String) result.get("maven.repo.remote"));
assertEquals(mavenRepoRemote, result.get("maven.repo.remote"));
}

/**
* <p>testIteratorToListWithAPopulatedList.</p>
*/
@org.junit.jupiter.api.Test
public void testIteratorToListWithAPopulatedList() {
List<String> original = new ArrayList<String>();
@Test
void iteratorToListWithAPopulatedList() {
List<String> original = new ArrayList<>();

original.add("en");
original.add("to");
Expand All @@ -214,9 +214,9 @@ public void testIteratorToListWithAPopulatedList() {
/**
* <p>testIteratorToListWithAEmptyList.</p>
*/
@org.junit.jupiter.api.Test
public void testIteratorToListWithAEmptyList() {
List<String> original = new ArrayList<String>();
@Test
void iteratorToListWithAEmptyList() {
List<String> original = new ArrayList<>();

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

Expand Down
63 changes: 31 additions & 32 deletions src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
* @version $Id: $Id
* @since 3.4.0
*/
public class DirectoryScannerTest extends FileBasedTestCase {
private static String testDir = getTestDirectory().getPath();
class DirectoryScannerTest extends FileBasedTestCase {
private static final String testDir = getTestDirectory().getPath();

/**
* <p>setUp.</p>
*/
@BeforeEach
public void setUp() {
void setUp() {
try {
FileUtils.deleteDirectory(testDir);
} catch (IOException e) {
Expand All @@ -67,7 +67,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 @@ -93,7 +93,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 @@ -156,11 +156,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(), getTestMethodName(), 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(), getTestMethodName(), 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 @@ -174,7 +173,7 @@ 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";
Expand All @@ -194,7 +193,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 @@ -213,7 +212,7 @@ public void testIncludesExcludesWithWhiteSpaces() throws IOException {
* <p>testFollowSymlinksFalse.</p>
*/
@Test
public void testFollowSymlinksFalse() {
void followSymlinksFalse() {
assumeTrue(checkTestFilesSymlinks());

DirectoryScanner ds = new DirectoryScanner();
Expand Down Expand Up @@ -248,7 +247,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 @@ -295,7 +294,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 @@ -317,7 +316,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 @@ -354,8 +353,8 @@ public void testAntExcludesOverrideIncludes() throws IOException {
*
* @throws java.io.IOException if any.
*/
@org.junit.jupiter.api.Test
public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException {
@Test
void antExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException {
printTestHeader();

File dir = new File(testDir, "regex-dir");
Expand Down Expand Up @@ -393,8 +392,8 @@ public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOExce
*
* @throws java.io.IOException if any.
*/
@org.junit.jupiter.api.Test
public void testRegexIncludeWithExcludedPrefixDirs() throws IOException {
@Test
void regexIncludeWithExcludedPrefixDirs() throws IOException {
printTestHeader();

File dir = new File(testDir, "regex-dir");
Expand Down Expand Up @@ -427,14 +426,14 @@ public void testRegexIncludeWithExcludedPrefixDirs() throws IOException {
*
* @throws java.io.IOException if any.
*/
@org.junit.jupiter.api.Test
public void testRegexExcludeWithNegativeLookahead() throws IOException {
@Test
void regexExcludeWithNegativeLookahead() throws IOException {
printTestHeader();

File dir = new File(testDir, "regex-dir");
try {
FileUtils.deleteDirectory(dir);
} catch (IOException e) {
} catch (IOException ignored) {
}

dir.mkdirs();
Expand Down Expand Up @@ -467,13 +466,13 @@ 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");
try {
FileUtils.deleteDirectory(dir);
} catch (IOException e) {
} catch (IOException ignored) {
}

dir.mkdirs();
Expand Down Expand Up @@ -508,7 +507,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 @@ -547,7 +546,7 @@ public void testDoNotScanUnnecesaryDirectories() throws IOException {
"directoryTest" + File.separator + "test-dir-123" + File.separator + "file1.dat"
};

final Set<String> scannedDirSet = new HashSet<String>();
final Set<String> scannedDirSet = new HashSet<>();

DirectoryScanner ds = new DirectoryScanner() {
@Override
Expand All @@ -566,7 +565,7 @@ protected void scandir(File dir, String vpath, boolean fast) {
assertInclusionsAndExclusions(ds.getIncludedFiles(), excludedPaths, includedPaths);

Set<String> expectedScannedDirSet =
new HashSet<String>(Arrays.asList("io", "directoryTest", "testDir123", "test_dir_123", "test-dir-123"));
new HashSet<>(Arrays.asList("io", "directoryTest", "testDir123", "test_dir_123", "test-dir-123"));

assertEquals(expectedScannedDirSet, scannedDirSet);
}
Expand All @@ -577,7 +576,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 @@ -594,7 +593,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 Expand Up @@ -622,7 +621,7 @@ private void assertInclusionsAndExclusions(String[] files, String[] excludedPath
System.out.println(file);
}

List<String> failedToExclude = new ArrayList<String>();
List<String> failedToExclude = new ArrayList<>();
for (String excludedPath : excludedPaths) {
String alt = excludedPath.replace('/', '\\');
System.out.println("Searching for exclusion as: " + excludedPath + "\nor: " + alt);
Expand All @@ -631,7 +630,7 @@ private void assertInclusionsAndExclusions(String[] files, String[] excludedPath
}
}

List<String> failedToInclude = new ArrayList<String>();
List<String> failedToInclude = new ArrayList<>();
for (String includedPath : includedPaths) {
String alt = includedPath.replace('/', '\\');
System.out.println("Searching for inclusion as: " + includedPath + "\nor: " + alt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down
Loading
Loading