### Question:
FileUpdateChecker { public boolean directoryHasChanged(String directoryPath) throws IOException { boolean ret = true; String dirHash = hashDirectory(directoryPath, true); if (checksums.containsKey(directoryPath)) { ret = !checksums.get(directoryPath).equals(dirHash); } checksums.put(directoryPath, dirHash); return ret; } FileUpdateChecker(String checksumFilepath); boolean directoryHasChanged(String directoryPath); void writeChecksums();  }### Answer:
@Test public void directoryHasChanged_returnsTrueWhenNoChecksumFile() throws Exception { final String checksumFilepath = "noSuchFile"; final String directoryPath = tempFolder.getRoot().getPath(); FileUpdateChecker checker = new FileUpdateChecker(checksumFilepath); assertTrue(checker.directoryHasChanged(directoryPath)); }
@Test public void directoryHasChanged_returnsTrueForNewDirectory() throws Exception { File checksumFile = tempFolder.newFile("checksums.csv"); initialiseChecksumFile(checksumFile, 1); File newDir = tempFolder.newFolder(); FileUpdateChecker checker = new FileUpdateChecker(checksumFile.getAbsolutePath()); assertTrue(checker.directoryHasChanged(newDir.getAbsolutePath())); }
@Test public void directoryHasChanged_returnsTrueForNewFileInDirectory() throws Exception { File checksumFile = tempFolder.newFile("checksums.csv"); Map<String, String> checksums = initialiseChecksumFile(checksumFile, 3); String existingDirPath = checksums.keySet().iterator().next(); File tmpFile = new File(existingDirPath, "newFile.txt"); try (final PrintWriter pw = new PrintWriter(new FileWriter(tmpFile))) { pw.println("Blah"); } FileUpdateChecker checker = new FileUpdateChecker(checksumFile.getAbsolutePath()); assertTrue(checker.directoryHasChanged(existingDirPath)); }
@Test public void directoryHasChanged_returnsFalseForSameDirectory() throws Exception { File checksumFile = tempFolder.newFile("checksums.csv"); Map<String, String> checksums = initialiseChecksumFile(checksumFile, 3); String existingDirPath = checksums.keySet().iterator().next(); FileUpdateChecker checker = new FileUpdateChecker(checksumFile.getAbsolutePath()); assertFalse(checker.directoryHasChanged(existingDirPath)); }