### Question:
DirectoryWatcher implements Loader { public void discover() throws IOException { DirectoryStream<Path> stream; try { stream = Files.newDirectoryStream(rootDir); } catch (IOException ioe) { throw ioe; } Path completed = null; for (Path p : stream) { completed = Paths.get(p.toString(), completedMarkerFilename); if (!Files.isDirectory(p) || knownDirs.contains(p) || Files.exists(completed)) { continue; } knownDirs.add(p); Files.createFile(completed); try { FileEntry e = DirectoryLoader.load(p); entries.add(e); } catch (IOException ioe) { LOGGER.error("Loading FileEntry batch directory failed, discarding it: {} with message: {}", p, ioe.getMessage()); } } } DirectoryWatcher(Path rootDir); static void deleteDirectory(Path path); static boolean isDirEmpty(Path dir); void discover(); boolean hasNewEntries(); List<FileEntry> getNewEntries(); List<FileEntry> getEntries(); @Override List<? extends AbstractEntry> loadAll(); @Override List<? extends AbstractEntry> loadNew();  }### Answer:
@Test public void testDiscover() throws IOException { assertNotNull(watcher); Path newDir1 = Files.createTempDirectory(rootPath, "testDir"); Path newFile1 = Files.createTempFile(newDir1, "testFileDirWatching", ".carcv.jpg"); Path newPermissions1 = Paths.get(newDir1.toString(), "info.properties"); properties.store(new FileOutputStream(newPermissions1.toFile()), ""); assertNotNull(newFile1); watcher.discover(); List<FileEntry> list1 = watcher.getNewEntries(); assertEquals(1, list1.size()); assertEquals(0, watcher.getNewEntries().size()); assertFalse(watcher.hasNewEntries()); FileEntry newEntry1 = list1.get(0); assertNotNull(newEntry1); assertNotNull(newEntry1.getCarData()); FileCarImage newImage1 = newEntry1.getCarImages().get(0); assertNotNull(newImage1); assertNotNull(newImage1.getFilepath()); assertNull(newImage1.getImage()); Path newDir2 = Files.createTempDirectory(rootPath, "testDir"); Path newFile2 = Files.createTempFile(newDir2, "testFileDirWatching", ".carcv.jpg"); Path newPermissions2 = Paths.get(newDir2.toString(), "info.properties"); properties.store(new FileOutputStream(newPermissions2.toFile()), ""); assertNotNull(newFile2); watcher.discover(); List<FileEntry> list2 = watcher.getNewEntries(); assertEquals(1, list2.size()); assertEquals(0, watcher.getNewEntries().size()); assertFalse(watcher.hasNewEntries()); FileEntry newEntry2 = list2.get(0); assertNotNull(newEntry2); assertNotNull(newEntry2.getCarData()); FileCarImage newImage2 = newEntry2.getCarImages().get(0); assertNotNull(newImage2); assertNotNull(newImage2.getFilepath()); assertNull(newImage2.getImage()); assertFalse(watcher.hasNewEntries()); assertNotEquals(newEntry1, newEntry2); assertEquals(newEntry1.getCarData(), newEntry2.getCarData()); assertNotEquals(newImage1, newImage2); assertNotEquals(newImage1.getFilepath(), newImage2.getFilepath()); assertNotEquals(newFile1, newFile2); assertFalse(watcher.hasNewEntries()); watcher.discover(); assertFalse(watcher.hasNewEntries()); }