### Question:
AnsibleExtraSensor extends AbstractAnsibleSensor { private boolean deleteDirectory(Path directory) { try { Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { LOGGER.warn("Cannot delete temporary directory: " + e.getMessage()); return false; } return true; } AnsibleExtraSensor(FileSystem fileSystem); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context); static final String EXTRA_RULES_TEMP_DIR; static final String EXTRA_RULES_DIR; }### Answer:
@Test public void testDeleteDirectory() throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { Method method = AnsibleExtraSensor.class.getDeclaredMethod("deleteDirectory", Path.class); method.setAccessible(true); Path tempDir = Files.createTempDirectory(EXTRA_RULES_TEMP_DIR); Path copyFile = tempDir.resolve(Paths.get("extra-rule1.sh")); Files.copy(Paths.get("src/test/resources/extra-rules/extra-rule1.sh"), copyFile); assertTrue((Boolean)method.invoke(sensor, tempDir)); assertFalse(tempDir.toFile().exists()); }