Ranides Atterwim 5 lat temu
rodzic
commit
ba5f71d62a

+ 107 - 33
assira/src/test/java/net/ranides/assira/io/PathUtilsTest.java

@@ -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);
     }
 
-
 }

+ 1 - 1
assira/src/test/java/net/ranides/assira/reflection/IClassLoaderTest.java

@@ -12,7 +12,7 @@ import static org.junit.Assert.*;
 @SuppressWarnings("unchecked")
 public class IClassLoaderTest {
 
-    private static final String TYPE1_CLASS = "..\\assira.test\\target\\classes\\net\\ranides\\assira\\test\\Type1.class";
+    private static final String TYPE1_CLASS = "../assira.test/target/classes/net/ranides/assira/test/Type1.class";
 
     @Test
     public void system() throws IOException {

+ 6 - 5
assira/src/test/java/net/ranides/assira/reflection/util/ClassUtilsTest.java

@@ -15,6 +15,7 @@ import java.util.function.Function;
 import java.util.function.Supplier;
 import net.ranides.assira.ContractTesters;
 import net.ranides.assira.collection.mockup.TPoint;
+import org.junit.Assume;
 import org.junit.Test;
 import static net.ranides.assira.junit.NewAssert.*;
 
@@ -25,7 +26,7 @@ import static net.ranides.assira.junit.NewAssert.*;
 public class ClassUtilsTest {
     
     @Test
-    public void testBox() throws Exception {
+    public void testBox() {
         assertEquals(Byte.class, ClassUtils.box(byte.class));
         assertEquals(Short.class, ClassUtils.box(short.class));
         assertEquals(Integer.class, ClassUtils.box(int.class));
@@ -40,7 +41,7 @@ public class ClassUtilsTest {
     }
     
     @Test
-    public void testUnbox() throws Exception {
+    public void testUnbox() {
         assertEquals(byte.class, ClassUtils.unbox(Byte.class));
         assertEquals(short.class, ClassUtils.unbox(Short.class));
         assertEquals(int.class, ClassUtils.unbox(Integer.class));
@@ -60,13 +61,13 @@ public class ClassUtilsTest {
     public void testIsLoaded() throws IOException {
         TPoint point = new TPoint(0, 0, 0);
         assertTrue(ClassUtils.isLoaded("net.ranides.assira.collection.mockup.TPoint"));
-        
-        assertFalse(ClassUtils.isLoaded("net.ranides.assira.reflection.util.ClassUtilsTest$IType1"));
+
+		Assume.assumeFalse(ClassUtils.isLoaded("net.ranides.assira.reflection.util.ClassUtilsTest$IType1"));
         IType1 a = new IType1();
         assertTrue(ClassUtils.isLoaded("net.ranides.assira.reflection.util.ClassUtilsTest$IType1"));
         
         IType1.IType2.IType3 b = null;
-        assertFalse(ClassUtils.isLoaded("net.ranides.assira.reflection.util.ClassUtilsTest$IType1$IType2$IType3"));
+		Assume.assumeFalse(ClassUtils.isLoaded("net.ranides.assira.reflection.util.ClassUtilsTest$IType1$IType2$IType3"));
         b = new IType1.IType2.IType3();
         assertTrue(ClassUtils.isLoaded("net.ranides.assira.reflection.util.ClassUtilsTest$IType1$IType2$IType3"));