@Test public void testRename() throws IOException{ File bla = new MockFile("bla"); File doh = new MockFile("doh"); Assert.assertFalse(bla.exists()); Assert.assertFalse(doh.exists()); boolean created = bla.createNewFile(); Assert.assertTrue(created); Assert.assertTrue(bla.exists()); Assert.assertFalse(doh.exists()); boolean renamed = bla.renameTo(doh); Assert.assertTrue(renamed); Assert.assertFalse(bla.exists()); Assert.assertTrue(doh.exists()); File inAnotherFolder = new MockFile("foo/hei/hello.tmp"); Assert.assertFalse(inAnotherFolder.exists()); renamed = doh.renameTo(inAnotherFolder); Assert.assertFalse(renamed); Assert.assertFalse(inAnotherFolder.exists()); Assert.assertTrue(doh.exists()); File de = new MockFile("deeee"); File blup = new MockFile("blup"); Assert.assertFalse(de.exists()); Assert.assertFalse(blup.exists()); renamed = de.renameTo(blup); Assert.assertFalse(renamed); Assert.assertFalse(de.exists()); Assert.assertFalse(blup.exists()); }
public boolean rename(String source, String destination) { String parentSource = new File(source).getParent(); String parentDest = new File(destination).getParent(); if ((parentSource == null && parentDest != null) || (!parentSource.equals(parentDest))) { return false; } FSObject src = findFSObject(source); if (src == null) { return false; } FSObject dest = findFSObject(destination); if (dest != null) { return false; } return src.rename(destination); }
VirtualFileSystem { public boolean rename(String source, String destination) { String parentSource = new File(source).getParent(); String parentDest = new File(destination).getParent(); if ((parentSource == null && parentDest != null) || (!parentSource.equals(parentDest))) { return false; } FSObject src = findFSObject(source); if (src == null) { return false; } FSObject dest = findFSObject(destination); if (dest != null) { return false; } return src.rename(destination); } }
VirtualFileSystem { public boolean rename(String source, String destination) { String parentSource = new File(source).getParent(); String parentDest = new File(destination).getParent(); if ((parentSource == null && parentDest != null) || (!parentSource.equals(parentDest))) { return false; } FSObject src = findFSObject(source); if (src == null) { return false; } FSObject dest = findFSObject(destination); if (dest != null) { return false; } return src.rename(destination); } private  VirtualFileSystem(); }
VirtualFileSystem { public boolean rename(String source, String destination) { String parentSource = new File(source).getParent(); String parentDest = new File(destination).getParent(); if ((parentSource == null && parentDest != null) || (!parentSource.equals(parentDest))) { return false; } FSObject src = findFSObject(source); if (src == null) { return false; } FSObject dest = findFSObject(destination); if (dest != null) { return false; } return src.rename(destination); } private  VirtualFileSystem(); static VirtualFileSystem getInstance(); void resetSingleton(); void addLeakingResource(LeakingResource resource); File getRealTmpFile(); void throwSimuledIOExceptionIfNeeded(String path); boolean isClassSupposedToThrowIOException(String path); boolean setShouldThrowIOException(EvoSuiteFile file); boolean setShouldAllThrowIOExceptions(); void init(); static String getWorkingDirPath(); static String getDefaultParent(); Set<String> getAccessedFiles(); String createTempFile(String prefix, String suffix, File directory); boolean exists(String rawPath); FSObject findFSObject(String rawPath); boolean deleteFSObject(String rawPath); boolean createFile(String rawPath); boolean rename(String source, String destination); boolean createFolder(String rawPath); }
VirtualFileSystem { public boolean rename(String source, String destination) { String parentSource = new File(source).getParent(); String parentDest = new File(destination).getParent(); if ((parentSource == null && parentDest != null) || (!parentSource.equals(parentDest))) { return false; } FSObject src = findFSObject(source); if (src == null) { return false; } FSObject dest = findFSObject(destination); if (dest != null) { return false; } return src.rename(destination); } private  VirtualFileSystem(); static VirtualFileSystem getInstance(); void resetSingleton(); void addLeakingResource(LeakingResource resource); File getRealTmpFile(); void throwSimuledIOExceptionIfNeeded(String path); boolean isClassSupposedToThrowIOException(String path); boolean setShouldThrowIOException(EvoSuiteFile file); boolean setShouldAllThrowIOExceptions(); void init(); static String getWorkingDirPath(); static String getDefaultParent(); Set<String> getAccessedFiles(); String createTempFile(String prefix, String suffix, File directory); boolean exists(String rawPath); FSObject findFSObject(String rawPath); boolean deleteFSObject(String rawPath); boolean createFile(String rawPath); boolean rename(String source, String destination); boolean createFolder(String rawPath);  }