diff --git a/pom.xml b/pom.xml
index ef4e14d..eb28168 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,6 +49,12 @@
plexus-utils
4.0.0
+
+ org.codehaus.plexus
+ plexus-xml
+ 3.0.0
+ test
+
com.google.code.findbugs
jsr305
@@ -63,21 +69,8 @@
- junit
- junit
- 4.13.2
- test
-
-
- org.hamcrest
- hamcrest-core
-
-
-
-
- org.hamcrest
- hamcrest
- 2.2
+ org.junit.jupiter
+ junit-jupiter
test
@@ -86,6 +79,12 @@
${slf4jVersion}
test
+
+ org.codehaus.plexus
+ plexus-testing
+ 1.1.0
+ test
+
org.eclipse.sisu
diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java b/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java
index b875595..50daec3 100644
--- a/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java
+++ b/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java
@@ -16,9 +16,9 @@
* limitations under the License.
*/
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public abstract class AbstractResourceAttributesTCK {
@@ -29,7 +29,7 @@ protected AbstractResourceAttributesTCK() {}
protected abstract PlexusIoResourceAttributes newAttributes(String mode);
@Test
- public final void testSetOctalModeString_OwnerModes() {
+ final void testSetOctalModeString_OwnerModes() {
verifyStringOctalModeSet("700", new boolean[] {true, true, true, false, false, false, false, false, false});
verifyStringOctalModeSet("600", new boolean[] {true, true, false, false, false, false, false, false, false});
verifyStringOctalModeSet("400", new boolean[] {true, false, false, false, false, false, false, false, false});
@@ -37,7 +37,7 @@ public final void testSetOctalModeString_OwnerModes() {
}
@Test
- public final void testSetOctalModeString_GroupModes() {
+ final void testSetOctalModeString_GroupModes() {
verifyStringOctalModeSet("070", new boolean[] {false, false, false, true, true, true, false, false, false});
verifyStringOctalModeSet("060", new boolean[] {false, false, false, true, true, false, false, false, false});
verifyStringOctalModeSet("040", new boolean[] {false, false, false, true, false, false, false, false, false});
@@ -45,7 +45,7 @@ public final void testSetOctalModeString_GroupModes() {
}
@Test
- public final void testSetOctalModeString_WorldModes() {
+ final void testSetOctalModeString_WorldModes() {
verifyStringOctalModeSet("007", new boolean[] {false, false, false, false, false, false, true, true, true});
verifyStringOctalModeSet("006", new boolean[] {false, false, false, false, false, false, true, true, false});
verifyStringOctalModeSet("004", new boolean[] {false, false, false, false, false, false, true, false, false});
@@ -53,7 +53,7 @@ public final void testSetOctalModeString_WorldModes() {
}
@Test
- public final void testSetOctalMode_OwnerModes() {
+ final void testSetOctalMode_OwnerModes() {
verifyOctalModeSet("700", new boolean[] {true, true, true, false, false, false, false, false, false});
verifyOctalModeSet("600", new boolean[] {true, true, false, false, false, false, false, false, false});
verifyOctalModeSet("400", new boolean[] {true, false, false, false, false, false, false, false, false});
@@ -61,7 +61,7 @@ public final void testSetOctalMode_OwnerModes() {
}
@Test
- public final void testSetOctalMode_GroupModes() {
+ final void testSetOctalMode_GroupModes() {
verifyOctalModeSet("070", new boolean[] {false, false, false, true, true, true, false, false, false});
verifyOctalModeSet("060", new boolean[] {false, false, false, true, true, false, false, false, false});
verifyOctalModeSet("040", new boolean[] {false, false, false, true, false, false, false, false, false});
@@ -69,7 +69,7 @@ public final void testSetOctalMode_GroupModes() {
}
@Test
- public final void testSetOctalMode_WorldModes() {
+ final void testSetOctalMode_WorldModes() {
verifyOctalModeSet("007", new boolean[] {false, false, false, false, false, false, true, true, true});
verifyOctalModeSet("006", new boolean[] {false, false, false, false, false, false, true, true, false});
verifyOctalModeSet("004", new boolean[] {false, false, false, false, false, false, true, false, false});
diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java
index 74f3ce5..38f1d01 100644
--- a/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java
+++ b/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java
@@ -6,17 +6,19 @@
import java.util.Set;
import org.codehaus.plexus.util.Os;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Kristian Rosenvold
*/
+@SuppressWarnings("OctalInteger")
public class AttributeUtilsTest {
@Test
- public void testMiscPatterns() throws Exception {
+ void testMiscPatterns() {
final Set permissions = AttributeUtils.getPermissions(0124);
assertTrue(permissions.contains(PosixFilePermission.OWNER_EXECUTE));
assertTrue(permissions.contains(PosixFilePermission.GROUP_WRITE));
@@ -24,7 +26,7 @@ public void testMiscPatterns() throws Exception {
}
@Test
- public void testMorePatterns() throws Exception {
+ void testMorePatterns() {
final Set permissions = AttributeUtils.getPermissions(0241);
assertTrue(permissions.contains(PosixFilePermission.OWNER_WRITE));
assertTrue(permissions.contains(PosixFilePermission.GROUP_READ));
@@ -32,7 +34,7 @@ public void testMorePatterns() throws Exception {
}
@Test
- public void testEvenMorePatterns() throws Exception {
+ void testEvenMorePatterns() throws Exception {
final Set permissions = AttributeUtils.getPermissions(0412);
assertTrue(permissions.contains(PosixFilePermission.OWNER_READ));
assertTrue(permissions.contains(PosixFilePermission.GROUP_EXECUTE));
@@ -40,13 +42,13 @@ public void testEvenMorePatterns() throws Exception {
}
@Test
- public void test777() throws Exception {
+ void test777() throws Exception {
final Set permissions = AttributeUtils.getPermissions(0777);
- assertTrue(permissions.size() == 9);
+ assertEquals(9, permissions.size());
}
@Test
- public void testChmodBackAndForth() throws IOException {
+ void testChmodBackAndForth() throws IOException {
if (Os.isFamily(Os.FAMILY_WINDOWS)) return;
final File bxx = File.createTempFile("bxx", "ff");
AttributeUtils.chmod(bxx, 0422);
diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java
index db2dc0d..0e3025c 100644
--- a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java
+++ b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java
@@ -19,16 +19,16 @@
import java.io.File;
import org.codehaus.plexus.util.Os;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author Kristian Rosenvold
*/
public class FileAttributesTest {
@Test
- public void testGetPosixFileAttributes() throws Exception {
+ void testGetPosixFileAttributes() throws Exception {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
return;
diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java
index 92af5c7..fe88770 100644
--- a/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java
+++ b/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java
@@ -19,6 +19,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.nio.file.NoSuchFileException;
import java.util.Map;
import org.codehaus.plexus.util.Os;
@@ -26,21 +27,16 @@
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils.getFileAttributes;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.*;
+@SuppressWarnings("OctalInteger")
public class PlexusIoResourceAttributeUtilsTest {
@Test
- public void testGetAttributesForThisTestClass() throws IOException {
+ void testGetAttributesForThisTestClass() throws IOException {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
System.out.println("WARNING: Unsupported OS, skipping test");
return;
@@ -68,7 +64,7 @@ public void testGetAttributesForThisTestClass() throws IOException {
}
@Test
- public void testDirectory() throws IOException, CommandLineException {
+ void testDirectory() throws IOException, CommandLineException {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
return; // Nothing to do here.
@@ -110,7 +106,7 @@ public void testDirectory() throws IOException, CommandLineException {
}
@Test
- public void testSrcResource() throws IOException {
+ void testSrcResource() throws IOException {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
return; // Nothing to do here.
}
@@ -129,18 +125,15 @@ public void testSrcResource() throws IOException {
}
@Test
- public void testNonExistingDirectory() {
- File dir = new File("src/test/noSuchDirectory");
- try {
+ void testNonExistingDirectory() {
+ assertThrows(NoSuchFileException.class, () -> {
+ File dir = new File("src/test/noSuchDirectory");
PlexusIoResourceAttributeUtils.getFileAttributesByPath(dir, true);
- fail("We were supposed to get an io exceptions");
- } catch (IOException ignore) {
- ignore.printStackTrace();
- }
+ });
}
@Test
- public void testMergeAttributesWithNullBase() {
+ void testMergeAttributesWithNullBase() {
PlexusIoResourceAttributes override = new SimpleResourceAttributes(1001, "myUser", 1001, "test", 0);
PlexusIoResourceAttributes defaults = new SimpleResourceAttributes(1000, "defaultUser", 1000, "defaultTest", 0);
@@ -152,7 +145,7 @@ public void testMergeAttributesWithNullBase() {
}
@Test
- public void testMergeAttributesWithNullOverrideGroup() {
+ void testMergeAttributesWithNullOverrideGroup() {
final PlexusIoResourceAttributes override = new SimpleResourceAttributes(1001, "myUser", -1, null, 0);
final PlexusIoResourceAttributes defaults =
new SimpleResourceAttributes(1000, "defaultUser", 1000, "defaultGroup", 0);
@@ -165,7 +158,7 @@ public void testMergeAttributesWithNullOverrideGroup() {
}
@Test
- public void testMergeAttributesOverride() {
+ void testMergeAttributesOverride() {
final PlexusIoResourceAttributes blank = new SimpleResourceAttributes();
final PlexusIoResourceAttributes invalid = new SimpleResourceAttributes(-1, null, -1, null, -1);
final PlexusIoResourceAttributes override =
@@ -174,23 +167,17 @@ public void testMergeAttributesOverride() {
new SimpleResourceAttributes(3333, "defaultUser", 4444, "defaultGroup", 0444);
final PlexusIoResourceAttributes base = new SimpleResourceAttributes(5555, "baseUser", 6666, "baseGroup", 0111);
- PlexusIoResourceAttributes attributes;
-
// When override is null, base is returned verbatim
- attributes = PlexusIoResourceAttributeUtils.mergeAttributes(null, null, null);
- assertNull(attributes);
+ assertNull(PlexusIoResourceAttributeUtils.mergeAttributes(null, null, null));
- attributes = PlexusIoResourceAttributeUtils.mergeAttributes(null, null, defaults);
- assertNull(attributes);
+ assertNull(PlexusIoResourceAttributeUtils.mergeAttributes(null, null, defaults));
- attributes = PlexusIoResourceAttributeUtils.mergeAttributes(null, base, null);
- assertSame(base, attributes);
+ assertSame(base, PlexusIoResourceAttributeUtils.mergeAttributes(null, base, null));
- attributes = PlexusIoResourceAttributeUtils.mergeAttributes(null, base, defaults);
- assertSame(base, attributes);
+ assertSame(base, PlexusIoResourceAttributeUtils.mergeAttributes(null, base, defaults));
// Test cases when override is non-null
- attributes = PlexusIoResourceAttributeUtils.mergeAttributes(override, null, null);
+ PlexusIoResourceAttributes attributes = PlexusIoResourceAttributeUtils.mergeAttributes(override, null, null);
assertEquals(Integer.valueOf(1111), attributes.getUserId());
assertEquals("testUser", attributes.getUserName());
@@ -273,7 +260,7 @@ public void testMergeAttributesOverride() {
}
@Test
- public void testFileAttributes() throws IOException {
+ void testFileAttributes() throws IOException {
PlexusIoResourceAttributes attrs = getFileAttributes(new File("src/test/resources/symlinks/src/fileW.txt"));
assertFalse(attrs.isSymbolicLink());
assertTrue(StringUtils.isNotEmpty(attrs.getUserName()));
@@ -285,7 +272,7 @@ public void testFileAttributes() throws IOException {
}
@Test
- public void testMergeAttributesDefault() {
+ void testMergeAttributesDefault() {
final PlexusIoResourceAttributes blank = new SimpleResourceAttributes(null, null, null, null, 0);
final PlexusIoResourceAttributes invalid = new SimpleResourceAttributes(-1, null, -1, null, -1);
final PlexusIoResourceAttributes defaults =
diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java
index 7d250f3..b3f97aa 100644
--- a/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java
+++ b/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java
@@ -21,27 +21,27 @@
import java.nio.file.Files;
import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
public class SymlinkUtilsTest {
File target = new File("target/symlinkCapabilities");
String expected = "This is a filed that we'll be symlinking to\n";
- @Before
+ @BeforeEach
public void setup() throws IOException {
FileUtils.deleteDirectory(target);
Files.createDirectories(target.toPath());
}
@Test
- public void testName() throws Exception {}
+ void testName() throws Exception {}
@Test
- public void create_read_symbolic_link_to_file() throws Exception {
+ void create_read_symbolic_link_to_file() throws Exception {
File symlink = new File(target, "symlinkToTarget");
File relativePath = createTargetFile(target);
SymlinkUtils.createSymbolicLink(symlink, relativePath);
@@ -50,7 +50,7 @@ public void create_read_symbolic_link_to_file() throws Exception {
}
@Test
- public void create_read_symbolic_link_to_directory() throws Exception {
+ void create_read_symbolic_link_to_directory() throws Exception {
File subDir = new File(target, "aSubDir");
createTargetFile(subDir);
File symlink = new File(target, "symlinkToDir");
diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java
index 9471d32..fbd7d94 100644
--- a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java
+++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java
@@ -16,17 +16,25 @@
* limitations under the License.
*/
+import javax.inject.Inject;
+
import java.lang.reflect.UndeclaredThrowableException;
import java.util.Arrays;
-import org.junit.Test;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.testing.PlexusTest;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* Test case for the various file mappers.
*/
-public class FileMapperTest extends TestSupport {
+@PlexusTest
+public class FileMapperTest {
+ @Inject
+ PlexusContainer container;
+
protected void testFileMapper(FileMapper pMapper, String[] pInput, String[] pOutput) {
for (int i = 0; i < pInput.length; i++) {
final String input = pInput[i];
@@ -77,7 +85,7 @@ protected void testFileMapper(FileMapper pMapper, String[] pInput, String[] pOut
};
@Test
- public void testIdentityMapper() throws Exception {
+ void testIdentityMapper() throws Exception {
final String[] results = getIdentityResults();
testFileMapper(new IdentityMapper(), SAMPLES, results);
}
@@ -90,15 +98,15 @@ private String[] getIdentityResults() {
}
@Test
- public void testDefaultMapper() throws Exception {
+ void testDefaultMapper() throws Exception {
final String[] results = getIdentityResults();
- testFileMapper((FileMapper) lookup(FileMapper.class), SAMPLES, results);
- testFileMapper((FileMapper) lookup(FileMapper.class, IdentityMapper.ROLE_HINT), SAMPLES, results);
- testFileMapper((FileMapper) lookup(FileMapper.class), SAMPLES, results);
+ testFileMapper(container.lookup(FileMapper.class), SAMPLES, results);
+ testFileMapper(container.lookup(FileMapper.class, IdentityMapper.ROLE_HINT), SAMPLES, results);
+ testFileMapper(container.lookup(FileMapper.class), SAMPLES, results);
}
@Test
- public void testFileExtensionMapper() throws Exception {
+ void testFileExtensionMapper() throws Exception {
final String[] results = getIdentityResults();
for (int i = 2; i <= 10; i += 2) {
results[i] += ".png";
@@ -107,7 +115,8 @@ public void testFileExtensionMapper() throws Exception {
results[i] = results[i].substring(0, results[i].length() - ".gif".length()) + ".png";
}
testFileExtensionMapper(results, new FileExtensionMapper());
- testFileExtensionMapper(results, (FileExtensionMapper) lookup(FileMapper.class, FileExtensionMapper.ROLE_HINT));
+ testFileExtensionMapper(
+ results, (FileExtensionMapper) container.lookup(FileMapper.class, FileExtensionMapper.ROLE_HINT));
}
private void testFileExtensionMapper(final String[] results, final FileExtensionMapper mapper) {
@@ -118,12 +127,12 @@ private void testFileExtensionMapper(final String[] results, final FileExtension
}
@Test
- public void testFlattenMapper() throws Exception {
+ void testFlattenMapper() throws Exception {
final String[] results = getIdentityResults();
results[4] = results[6] = results[8] = results[10] = results[2];
results[5] = results[7] = results[9] = results[11] = results[3];
testFileMapper(new FlattenFileMapper(), SAMPLES, results);
- testFileMapper((FileMapper) lookup(FileMapper.class, FlattenFileMapper.ROLE_HINT), SAMPLES, results);
+ testFileMapper(container.lookup(FileMapper.class, FlattenFileMapper.ROLE_HINT), SAMPLES, results);
}
private void testMergeMapper(String pTargetName, String[] pResults, MergeFileMapper pMapper) {
@@ -132,22 +141,23 @@ private void testMergeMapper(String pTargetName, String[] pResults, MergeFileMap
}
@Test
- public void testMergeMapper() throws Exception {
+ void testMergeMapper() throws Exception {
final String[] results = getIdentityResults();
final String targetName = "zgh";
for (int i = 2; i < results.length; i++) {
results[i] = targetName;
}
testMergeMapper(targetName, results, new MergeFileMapper());
- testMergeMapper(targetName, results, (MergeFileMapper) lookup(FileMapper.class, MergeFileMapper.ROLE_HINT));
+ testMergeMapper(
+ targetName, results, (MergeFileMapper) container.lookup(FileMapper.class, MergeFileMapper.ROLE_HINT));
}
@Test
- public void testPrefixMapper() throws Exception {
+ void testPrefixMapper() throws Exception {
final String prefix = "x7Rtf";
final String[] results = getIdentityResults();
testFileMapper(new PrefixFileMapper(), SAMPLES, results);
- testFileMapper((PrefixFileMapper) lookup(FileMapper.class, PrefixFileMapper.ROLE_HINT), SAMPLES, results);
+ testFileMapper(container.lookup(FileMapper.class, PrefixFileMapper.ROLE_HINT), SAMPLES, results);
for (int i = 0; i < results.length; i++) {
if (results[i] != null) {
results[i] = prefix + results[i];
@@ -156,13 +166,13 @@ public void testPrefixMapper() throws Exception {
PrefixFileMapper mapper = new PrefixFileMapper();
mapper.setPrefix(prefix);
testFileMapper(mapper, SAMPLES, results);
- mapper = (PrefixFileMapper) lookup(FileMapper.class, PrefixFileMapper.ROLE_HINT);
+ mapper = (PrefixFileMapper) container.lookup(FileMapper.class, PrefixFileMapper.ROLE_HINT);
mapper.setPrefix(prefix);
testFileMapper(mapper, SAMPLES, results);
}
@Test
- public void testSuffixMapper() throws Exception {
+ void testSuffixMapper() throws Exception {
final String suffix = "suffix";
String[] samples = Arrays.copyOf(SAMPLES, SAMPLES.length + 2);
samples[samples.length - 2] = "archive.tar.gz";
@@ -186,7 +196,7 @@ public void testSuffixMapper() throws Exception {
SuffixFileMapper mapper = new SuffixFileMapper();
mapper.setSuffix(suffix);
testFileMapper(mapper, samples, results);
- mapper = (SuffixFileMapper) lookup(FileMapper.class, SuffixFileMapper.ROLE_HINT);
+ mapper = (SuffixFileMapper) container.lookup(FileMapper.class, SuffixFileMapper.ROLE_HINT);
mapper.setSuffix(suffix);
testFileMapper(mapper, samples, results);
}
@@ -198,7 +208,7 @@ private RegExpFileMapper configure(RegExpFileMapper pMapper, String pPattern, St
}
@Test
- public void testRegExpFileMapper() throws Exception {
+ void testRegExpFileMapper() throws Exception {
final String[] results = getIdentityResults();
results[3] = "xyz.jpg";
results[5] = "b/xyz.jpg";
@@ -208,7 +218,10 @@ public void testRegExpFileMapper() throws Exception {
testFileMapper(configure(new RegExpFileMapper(), "\\.gif$", ".jpg"), SAMPLES, results);
testFileMapper(configure(new RegExpFileMapper(), "^(.*)\\.gif$", "$1.jpg"), SAMPLES, results);
testFileMapper(
- configure((RegExpFileMapper) lookup(FileMapper.class, RegExpFileMapper.ROLE_HINT), "\\.gif$", ".jpg"),
+ configure(
+ (RegExpFileMapper) container.lookup(FileMapper.class, RegExpFileMapper.ROLE_HINT),
+ "\\.gif$",
+ ".jpg"),
SAMPLES,
results);
final RegExpFileMapper mapper = configure(new RegExpFileMapper(), "c", "f");
diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java
index f867658..c32b03c 100644
--- a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java
+++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java
@@ -17,24 +17,33 @@
*/
import javax.annotation.Nonnull;
+import javax.inject.Inject;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.Arrays;
+import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.components.io.fileselectors.AllFilesFileSelector;
import org.codehaus.plexus.components.io.fileselectors.FileSelector;
import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;
import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource;
-import org.junit.Test;
+import org.codehaus.plexus.testing.PlexusTest;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* Test case for implementations of {@link FileSelector}.
*/
-public class FileSelectorTest extends TestSupport {
+@PlexusTest
+public class FileSelectorTest {
+
+ @Inject
+ PlexusContainer container;
+
protected void testFileSelector(FileSelector pSelector, String[] pInput, boolean[] pOutput) throws IOException {
for (int i = 0; i < pInput.length; i++) {
final String name = pInput[i];
@@ -66,17 +75,15 @@ protected void testFileSelector(AllFilesFileSelector pSelector) throws Exception
private boolean[] getAllTrues() {
final boolean[] trues = new boolean[SAMPLES.length];
- for (int i = 0; i < trues.length; i++) {
- trues[i] = true;
- }
+ Arrays.fill(trues, true);
return trues;
}
@Test
- public void testAllFilesFileSelector() throws Exception {
+ void testAllFilesFileSelector() throws Exception {
testFileSelector(new AllFilesFileSelector());
- testFileSelector((AllFilesFileSelector) lookup(FileSelector.class));
- testFileSelector((AllFilesFileSelector) lookup(FileSelector.class, AllFilesFileSelector.ROLE_HINT));
+ testFileSelector((AllFilesFileSelector) container.lookup(FileSelector.class));
+ testFileSelector((AllFilesFileSelector) container.lookup(FileSelector.class, AllFilesFileSelector.ROLE_HINT));
}
protected boolean[] getIncludeGifs(String[] pSamples) {
@@ -107,13 +114,14 @@ protected void testFileSelector(IncludeExcludeFileSelector pSelector) throws Exc
}
@Test
- public void testIncludeExcludeFileSelector() throws Exception {
+ void testIncludeExcludeFileSelector() throws Exception {
testFileSelector(new IncludeExcludeFileSelector());
- testFileSelector((IncludeExcludeFileSelector) lookup(FileSelector.class, IncludeExcludeFileSelector.ROLE_HINT));
+ testFileSelector((IncludeExcludeFileSelector)
+ container.lookup(FileSelector.class, IncludeExcludeFileSelector.ROLE_HINT));
}
@Test
- public void testIncludeExcludeFileSelector_SetExcludes() throws Exception {
+ void testIncludeExcludeFileSelector_SetExcludes() throws Exception {
IncludeExcludeFileSelector selector = new IncludeExcludeFileSelector();
// Test that the setExcludes method does not modify the excludes.
diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java
index 66429a3..540da59 100644
--- a/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java
+++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java
@@ -16,6 +16,8 @@
* limitations under the License.
*/
+import javax.inject.Inject;
+
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
@@ -23,27 +25,32 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.Iterator;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
-import org.codehaus.plexus.components.io.resources.AbstractPlexusIoArchiveResourceCollection;
+import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.components.io.resources.PlexusIoFileResource;
import org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection;
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection;
+import org.codehaus.plexus.testing.PlexusTest;
import org.codehaus.plexus.util.FileUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-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.jupiter.api.Assertions.*;
/**
* Test case for resource collections.
*/
-public class ResourcesTest extends TestSupport {
+@PlexusTest
+public class ResourcesTest {
+
+ @Inject
+ PlexusContainer container;
+
private static final String X_PATH = "x";
private static final String A_PATH = X_PATH + "/a";
private static final String B_PATH = X_PATH + "/b";
@@ -65,11 +72,11 @@ private void createFiles() throws IOException {
final File aFile = new File(baseDir, A_PATH);
FileUtils.mkdir(aFile.getParentFile().getPath());
FileOutputStream fos = new FileOutputStream(aFile);
- fos.write("0123456789".getBytes("US-ASCII"));
+ fos.write("0123456789".getBytes(StandardCharsets.US_ASCII));
fos.close();
final File bFile = new File(baseDir, B_PATH);
fos = new FileOutputStream(bFile);
- fos.write("abcdefghijklmnopqrstuvwxyz".getBytes("US-ASCII"));
+ fos.write("abcdefghijklmnopqrstuvwxyz".getBytes(StandardCharsets.US_ASCII));
fos.close();
final File yDir = new File(baseDir, Y_PATH);
FileUtils.mkdir(yDir.getPath());
@@ -112,7 +119,7 @@ private void createZipFile(File dest, File dir) throws IOException {
}
private void compare(InputStream in, File file) throws IOException {
- try (InputStream fIn = new FileInputStream(file)) {
+ try (InputStream fIn = Files.newInputStream(file.toPath())) {
for (; ; ) {
int i1 = in.read();
int i2 = fIn.read();
@@ -147,28 +154,28 @@ private void testPlexusIoResourceCollection(PlexusIoResourceCollection plexusIoR
boolean yPathSeen = false;
boolean aFileSeen = false;
boolean bFileSeen = false;
- Iterator iter = plexusIoResourceCollection.getResources();
+ Iterator iter = plexusIoResourceCollection.getResources();
while (iter.hasNext()) {
- PlexusIoResource res = (PlexusIoResource) iter.next();
+ PlexusIoResource res = iter.next();
final String resName = res.getName().replace(File.separatorChar, '/');
if (res.isDirectory()) {
- assertFalse("The directory " + resName + " is a file.", res.isFile());
+ assertFalse(res.isFile(), "The directory " + resName + " is a file.");
if (X_PATH.equals(resName)) {
xPathSeen = true;
} else if (Y_PATH.equals(resName)) {
yPathSeen = true;
- } else if ("".equals(resName) || ".".equals(resName)) {
+ } else if (resName.isEmpty() || ".".equals(resName)) {
// Ignore me
} else {
fail("Unexpected directory entry: " + resName);
}
final File dir = new File(getFilesDir(), resName);
- assertTrue("The directory " + dir + " doesn't exist.", dir.isDirectory());
+ assertTrue(dir.isDirectory(), "The directory " + dir + " doesn't exist.");
} else {
- assertTrue("The file " + resName + " isn't reported to be a file.", res.isFile());
- assertTrue("The file " + resName + " doesn't exist.", res.isExisting());
+ assertTrue(res.isFile(), "The file " + resName + " isn't reported to be a file.");
+ assertTrue(res.isExisting(), "The file " + resName + " doesn't exist.");
final File f = new File(getFilesDir(), resName);
- assertTrue("A file " + f + " doesn't exist.", f.isFile() && f.exists());
+ assertTrue(f.isFile() && f.exists(), "A file " + f + " doesn't exist.");
if (A_PATH.equals(resName)) {
aFileSeen = true;
} else if (B_PATH.equals(resName)) {
@@ -193,16 +200,10 @@ private void testFileResourceCollection(PlexusIoFileResourceCollection resourceC
}
@Test
- public void testFileCollection() throws Exception {
+ void testFileCollection() throws Exception {
createFiles();
- testFileResourceCollection((PlexusIoFileResourceCollection) lookup(PlexusIoResourceCollection.class));
+ testFileResourceCollection((PlexusIoFileResourceCollection) container.lookup(PlexusIoResourceCollection.class));
testFileResourceCollection((PlexusIoFileResourceCollection)
- lookup(PlexusIoResourceCollection.class, PlexusIoFileResourceCollection.ROLE_HINT));
- }
-
- private void testZipFileCollection(AbstractPlexusIoArchiveResourceCollection resourceCollection, File zipFile)
- throws IOException {
- resourceCollection.setFile(zipFile);
- testPlexusIoResourceCollection(resourceCollection);
+ container.lookup(PlexusIoResourceCollection.class, PlexusIoFileResourceCollection.ROLE_HINT));
}
}
diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java
index 635b5ce..21c3714 100644
--- a/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java
+++ b/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java
@@ -10,9 +10,9 @@
import java.util.Iterator;
import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Kristian Rosenvold
@@ -20,7 +20,7 @@
public class AbstractPlexusIoResourceCollectionTest {
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
- public void testGetIncludes() throws Exception {
+ void testGetIncludes() throws Exception {
AbstractPlexusIoResourceCollection sut = new AbstractPlexusIoResourceCollection() {
public Iterator getResources() throws IOException {
return Arrays.asList(getResource("r1"), getResource("r2")).iterator();
diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java
index 418a3f0..dfcce72 100755
--- a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java
+++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java
@@ -3,16 +3,16 @@
import java.io.File;
import java.util.Iterator;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Kristian Rosenvold
*/
public class PlexusIoFileSupplierResourceCollectionTest {
@Test
- public void testGetName() throws Exception {
+ void testGetName() throws Exception {
PlexusIoFileResourceCollection coll = new PlexusIoFileResourceCollection();
char nonSeparator = File.separatorChar == '/' ? '\\' : '/';
coll.setPrefix("fud" + nonSeparator);
diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java
index 289087c..a4733f9 100644
--- a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java
+++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java
@@ -8,16 +8,14 @@
import org.codehaus.plexus.components.io.attributes.SymlinkUtils;
import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier;
import org.codehaus.plexus.util.Os;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
public class PlexusIoPlexusIoFileResourceTest {
@Test
- public void testRealSymlink() throws IOException {
+ void testRealSymlink() throws IOException {
if (Os.isFamily(Os.FAMILY_WINDOWS)) return;
final File file = new File("src/test/resources/symlinks/src/symDir");
PlexusIoResourceAttributes attrs = FileAttributes.uncached(file);
@@ -32,7 +30,7 @@ public void testRealSymlink() throws IOException {
}
@Test
- public void testSymSymlinkFile() throws IOException {
+ void testSymSymlinkFile() throws IOException {
if (Os.isFamily(Os.FAMILY_WINDOWS)) return;
final File file = new File("src/test/resources/symlinks/src/symSymR");
PlexusIoResource r = ResourceFactory.createResource(file);
@@ -47,7 +45,7 @@ public void testSymSymlinkFile() throws IOException {
}
@Test
- public void testSymlinkFile() throws IOException {
+ void testSymlinkFile() throws IOException {
if (Os.isFamily(Os.FAMILY_WINDOWS)) return;
final File file = new File("src/test/resources/symlinks/src/symR");
PlexusIoResource r = ResourceFactory.createResource(file);
diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java
index 87ba1e4..426ff90 100644
--- a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java
+++ b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java
@@ -28,10 +28,10 @@
import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResourceCollection;
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
import org.codehaus.plexus.components.io.resources.Stream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test case for {@link PlexusIoProxyResourceCollection}.
@@ -42,7 +42,7 @@ public class PlexusIoProxyResourceCollectionTest {
private final String[] SAMPLE_EXCLUDES = {"*.junk", "somwhere/**"};
@Test
- public void testGetDefaultFileSelector() throws Exception {
+ void testGetDefaultFileSelector() throws Exception {
PlexusIoProxyResourceCollection resCol = new PlexusIoProxyResourceCollection(null);
// This will throw an exception if there is a bug
@@ -55,12 +55,12 @@ public void testGetDefaultFileSelector() throws Exception {
resCol.getDefaultFileSelector();
}
- class CloseableIterator implements Iterator, Closeable {
+ static class CloseableIterator implements Iterator, Closeable {
boolean next = true;
boolean closed = false;
- public void close() throws IOException {
+ public void close() {
closed = true;
}
@@ -91,7 +91,7 @@ public void remove() {
}
@Test
- public void testClosing() throws IOException {
+ void testClosing() throws IOException {
final CloseableIterator closeableIterator = new CloseableIterator();
PlexusIoProxyResourceCollection resCol =
new PlexusIoProxyResourceCollection(new AbstractPlexusIoResourceCollection() {
diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java
index 7838332..158c363 100644
--- a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java
+++ b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java
@@ -18,17 +18,14 @@
import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier;
import org.codehaus.plexus.components.io.resources.PlexusIoFileResource;
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
public class ProxyFactoryTest {
@Test
- public void testCreateProxy() throws Exception {
+ void testCreateProxy() throws Exception {
final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), null);
assertTrue(proxy instanceof ResourceAttributeSupplier);
assertTrue(proxy instanceof FileSupplier);
@@ -36,42 +33,30 @@ public void testCreateProxy() throws Exception {
}
@Test
- public void testCreateProxyWithNameOverride() throws Exception {
- NameSupplier ns = new NameSupplier() {
- public String getName() {
- return "fred";
- }
- };
+ void testCreateProxyWithNameOverride() throws Exception {
+ NameSupplier ns = () -> "fred";
final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), ns);
assertEquals("fred", proxy.getName());
}
@Test
- public void testCreateProxyWithResourceAttributeOverride() throws Exception {
+ void testCreateProxyWithResourceAttributeOverride() throws Exception {
final PlexusIoResourceAttributes s = SimpleResourceAttributes.lastResortDummyAttributesForBrokenOS();
- ResourceAttributeSupplier ns = new ResourceAttributeSupplier() {
- public PlexusIoResourceAttributes getAttributes() {
- return s;
- }
- };
+ ResourceAttributeSupplier ns = () -> s;
final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), ns);
assertSame(s, ((ResourceAttributeSupplier) proxy).getAttributes());
}
@Test
- public void testCreateProxyWithSizeSupplierOverride() throws Exception {
+ void testCreateProxyWithSizeSupplierOverride() throws Exception {
final PlexusIoResourceAttributes s = SimpleResourceAttributes.lastResortDummyAttributesForBrokenOS();
- SizeSupplier ns = new SizeSupplier() {
- public long getSize() {
- return 42;
- }
- };
+ SizeSupplier ns = () -> 42;
final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), ns);
assertEquals(42, proxy.getSize());
}
@Test
- public void testCreateProxyWithContentSupplierOverride() throws Exception {
+ void testCreateProxyWithContentSupplierOverride() throws Exception {
final InputStream s = new ByteArrayInputStream(new byte[10]);
ContentSupplier ns = new ContentSupplier() {
public InputStream getContents() throws IOException {
@@ -83,12 +68,8 @@ public InputStream getContents() throws IOException {
}
@Test
- public void testCreateProxyWithSymlinkDestinationSupplierOverride() throws Exception {
- SymlinkDestinationSupplier ns = new SymlinkDestinationSupplier() {
- public String getSymlinkDestination() throws IOException {
- return "mordor";
- }
- };
+ void testCreateProxyWithSymlinkDestinationSupplierOverride() throws Exception {
+ SymlinkDestinationSupplier ns = () -> "mordor";
final PlexusIoResource proxy = ProxyFactory.createProxy(getDummySymlinkResource(), ns);
assertEquals("mordor", ((SymlinkDestinationSupplier) proxy).getSymlinkDestination());
}
@@ -100,7 +81,7 @@ private PlexusIoFileResource getPomResource() throws IOException {
return new PlexusIoFileResource(file, "pom.xml", attrs) {};
}
- class Dummy extends PlexusIoFileResource implements SymlinkDestinationSupplier {
+ static class Dummy extends PlexusIoFileResource implements SymlinkDestinationSupplier {
public Dummy(@Nonnull File file, @Nonnull PlexusIoResourceAttributes attrs) throws IOException {
super(file, file.getName(), attrs);
}