Skip to content
Closed
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
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.14</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
Expand Down Expand Up @@ -62,4 +63,75 @@ void chmodBackAndForth() throws Exception {
assertTrue(secondAttrs.isOwnerWritable());
assertTrue(secondAttrs.isOwnerExecutable());
}

@Test
void testGetLastModified() throws Exception {
File tempFile = File.createTempFile("test", ".tmp");
try {
long lastModified = AttributeUtils.getLastModified(tempFile);
assertTrue(lastModified > 0);
} finally {
tempFile.delete();
}
}

@Test
@DisabledOnOs(OS.WINDOWS)
void testGetPosixFileAttributes() throws Exception {
File tempFile = File.createTempFile("test", ".tmp");
try {
java.nio.file.attribute.PosixFileAttributes attrs = AttributeUtils.getPosixFileAttributes(tempFile);
assertNotNull(attrs);
} finally {
tempFile.delete();
}
}

@Test
void testGetFileAttributes() throws Exception {
File tempFile = File.createTempFile("test", ".tmp");
try {
java.nio.file.attribute.BasicFileAttributes attrs = AttributeUtils.getFileAttributes(tempFile);
assertNotNull(attrs);
assertTrue(attrs.isRegularFile());
} finally {
tempFile.delete();
}
}

@Test
void testGetFileAttributesPath() throws Exception {
File tempFile = File.createTempFile("test", ".tmp");
try {
java.nio.file.attribute.BasicFileAttributes attrs = AttributeUtils.getFileAttributes(tempFile.toPath());
assertNotNull(attrs);
assertTrue(attrs.isRegularFile());
} finally {
tempFile.delete();
}
}

@Test
void testIsUnix() throws Exception {
File tempFile = File.createTempFile("test", ".tmp");
try {
boolean isUnix = AttributeUtils.isUnix(tempFile.toPath());
// Just verify it returns a boolean value and doesn't throw
assertTrue(isUnix || !isUnix); // tautology to use the value
} finally {
tempFile.delete();
}
}

@Test
void testGetFileOwnershipInfo() throws Exception {
File tempFile = File.createTempFile("test", ".tmp");
try {
java.nio.file.attribute.FileOwnerAttributeView ownerView = AttributeUtils.getFileOwnershipInfo(tempFile);
// May be null on unsupported systems, just verify it doesn't throw
assertTrue(ownerView != null || ownerView == null);
} finally {
tempFile.delete();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
* limitations under the License.
*/

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class SimpleResourceAttributesTest extends AbstractResourceAttributesTCK {

protected PlexusIoResourceAttributes newAttributes(int mode) {
Expand All @@ -29,4 +33,50 @@ protected PlexusIoResourceAttributes newAttributes(String mode) {
simpleResourceAttributes.setOctalModeString(mode);
return simpleResourceAttributes;
}

@Test
void testConstructorWithAllParameters() {
SimpleResourceAttributes attrs = new SimpleResourceAttributes(1000, "testuser", 2000, "testgroup", 0644);
assertEquals(1000, attrs.getUserId());
assertEquals("testuser", attrs.getUserName());
assertEquals(2000, attrs.getGroupId());
assertEquals("testgroup", attrs.getGroupName());
assertEquals(0644, attrs.getOctalMode());
}

@Test
void testConstructorWithSymbolicLink() {
SimpleResourceAttributes attrs = new SimpleResourceAttributes(1000, "testuser", 2000, "testgroup", 0644, true);
assertTrue(attrs.isSymbolicLink());
assertEquals(1000, attrs.getUserId());
}

@Test
void testLastResortDummyAttributes() {
PlexusIoResourceAttributes attrs = SimpleResourceAttributes.lastResortDummyAttributesForBrokenOS();
assertNotNull(attrs);
assertEquals(PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE, attrs.getOctalMode());
}

@Test
void testSettersAndGetters() {
SimpleResourceAttributes attrs = new SimpleResourceAttributes();
attrs.setUserId(500);
attrs.setUserName("user");
attrs.setGroupId(600);
attrs.setGroupName("group");

assertEquals(500, attrs.getUserId());
assertEquals("user", attrs.getUserName());
assertEquals(600, attrs.getGroupId());
assertEquals("group", attrs.getGroupName());
}

@Test
void testSetOctalModeString() {
SimpleResourceAttributes attrs = new SimpleResourceAttributes();
attrs.setOctalModeString("0755");
assertEquals(0755, attrs.getOctalMode());
assertEquals("755", attrs.getOctalModeString()); // Returns octal string without leading 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package org.codehaus.plexus.components.io.attributes;

/*
* Copyright 2025 The Codehaus Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import java.io.File;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
* Tests for {@link UserGroupModeFileAttributes}
*/
class UserGroupModeFileAttributesTest {

@Test
void testConstructorAndToString() throws Exception {
// Create a base FileAttributes
File tempFile = File.createTempFile("plexus-test", ".tmp");
try {
FileAttributes base = new FileAttributes(tempFile);

// Create UserGroupModeFileAttributes with various values
UserGroupModeFileAttributes attrs =
new UserGroupModeFileAttributes(1000, "testuser", 2000, "testgroup", 0644, base);

// Verify the object is created
assertNotNull(attrs);

// Verify toString contains expected information
String toString = attrs.toString();
assertNotNull(toString);
assertTrue(toString.contains("testuser"));
assertTrue(toString.contains("testgroup"));
assertTrue(toString.contains("1000"));
assertTrue(toString.contains("2000"));
} finally {
tempFile.delete();
}
}

@Test
void testWithNullUserAndGroup() throws Exception {
File tempFile = File.createTempFile("plexus-test", ".tmp");
try {
FileAttributes base = new FileAttributes(tempFile);

// Create with null user and group names
UserGroupModeFileAttributes attrs = new UserGroupModeFileAttributes(null, null, null, null, 0755, base);

// Verify toString handles nulls properly
String toString = attrs.toString();
assertNotNull(toString);
// Should show empty strings for null names
assertTrue(toString.contains("user:"));
assertTrue(toString.contains("group:"));
} finally {
tempFile.delete();
}
}

@Test
void testInheritsFromBase() throws Exception {
File tempFile = File.createTempFile("plexus-test", ".tmp");
try {
FileAttributes base = new FileAttributes(tempFile);

UserGroupModeFileAttributes attrs =
new UserGroupModeFileAttributes(1000, "testuser", 2000, "testgroup", 0755, base);

// Verify inherited properties
assertEquals(base.isSymbolicLink(), attrs.isSymbolicLink());
assertEquals(base.isRegularFile(), attrs.isRegularFile());
assertEquals(base.isDirectory(), attrs.isDirectory());
} finally {
tempFile.delete();
}
}
}
Loading
Loading