LogFilter { public boolean acceptsFile(Path file) { if (startDate == null) { return true; } return getEndTimeOf(file).isAfter(startDate); } LogFilter(Level logLevel, LocalDateTime startDate, LocalDateTime endDate);  LogFilter(Level logLevel, boolean thisLevelOnly, LocalDateTime startDate,
      LocalDateTime endDate); void startNewFile(); LineFilterResult acceptsLine(String logLine); boolean acceptsFile(Path file);  }
@Test public void testAcceptFileWithCreateTimeNotAvailale() { Path path = mock(Path.class); when(path.toFile()).thenReturn(mock(File.class)); when(path.toFile().lastModified()).thenReturn(System.currentTimeMillis()); when(path.getFileSystem()).thenThrow(SecurityException.class); LogFilter filter = new LogFilter(Level.INFO, null, null); assertThat(filter.acceptsFile(path)).isTrue(); filter = new LogFilter(Level.INFO, LocalDateTime.now(), null); assertThat(filter.acceptsFile(path)).isFalse(); filter = new LogFilter(Level.INFO, LocalDateTime.now().minusHours(1), null); assertThat(filter.acceptsFile(path)).isTrue(); filter = new LogFilter(Level.INFO, null, LocalDateTime.now()); assertThat(filter.acceptsFile(path)).isTrue(); filter = new LogFilter(Level.INFO, null, LocalDateTime.now().minusHours(1)); assertThat(filter.acceptsFile(path)).isTrue(); }
@Test public void testAcceptFileWithCreateTimeAvailable() throws Exception { Path path = mock(Path.class); when(path.toFile()).thenReturn(mock(File.class)); when(path.toFile().lastModified()).thenReturn(System.currentTimeMillis()); BasicFileAttributes attributes = mock(BasicFileAttributes.class); when(path.getFileSystem()).thenReturn(mock(FileSystem.class)); when(path.getFileSystem().provider()).thenReturn(mock(FileSystemProvider.class)); when(path.getFileSystem().provider().readAttributes(path, BasicFileAttributes.class)) .thenReturn(attributes); LogFilter filter = new LogFilter(Level.INFO, null, null); assertThat(filter.acceptsFile(path)).isTrue(); filter = new LogFilter(Level.INFO, LocalDateTime.now(), null); assertThat(filter.acceptsFile(path)).isFalse(); filter = new LogFilter(Level.INFO, LocalDateTime.now().minusHours(1), null); assertThat(filter.acceptsFile(path)).isTrue(); filter = new LogFilter(Level.INFO, null, LocalDateTime.now()); assertThat(filter.acceptsFile(path)).isTrue(); filter = new LogFilter(Level.INFO, null, LocalDateTime.now().minusHours(1)); assertThat(filter.acceptsFile(path)).isTrue(); }