Skip to content

JUnit4 to 5 migration #111

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
Sep 21, 2023
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
29 changes: 14 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
<artifactId>plexus-utils</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand All @@ -63,21 +69,8 @@

<!-- Tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -86,6 +79,12 @@
<version>${slf4jVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-testing</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>
<!-- Sisu and dependencies -->
<dependency>
<groupId>org.eclipse.sisu</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -29,47 +29,47 @@ 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});
verifyStringOctalModeSet("200", new boolean[] {false, true, false, false, false, false, false, false, false});
}

@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});
verifyStringOctalModeSet("020", new boolean[] {false, false, false, false, true, false, false, false, false});
}

@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});
verifyStringOctalModeSet("002", new boolean[] {false, false, false, false, false, false, false, true, false});
}

@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});
verifyOctalModeSet("200", new boolean[] {false, true, false, false, false, false, false, false, false});
}

@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});
verifyOctalModeSet("020", new boolean[] {false, false, false, false, true, false, false, false, false});
}

@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});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,49 @@
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<PosixFilePermission> permissions = AttributeUtils.getPermissions(0124);
assertTrue(permissions.contains(PosixFilePermission.OWNER_EXECUTE));
assertTrue(permissions.contains(PosixFilePermission.GROUP_WRITE));
assertTrue(permissions.contains(PosixFilePermission.OTHERS_READ));
}

@Test
public void testMorePatterns() throws Exception {
void testMorePatterns() {
final Set<PosixFilePermission> permissions = AttributeUtils.getPermissions(0241);
assertTrue(permissions.contains(PosixFilePermission.OWNER_WRITE));
assertTrue(permissions.contains(PosixFilePermission.GROUP_READ));
assertTrue(permissions.contains(PosixFilePermission.OTHERS_EXECUTE));
}

@Test
public void testEvenMorePatterns() throws Exception {
void testEvenMorePatterns() throws Exception {
final Set<PosixFilePermission> permissions = AttributeUtils.getPermissions(0412);
assertTrue(permissions.contains(PosixFilePermission.OWNER_READ));
assertTrue(permissions.contains(PosixFilePermission.GROUP_EXECUTE));
assertTrue(permissions.contains(PosixFilePermission.OTHERS_WRITE));
}

@Test
public void test777() throws Exception {
void test777() throws Exception {
final Set<PosixFilePermission> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,24 @@
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;
import org.codehaus.plexus.util.StringUtils;
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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
}
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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 =
Expand All @@ -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());
Expand Down Expand Up @@ -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()));
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand Down
Loading