@Test public void testDeleteDirectoryRecursive() throws IOException { File folder = OperatingSystemUtils.createTempDir(); folder.deleteOnExit(); folder.mkdir(); File folder2 = OperatingSystemUtils.createTempDir(); folder2.deleteOnExit(); folder2.mkdir(); File file = File.createTempFile("fileresourcetest", ".tmp"); file.deleteOnExit(); file.createNewFile(); File file2 = File.createTempFile("fileresourcetest2", ".tmp"); file2.deleteOnExit(); file2.createNewFile(); DirectoryResource folderResource = resourceFactory.create(DirectoryResource.class, folder); FileResource<?> src = resourceFactory.create(file).reify(FileResource.class); src.moveTo(folderResource); DirectoryResource folderResource2 = resourceFactory.create(DirectoryResource.class, folder2); FileResource<?> src2 = resourceFactory.create(file2).reify(FileResource.class); folderResource2.moveTo(folderResource); src2.moveTo(folderResource2); Assert.assertTrue(folderResource.isDirectory()); Assert.assertTrue(folderResource.exists()); Assert.assertTrue(src.exists()); Assert.assertTrue(folderResource2.isDirectory()); Assert.assertTrue(folderResource2.exists()); Assert.assertTrue(src2.exists()); folderResource.delete(true); Assert.assertTrue(!folderResource.exists()); Assert.assertTrue(!file.exists()); Assert.assertTrue(!folderResource2.exists()); Assert.assertTrue(!file2.exists()); }
@Test @SuppressWarnings("unchecked") public void testMoveFileResource() throws IOException { File file = File.createTempFile("fileresourcetest", ".tmp"); file.deleteOnExit(); File dest = File.createTempFile("newFileResourcetest", ".tmp"); dest.deleteOnExit(); FileResource<?> src = resourceFactory.create(FileResource.class, file); FileResource<?> newFile = resourceFactory.create(FileResource.class, dest); src.moveTo(newFile); Assert.assertNotNull(dest); Assert.assertTrue(dest.isFile()); Assert.assertEquals( src.getUnderlyingResourceObject().getAbsolutePath(), dest.getAbsolutePath()); Assert.assertTrue(src.exists()); }
@Test public void testMoveFileResourceToDirectory() throws IOException { File file = File.createTempFile("fileresourcetest", ".tmp"); file.deleteOnExit(); file.createNewFile(); File folder = OperatingSystemUtils.createTempDir(); folder.deleteOnExit(); folder.mkdir(); FileResource<?> src = resourceFactory.create(file).reify(FileResource.class); DirectoryResource folderResource = resourceFactory.create(DirectoryResource.class, folder); src.moveTo(folderResource); Assert.assertNotNull(src); Assert.assertTrue( src.getUnderlyingResourceObject().getAbsolutePath().contains(folder.getName())); Assert.assertTrue(src.exists()); Assert.assertFalse(src.isDirectory()); }