DynamicPath { public boolean isValid(final File file) { return isValid(file.getAbsolutePath(), 0, 0); } DynamicPath(final String path); String resolve(); List<FileTuple> getAllFiles(final String backupSuffix); boolean isValid(final File file);  }
@Test public void validateFileWithExtension() { String pattern = new File(folder.getRoot(), "{count}.log").getAbsolutePath(); DynamicPath path = new DynamicPath(pattern); assertThat(path.isValid(new File(folder.getRoot(), "42.log"))).isTrue(); }
@Test public void validateFileWithoutExtension() { String pattern = new File(folder.getRoot(), "{count}").getAbsolutePath(); DynamicPath path = new DynamicPath(pattern); assertThat(path.isValid(new File(folder.getRoot(), "42"))).isTrue(); }
@Test public void validateFileWithPrefix() { String pattern = new File(folder.getRoot(), "log_{count}.txt").getAbsolutePath(); DynamicPath path = new DynamicPath(pattern); assertThat(path.isValid(new File(folder.getRoot(), "log_42.txt"))).isTrue(); }
@Test public void validateFileWithMultiplePatterns() { String pattern = new File(folder.getRoot(), "{date:YYYY}_{count}.log").getAbsolutePath(); DynamicPath path = new DynamicPath(pattern); assertThat(path.isValid(new File(folder.getRoot(), "2018_0.log"))).isTrue(); }
@Test public void validateFileInCurrentDirectory() { DynamicPath path = new DynamicPath("log_{count}.tmp"); assertThat(path.isValid(new File("log_42.tmp"))).isTrue(); }
@Test public void validateFileWithRelativeFolder() { DynamicPath path = new DynamicPath("test/log_{count}.tmp"); assertThat(path.isValid(new File("test/log_42.tmp"))).isTrue(); }
@Test public void validateFileFromOtherFolder() { String pattern = new File(folder.getRoot(), "{count}").getAbsolutePath(); DynamicPath path = new DynamicPath(pattern); assertThat(path.isValid(new File(folder.getRoot().getParentFile(), "42"))).isFalse(); }
@Test public void validateFileWithWrongSeparator() { String pattern = new File(folder.getRoot(), "{date:YYYY}.{count}.log").getAbsolutePath(); DynamicPath path = new DynamicPath(pattern); assertThat(path.isValid(new File(folder.getRoot(), "2018_42.log"))).isFalse(); }
@Test public void validateFileWithWrongPrefix() { String pattern = new File(folder.getRoot(), "log_{count}.txt").getAbsolutePath(); DynamicPath path = new DynamicPath(pattern); assertThat(path.isValid(new File(folder.getRoot(), "test_42.txt"))).isFalse(); }