Skip to content

Commit 3cf0f8b

Browse files
committed
Add unit test
1 parent f6f9e34 commit 3cf0f8b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/test/java/org/carlspring/cloud/storage/s3fs/path/ResolveTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import org.carlspring.cloud.storage.s3fs.util.S3EndpointConstant;
77

88
import java.io.IOException;
9+
import java.nio.file.Paths;
910

1011
import org.junit.jupiter.api.AfterEach;
1112
import org.junit.jupiter.api.BeforeEach;
1213
import org.junit.jupiter.api.Test;
1314
import static org.carlspring.cloud.storage.s3fs.util.S3EndpointConstant.S3_GLOBAL_URI_TEST;
1415
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertThrows;
1517

1618
class ResolveTest
1719
extends S3UnitTestBase
@@ -64,4 +66,30 @@ void resolve()
6466
assertEquals(getPath("/bucket2/other/child"), getPath("/bucket/path/to/file").resolve("/bucket2/other/child"));
6567
}
6668

69+
70+
@Test
71+
void nonS3Paths()
72+
{
73+
S3Path parent = getPath("/bucket");
74+
S3Path child = getPath("/bucket/rabbit");
75+
S3Path resolved = (S3Path) parent.resolve(child);
76+
77+
assertEquals(child, resolved);
78+
79+
resolved = (S3Path) parent.resolve("rabbit");
80+
assertEquals(child, resolved);
81+
82+
resolved = (S3Path) parent.resolve(Paths.get("rabbit")); //unixPath
83+
assertEquals(child, resolved);
84+
85+
resolved = (S3Path) parent.resolve(Paths.get("./rabbit")); //unixPath
86+
assertEquals("s3://s3.test.amazonaws.com/bucket/./rabbit", resolved.toString());
87+
88+
resolved = (S3Path) parent.resolve(Paths.get("./rabbit in space")); //unixPath
89+
assertEquals("s3://s3.test.amazonaws.com/bucket/./rabbit%20in%20space", resolved.toString());
90+
91+
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () ->
92+
parent.resolve(Paths.get("/tmp")));
93+
assertEquals("other must be an instance of org.carlspring.cloud.storage.s3fs.S3Path or a relative Path", e.getMessage());
94+
}
6795
}

0 commit comments

Comments
 (0)