@Test public void testSyncSenderLogger() throws IOException { senderLogger = new SyncSenderLogger( new File(config.getSenderFolderPath(), SyncConstant.SYNC_LOG_NAME)); Set<String> deletedFileNames = new HashSet<>(); Set<String> deletedFileNamesTest = new HashSet<>(); senderLogger.startSyncDeletedFilesName(); for (int i = 0; i < 100; i++) { senderLogger .finishSyncDeletedFileName(new File(config.getSenderFolderPath(), "deleted" + i)); deletedFileNames .add(new File(config.getSenderFolderPath(), "deleted" + i).getAbsolutePath()); } Set<String> toBeSyncedFiles = new HashSet<>(); Set<String> toBeSyncedFilesTest = new HashSet<>(); senderLogger.startSyncTsFiles(); for (int i = 0; i < 100; i++) { senderLogger .finishSyncTsfile(new File(config.getSenderFolderPath(), "new" + i)); toBeSyncedFiles .add(new File(config.getSenderFolderPath(), "new" + i).getAbsolutePath()); } senderLogger.close(); int count = 0; int mode = 0; try (BufferedReader br = new BufferedReader( new FileReader(new File(config.getSenderFolderPath(), SyncConstant.SYNC_LOG_NAME)))) { String line; while ((line = br.readLine()) != null) { count++; if (line.equals(SyncSenderLogger.SYNC_DELETED_FILE_NAME_START)) { mode = -1; } else if (line.equals(SyncSenderLogger.SYNC_TSFILE_START)) { mode = 1; } else { if (mode == -1) { deletedFileNamesTest.add(line); } else if (mode == 1) { toBeSyncedFilesTest.add(line); } } } } assertEquals(202, count); assertEquals(deletedFileNames.size(), deletedFileNamesTest.size()); assertEquals(toBeSyncedFiles.size(), toBeSyncedFilesTest.size()); assertTrue(deletedFileNames.containsAll(deletedFileNamesTest)); assertTrue(toBeSyncedFiles.containsAll(toBeSyncedFilesTest)); }
public SyncSenderLogger(File file) throws IOException { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } this.bw = new BufferedWriter(new FileWriter(file.getAbsolutePath())); }
SyncSenderLogger implements ISyncSenderLogger { public SyncSenderLogger(File file) throws IOException { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } this.bw = new BufferedWriter(new FileWriter(file.getAbsolutePath())); } }
SyncSenderLogger implements ISyncSenderLogger { public SyncSenderLogger(File file) throws IOException { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } this.bw = new BufferedWriter(new FileWriter(file.getAbsolutePath())); } SyncSenderLogger(File file); }
SyncSenderLogger implements ISyncSenderLogger { public SyncSenderLogger(File file) throws IOException { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } this.bw = new BufferedWriter(new FileWriter(file.getAbsolutePath())); } SyncSenderLogger(File file); @Override void startSyncDeletedFilesName(); @Override void finishSyncDeletedFileName(File file); @Override void startSyncTsFiles(); @Override void finishSyncTsfile(File file); @Override void close(); }
SyncSenderLogger implements ISyncSenderLogger { public SyncSenderLogger(File file) throws IOException { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } this.bw = new BufferedWriter(new FileWriter(file.getAbsolutePath())); } SyncSenderLogger(File file); @Override void startSyncDeletedFilesName(); @Override void finishSyncDeletedFileName(File file); @Override void startSyncTsFiles(); @Override void finishSyncTsfile(File file); @Override void close();  }