PathCreator { public String replaceFileName(String path, final String fileName) { path = replace(path, "fileName", () -> fileName); path = replace(path, "fileStem", () -> { String fileStem = fileName; final int index = fileName.lastIndexOf("."); if (index != -1) { fileStem = fileName.substring(0, index); } return fileStem; }); path = replace(path, "fileExtension", () -> { String fileExtension = ""; final int index = fileName.lastIndexOf("."); if (index != -1) { fileExtension = fileName.substring(index + 1); } return fileExtension; }); return path; } @Inject  PathCreator(final TempDirProvider tempDirProvider); String replaceTimeVars(String path); String replaceSystemProperties(String path); String replaceUUIDVars(String path); String replaceFileName(String path, final String fileName); String[] findVars(final String path); String replace(final String path,
                          final String type,
                          final Supplier<String> replacementSupplier); String replaceAll(String path); String replaceContextVars(String path);  }
@Test void testReplaceFileName(@TempDir Path tempDir) { final PathCreator pathCreator = new PathCreator(() -> tempDir); assertThat(pathCreator.replaceFileName("${fileStem}.txt", "test.tmp")).isEqualTo("test.txt"); assertThat(pathCreator.replaceFileName("${fileStem}", "test.tmp")).isEqualTo("test"); assertThat(pathCreator.replaceFileName("${fileStem}", "test")).isEqualTo("test"); assertThat(pathCreator.replaceFileName("${fileExtension}", "test.tmp")).isEqualTo("tmp"); assertThat(pathCreator.replaceFileName("${fileExtension}", "test")).isEqualTo(""); assertThat(pathCreator.replaceFileName("${fileName}.txt", "test.tmp")).isEqualTo("test.tmp.txt"); }