Code example for Path

Methods: toFiletoString

0
        //FileListerTest.delete(tempDir, true); 
    } 
 
    @Test
    public void testListFiles() { 
        File tmp = tempDir.toFile();
        File child1 = new File(tmp + Config.getPathSeparator()+"child1");
        File child2 = new File(tmp + Config.getPathSeparator()+"child2");
        File child11 = new File(child1 + Config.getPathSeparator()+"child11");
        File child12 = new File(child1 + Config.getPathSeparator()+"child12");
        File child21 = new File(child1 + Config.getPathSeparator()+"child21");
        File child22 = new File(child1 + Config.getPathSeparator()+"child22");
 
        assertEquals(child1, PathResolver.resolvePath(new File(""), child1).get(0));
 
        assertEquals(child1, PathResolver.resolvePath(new File(".."), child11).get(0));
        assertEquals(child1, PathResolver.resolvePath(new File(".."+Config.getPathSeparator()), child11).get(0));
        assertEquals(tmp, PathResolver.resolvePath(new File(".."+Config.getPathSeparator()+".."), child11).get(0));
        assertEquals(tmp, PathResolver.resolvePath(new File(".."+Config.getPathSeparator()+
                ".."+Config.getPathSeparator()), child11).get(0));
 
        if(Config.isOSPOSIXCompatible()) {
            assertEquals(tmp.getParentFile(), PathResolver.resolvePath(new File("../../../"), child11).get(0));
            assertEquals(tmp.getParentFile().getParentFile(),
                    PathResolver.resolvePath(new File("../../../../"), child11).get(0));
//            assertEquals(tmp.getParentFile().getParentFile(), 
//                    PathResolver.resolvePath(new File("../../../../../"), child11).get(0)); 
//            assertEquals(tmp.getParentFile().getParentFile(), 
//                    PathResolver.resolvePath(new File("../../../../../.."), child11).get(0)); 
        } 
 
        assertEquals(child11, PathResolver.resolvePath(new File(".."+Config.getPathSeparator()+"child11"), child11).get(0));
        assertEquals(child1, PathResolver.resolvePath(new File(".."+Config.getPathSeparator()+".."+Config.getPathSeparator()+"child1"),
                child11).get(0));
        assertEquals(child11, PathResolver.resolvePath(new File(".."+Config.getPathSeparator()+".."+
                Config.getPathSeparator()+"child1"+Config.getPathSeparator()+"child11"), child11).get(0));
        assertEquals(tmp, PathResolver.resolvePath(new File(".."+Config.getPathSeparator()+".."+
                Config.getPathSeparator()+".."+Config.getPathSeparator()+tmp.getName()), child11).get(0));
 
 
        assertEquals(child11, PathResolver.resolvePath(new File("child11"), child1).get(0));
        assertEquals(child11, PathResolver.resolvePath(new File("child1"+Config.getPathSeparator()+"child11"), tmp).get(0));
 
        assertEquals(child11, PathResolver.resolvePath(new File("."+Config.getPathSeparator()+"child11"), child1).get(0));
        assertEquals(child1, PathResolver.resolvePath(new File("."+Config.getPathSeparator()), child1).get(0));
 
        assertEquals(child1, PathResolver.resolvePath(
                new File(".."+Config.getPathSeparator()+"child1"+Config.getPathSeparator()), child1).get(0));
        assertEquals(child1, PathResolver.resolvePath(new File(".."+Config.getPathSeparator()+"child1"+
                Config.getPathSeparator()+".."+Config.getPathSeparator()+"child1"), child1).get(0));
        assertEquals(child11, PathResolver.resolvePath(new File(".."+Config.getPathSeparator()+"child1"+
                Config.getPathSeparator()+".."+Config.getPathSeparator()+"child1"+Config.getPathSeparator()+"child11"), child1).get(0));
 
        assertEquals(child11, PathResolver.resolvePath(new File(".."+Config.getPathSeparator()+
                "child1"+Config.getPathSeparator()+"."+Config.getPathSeparator()+"child11"), child1).get(0));
 
        assertEquals(child11, PathResolver.resolvePath(new File("."+Config.getPathSeparator()+".."+
                Config.getPathSeparator()+"child1"+Config.getPathSeparator()+"."+Config.getPathSeparator()+"child11"), child1).get(0));
        assertEquals(child11, PathResolver.resolvePath(new File("."+Config.getPathSeparator()+".."+
                Config.getPathSeparator()+"child1"+Config.getPathSeparator()+"."+
                Config.getPathSeparator()+"child11"+Config.getPathSeparator()+"."), child1).get(0));
 
        System.setProperty("user.home", tempDir.toString()+Config.getPathSeparator()+"home");
        assertEquals(new File(Config.getHomeDir()), PathResolver.resolvePath(new File("~/../home"), child1).get(0));
 
        assertEquals(new File(Config.getHomeDir()), PathResolver.resolvePath(new File("~"), child1).get(0));
        assertEquals(new File(child1, "~a"), PathResolver.resolvePath(new File("~a"), child1).get(0));
    } 
Contextual code suggestions in your IDE  Get Codota for Java