### Question:
DefaultTransferManager extends Observable implements TransferManager { void download(Download download) throws Exception { try (Download ignored = download) { try { if (!download.isValid()) { throw new TransferSkippedException("download says it's invalid"); } Path destination = download.getDestination(); Path source = download.getSource(); switch (download.getType()) { case UPDATE: case CREATE: if (download.isDir()) { Files.createDirectories(destination); download.setMtime(Files.getLastModifiedTime(destination).toMillis()); break; } Path parent = source.getParent(); BoxNavigation nav = navigate(parent, download.getBoxVolume()); BoxFile file = nav.getFile(source.getFileName().toString()); download.setSize(file.getSize()); if (remoteChanged(download, file)) { throw new TransferSkippedException("remote has changed"); } if (localIsNewer(destination, file)) { throw new TransferSkippedException("local is newer"); } ProgressListener listener = new TransactionRelatedProgressListener(download); try (InputStream stream = new BufferedInputStream(nav.download(file, listener))) { Path tmpFile = createTempFileForDownload(destination); try { Files.copy(stream, tmpFile, StandardCopyOption.REPLACE_EXISTING); Files.setLastModifiedTime(tmpFile, FileTime.fromMillis(download.getMtime())); Files.move(tmpFile, destination, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); if (Files.getLastModifiedTime(destination).toMillis() != download.getMtime()) { Files.setLastModifiedTime(destination, FileTime.fromMillis(download.getMtime())); } } finally { Files.deleteIfExists(tmpFile); } } break; case DELETE: if (download.isDir()) { FileUtils.deleteDirectory(destination.toFile()); } else { Files.deleteIfExists(destination); } break; } download.toState(FINISHED); } catch (TransferSkippedException e) { download.toState(SKIPPED); logger.debug("skipped download " + " (" + e.getMessage() + ")"); } catch (Exception e) { download.toState(FAILED); throw e; } } }  @Override List<Transaction> getTransactions(); @Override void addDownload(Download download); @Override List<Transaction> getHistory(); @Override void cleanup(); @Override void addUpload(Upload upload); @Override void run(); void next();  }### Answer:
@Test public void downloadsFolders() throws Exception { nav().createFolder("syncRoot"); download.source = syncRoot; download.destination = tmpPath("syncLocal"); download.type = CREATE; download.isDir = true; manager.download(download); assertTrue(Files.isDirectory(download.destination)); }
@Test public void closesDownload() throws Exception { nav().createFolder("syncRoot"); download.source = syncRoot; download.destination = tmpPath("syncLocal"); download.type = CREATE; download.isDir = true; manager.download(download); assertEquals(FINISHED, download.state); assertTrue("download not closed", download.closed); }
@Test public void deletesFilesLocally() throws Exception { Path downloadPath = tmpPath("testfile"); write("content", downloadPath); setDownload(downloadPath, NEWER, DELETE, false); manager.download(download); assertFalse("local file was not deleted", Files.exists(downloadPath)); }