DynamicPath { public String resolve() { Timestamp timestamp = RuntimeProvider.createTimestamp(); StringBuilder builder = new StringBuilder(); for (Segment segment : segments) { builder.append(segment.createToken(builder.toString(), timestamp)); } return builder.toString(); } DynamicPath(final String path); String resolve(); List<FileTuple> getAllFiles(final String backupSuffix); boolean isValid(final File file);  }
@Test public void staticPath() throws IOException { File file = folder.newFile(); DynamicPath path = new DynamicPath(file.getAbsolutePath()); assertThat(path.resolve()).isEqualTo(file.getAbsolutePath()); }
@Test public void countToken() { String pattern = new File(folder.getRoot(), "{count}.log").getAbsolutePath(); DynamicPath path = new DynamicPath(pattern); assertThat(path.resolve()).isEqualTo(folder.getRoot() + File.separator + "0.log"); }
@Test @PrepareForTest(RuntimeProvider.class) public void defaultDateToken() throws Exception { setCurrentTime(LocalDateTime.of(1985, 6, 3, 12, 30, 55)); String pattern = new File(folder.getRoot(), "{date}.log").getAbsolutePath(); DynamicPath path = new DynamicPath(pattern); assertThat(path.resolve()).isEqualTo(folder.getRoot() + File.separator + "1985-06-03_12-30-55.log"); }
@Test @PrepareForTest(RuntimeProvider.class) public void customDateToken() throws Exception { setCurrentTime(LocalDateTime.of(1985, 6, 3, 12, 30, 55)); String pattern = new File(folder.getRoot(), "{date:yyyy}.log").getAbsolutePath(); DynamicPath path = new DynamicPath(pattern); assertThat(path.resolve()).isEqualTo(folder.getRoot() + File.separator + "1985.log"); }
@Test public void processIdToken() { String pattern = new File(folder.getRoot(), "{pid}.log").getAbsolutePath(); DynamicPath path = new DynamicPath(pattern); assertThat(path.resolve()).isEqualTo(folder.getRoot() + File.separator + RuntimeProvider.getProcessId() + ".log"); }
@Test public void multipleTokens() { DynamicPath path = new DynamicPath("{count}.{pid}"); assertThat(path.resolve()).isEqualTo("0." + RuntimeProvider.getProcessId()); }