|
|
@@ -36,30 +36,49 @@ public class PathUtilsTest {
|
|
|
|
|
|
@Test
|
|
|
public void testGetSimpleName() {
|
|
|
- assertEquals("file", PathUtils.getSimpleName("c:/ms/file"));
|
|
|
- assertEquals("file", PathUtils.getSimpleName("c:/ms/file.txt"));
|
|
|
- assertEquals("file", PathUtils.getSimpleName("c:\\ms\\file.txt"));
|
|
|
assertEquals("file", PathUtils.getSimpleName("file.txt"));
|
|
|
- assertEquals("file", PathUtils.getSimpleName("/ms/file.txt"));
|
|
|
-
|
|
|
- assertEquals("file", PathUtils.getSimpleName("c:/ms/file.info."));
|
|
|
- assertEquals("file", PathUtils.getSimpleName("c:/ms/file.info.txt"));
|
|
|
- assertEquals("file", PathUtils.getSimpleName("c:\\ms\\file.info.txt"));
|
|
|
assertEquals("file", PathUtils.getSimpleName("file.info.txt"));
|
|
|
+
|
|
|
+ assertEquals("file", PathUtils.getSimpleName("/ms/file.txt"));
|
|
|
assertEquals("file", PathUtils.getSimpleName("/ms/file.info.txt"));
|
|
|
+
|
|
|
+ assertEquals("file", PathUtils.getSimpleName("c:/ms/file"));
|
|
|
+ assertEquals("file", PathUtils.getSimpleName("c:/ms/file.txt"));
|
|
|
+ assertEquals("file", PathUtils.getSimpleName("/c:/ms/file.info."));
|
|
|
+ assertEquals("file", PathUtils.getSimpleName("/c:/ms/file.info.txt"));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testChangeExtensionString_W32() {
|
|
|
+ public void testGetSimpleName_W32() {
|
|
|
Assume.assumeTrue(HostSystem.WINDOWS.detected());
|
|
|
|
|
|
+ assertEquals("file", PathUtils.getSimpleName("c:\\ms\\file.txt"));
|
|
|
+ assertEquals("file", PathUtils.getSimpleName("c:\\ms\\file.info.txt"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testGetSimpleName_NIX() {
|
|
|
+ Assume.assumeFalse(HostSystem.WINDOWS.detected());
|
|
|
+
|
|
|
+ assertEquals("c:\\ms\\file", PathUtils.getSimpleName("c:\\ms\\file.txt"));
|
|
|
+ assertEquals("c:\\ms\\file", PathUtils.getSimpleName("c:\\ms\\file.info.txt"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testChangeExtensionString() {
|
|
|
assertEquals(Paths.get("file.txt"), PathUtils.changeExtension("file.txt", ".txt"));
|
|
|
assertEquals(Paths.get("file.dat"), PathUtils.changeExtension("file.txt", ".dat"));
|
|
|
assertEquals(Paths.get("file.txt.dat"), PathUtils.changeExtension("file.txt.info", ".txt.dat"));
|
|
|
assertEquals(Paths.get("file.dat"), PathUtils.changeExtension("file.txt.info", ".dat"));
|
|
|
assertEquals(Paths.get("file.dat"), PathUtils.changeExtension("file", ".dat"));
|
|
|
-
|
|
|
+
|
|
|
assertEquals(Paths.get("base","name","file.txt"), PathUtils.changeExtension("base/name/file.txt", ".txt"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testChangeExtensionString_W32() {
|
|
|
+ Assume.assumeTrue(HostSystem.WINDOWS.detected());
|
|
|
+
|
|
|
assertEquals(Paths.get("base","name","file.dat"), PathUtils.changeExtension("base\\name\\file.txt", ".dat"));
|
|
|
assertEquals(Paths.get("c:","base","name","file.dat"), PathUtils.changeExtension("c:\\base\\name\\file.txt", ".dat"));
|
|
|
assertEquals(Paths.get("/base","name","file.dat"), PathUtils.changeExtension("/base/name\\file.txt", ".dat"));
|
|
|
@@ -68,40 +87,58 @@ public class PathUtilsTest {
|
|
|
@Test
|
|
|
public void testChangeExtension_NIX() {
|
|
|
Assume.assumeFalse(HostSystem.WINDOWS.detected());
|
|
|
- fail("implement");
|
|
|
+
|
|
|
+ assertEquals(Paths.get("base","name","file.dat"), PathUtils.changeExtension("base/name/file.txt", ".dat"));
|
|
|
+ assertEquals(Paths.get("c:","base","name","file.dat"), PathUtils.changeExtension("c:/base/name/file.txt", ".dat"));
|
|
|
+ assertEquals(Paths.get("/base","name","file.dat"), PathUtils.changeExtension("/base/name/file.txt", ".dat"));
|
|
|
+
|
|
|
+ assertEquals(Paths.get("base\\fame\\file.dat"), PathUtils.changeExtension("base\\fame\\file.txt", ".dat"));
|
|
|
+ assertEquals(Paths.get("base\\name\\file.dat"), PathUtils.changeExtension("base\\name\\file.txt", ".dat"));
|
|
|
+ assertEquals(Paths.get("c:\\base\\name\\file.dat"), PathUtils.changeExtension("c:\\base\\name\\file.txt", ".dat"));
|
|
|
+ assertEquals(Paths.get("/base","name\\file.dat"), PathUtils.changeExtension("/base/name\\file.txt", ".dat"));
|
|
|
}
|
|
|
-
|
|
|
- @Test
|
|
|
- public void testChangeExtensionPath_W32() {
|
|
|
- Assume.assumeTrue(HostSystem.WINDOWS.detected());
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testChangeExtensionPath() {
|
|
|
assertEquals(Paths.get("file.txt"), pce("file.txt", ".txt"));
|
|
|
assertEquals(Paths.get("file.dat"), pce("file.txt", ".dat"));
|
|
|
assertEquals(Paths.get("file.txt.dat"), pce("file.txt.info", ".txt.dat"));
|
|
|
assertEquals(Paths.get("file.dat"), pce("file.txt.info", ".dat"));
|
|
|
assertEquals(Paths.get("file.dat"), pce("file", ".dat"));
|
|
|
-
|
|
|
+
|
|
|
assertEquals(Paths.get("base","name","file.txt"), pce("base/name/file.txt", ".txt"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testChangeExtensionPath_W32() {
|
|
|
+ Assume.assumeTrue(HostSystem.WINDOWS.detected());
|
|
|
+
|
|
|
assertEquals(Paths.get("base","name","file.dat"), pce("base\\name\\file.txt", ".dat"));
|
|
|
assertEquals(Paths.get("c:","base","name","file.dat"), pce("c:\\base\\name\\file.txt", ".dat"));
|
|
|
assertEquals(Paths.get("/base","name","file.dat"), pce("/base/name\\file.txt", ".dat"));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testChangeSuffix() {
|
|
|
- assertEquals("c:\\ms\\root\\data.exe", PathUtils.changeSuffix("c:\\ms\\root\\data.if", ".exe").toString() );
|
|
|
+ public void testChangeExtensionPath_NIX() {
|
|
|
+ Assume.assumeFalse(HostSystem.WINDOWS.detected());
|
|
|
+
|
|
|
+ assertEquals(Paths.get("base","name","file.dat"), pce("base/name/file.txt", ".dat"));
|
|
|
+ assertEquals(Paths.get("c:","base","name","file.dat"), pce("c:/base/name/file.txt", ".dat"));
|
|
|
+ assertEquals(Paths.get("/base","name","file.dat"), pce("/base/name/file.txt", ".dat"));
|
|
|
+
|
|
|
+ assertEquals(Paths.get("base\\fame\\file.dat"), pce("base\\fame\\file.txt", ".dat"));
|
|
|
+ assertEquals(Paths.get("base\\name\\file.dat"), pce("base\\name\\file.txt", ".dat"));
|
|
|
+ assertEquals(Paths.get("c:\\base\\name\\file.dat"), pce("c:\\base\\name\\file.txt", ".dat"));
|
|
|
+ assertEquals(Paths.get("/base","name\\file.dat"), pce("/base/name\\file.txt", ".dat"));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testChangeExtensionP_NIX() {
|
|
|
- Assume.assumeFalse(HostSystem.WINDOWS.detected());
|
|
|
- fail("implement");
|
|
|
+ public void testChangeSuffix() {
|
|
|
+ assertEquals("c:\\ms\\root\\data.exe", PathUtils.changeSuffix("c:\\ms\\root\\data.if", ".exe").toString() );
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testFromURL_W32() throws MalformedURLException {
|
|
|
- Assume.assumeTrue(HostSystem.WINDOWS.detected());
|
|
|
-
|
|
|
+ public void testFromURL() throws MalformedURLException {
|
|
|
assertThrows(FileSystemNotFoundException.class, ()->{
|
|
|
PathUtils.fromURL(new URL("http://ranides.net/index.htm"));
|
|
|
});
|
|
|
@@ -109,23 +146,30 @@ public class PathUtilsTest {
|
|
|
PathUtils.fromURL(new URL("ftp://ranides.net/index.htm"));
|
|
|
});
|
|
|
|
|
|
- assertEquals(Paths.get("/ranides.net/index.htm"), PathUtils.fromURL(new URL("file:///ranides.net/index.htm")));
|
|
|
- assertEquals(Paths.get("c:/ms/index.htm"), PathUtils.fromURL(new URL("file:///c:/ms/index.htm")));
|
|
|
-
|
|
|
-
|
|
|
assertThrows(IllegalArgumentException.class, ()->{
|
|
|
PathUtils.fromURL(new URL("file://c:/ms/index.htm?query"));
|
|
|
});
|
|
|
+
|
|
|
+ assertEquals(Paths.get("/ranides.net/index.htm"), PathUtils.fromURL(new URL("file:///ranides.net/index.htm")));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testFromURL_NIX() {
|
|
|
+ public void testFromURL_W32() throws MalformedURLException {
|
|
|
+ Assume.assumeTrue(HostSystem.WINDOWS.detected());
|
|
|
+
|
|
|
+ assertEquals(Paths.get("c:/ms/index.htm"), PathUtils.fromURL(new URL("file:///c:/ms/index.htm")));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testFromURL_NIX() throws MalformedURLException {
|
|
|
Assume.assumeFalse(HostSystem.WINDOWS.detected());
|
|
|
- fail("implement");
|
|
|
+
|
|
|
+ assertEquals(Paths.get("/c:/ms/index.htm"), PathUtils.fromURL(new URL("file:///c:/ms/index.htm")));
|
|
|
+ assertEquals(Paths.get("/ranides.net/index.htm"), PathUtils.fromURL(new URL("file:///ranides.net/index.htm")));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void canonnical() {
|
|
|
+ public void canonnical_W32() {
|
|
|
Assume.assumeTrue(HostSystem.WINDOWS.detected());
|
|
|
|
|
|
assertEquals(Paths.get("c:/ms/Home"), PathUtils.normalize(Paths.get("c:/ms/Home")));
|
|
|
@@ -142,7 +186,21 @@ public class PathUtilsTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void canonnicalString() {
|
|
|
+ public void canonnical_NIX() {
|
|
|
+ Assume.assumeFalse(HostSystem.WINDOWS.detected());
|
|
|
+
|
|
|
+ assertEquals(Paths.get("/c/ms/Home"), PathUtils.normalize(Paths.get("/c/ms/Home")));
|
|
|
+
|
|
|
+ assertEquals(Paths.get("/root/dir/other/end"), PathUtils.normalize(Paths.get("/root/dir/something/../other/./end")));
|
|
|
+
|
|
|
+ assertFalse(Paths.get("/root/dir/something/../other/./end").startsWith("/root/dir/other") );
|
|
|
+ assertTrue(PathUtils.normalize(Paths.get("/root/dir/something/../other/./end")).startsWith("/root/dir/other/end"));
|
|
|
+
|
|
|
+ assertTrue(PathUtils.normalize(Paths.get("other/./end")).isAbsolute());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void canonnicalString_W32() {
|
|
|
Assume.assumeTrue(HostSystem.WINDOWS.detected());
|
|
|
|
|
|
assertEquals("c:\\ms\\Home", PathUtils.normalize("c:/ms/Home"));
|
|
|
@@ -158,9 +216,25 @@ public class PathUtilsTest {
|
|
|
assertTrue(new File(PathUtils.normalize("other/./end")).isAbsolute());
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void canonnicalString_NIX() {
|
|
|
+ Assume.assumeFalse(HostSystem.WINDOWS.detected());
|
|
|
+
|
|
|
+ assertEquals("/root/ms/Home", PathUtils.normalize("/root/ms/Home"));
|
|
|
+ assertNotEquals("/root/ms/Home", PathUtils.normalize("/root/ms/home"));
|
|
|
+
|
|
|
+ assertTrue(PathUtils.normalize("/root/ms/home").startsWith("/root/ms"));
|
|
|
+ assertFalse(PathUtils.normalize("/root/ms/home").startsWith("/root/MS"));
|
|
|
+
|
|
|
+ assertEquals("/root/dir/other/end", PathUtils.normalize("/root/dir/something/../other/./end"));
|
|
|
+
|
|
|
+ assertTrue(PathUtils.normalize("/root/dir/something/../other/./end").startsWith("/root/dir/other") );
|
|
|
+
|
|
|
+ assertTrue(new File(PathUtils.normalize("other/./end")).isAbsolute());
|
|
|
+ }
|
|
|
+
|
|
|
private static Path pce(String path, String ext) {
|
|
|
return PathUtils.changeExtension(Paths.get(path), ext);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|