@Test public void processExistingFilesShouldProcessOneFile(@Mocked DirectoryStream<Path> mockDirectoryStream, @Mocked Iterator<Path> mockIterator) { try { new Expectations(Files.class) { { Files.newDirectoryStream((Path) any); result = mockDirectoryStream; mockDirectoryStream.iterator(); result = mockIterator; mockIterator.hasNext(); returns(true, false); mockIterator.next(); returns(mockFile, null); } }; } catch (IOException e) { fail("Unexpected exception in expectations block: " + e); } testImporterProcessor.processDirectory(injectableDir, injectableBackupDir, injectableFailureDir); }
public int processDirectory(Path dir, Path backupDir, Path failureDir) { int count = 0; try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path entry : stream) { if (entry.toFile().isDirectory()) { processDirectory(entry, backupDir, failureDir); } else { logger.debug("Found a file to process: {}", entry.getFileName()); processAndBackupFile(entry, backupDir, failureDir); count++; } } } catch (Exception e) { logger.error("Error processing files.", e); } return count; }
ImporterProcessor { public int processDirectory(Path dir, Path backupDir, Path failureDir) { int count = 0; try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path entry : stream) { if (entry.toFile().isDirectory()) { processDirectory(entry, backupDir, failureDir); } else { logger.debug("Found a file to process: {}", entry.getFileName()); processAndBackupFile(entry, backupDir, failureDir); count++; } } } catch (Exception e) { logger.error("Error processing files.", e); } return count; } }
ImporterProcessor { public int processDirectory(Path dir, Path backupDir, Path failureDir) { int count = 0; try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path entry : stream) { if (entry.toFile().isDirectory()) { processDirectory(entry, backupDir, failureDir); } else { logger.debug("Found a file to process: {}", entry.getFileName()); processAndBackupFile(entry, backupDir, failureDir); count++; } } } catch (Exception e) { logger.error("Error processing files.", e); } return count; } ImporterProcessor(OdeProperties odeProperties, ImporterFileType fileType); }
ImporterProcessor { public int processDirectory(Path dir, Path backupDir, Path failureDir) { int count = 0; try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path entry : stream) { if (entry.toFile().isDirectory()) { processDirectory(entry, backupDir, failureDir); } else { logger.debug("Found a file to process: {}", entry.getFileName()); processAndBackupFile(entry, backupDir, failureDir); count++; } } } catch (Exception e) { logger.error("Error processing files.", e); } return count; } ImporterProcessor(OdeProperties odeProperties, ImporterFileType fileType); int processDirectory(Path dir, Path backupDir, Path failureDir); void processAndBackupFile(Path filePath, Path backupDir, Path failureDir); }
ImporterProcessor { public int processDirectory(Path dir, Path backupDir, Path failureDir) { int count = 0; try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path entry : stream) { if (entry.toFile().isDirectory()) { processDirectory(entry, backupDir, failureDir); } else { logger.debug("Found a file to process: {}", entry.getFileName()); processAndBackupFile(entry, backupDir, failureDir); count++; } } } catch (Exception e) { logger.error("Error processing files.", e); } return count; } ImporterProcessor(OdeProperties odeProperties, ImporterFileType fileType); int processDirectory(Path dir, Path backupDir, Path failureDir); void processAndBackupFile(Path filePath, Path backupDir, Path failureDir);  }