### Question:
FilePathResolver { public File resolvePathToFile(String path) { path = resolveVariables(path); if (path.contains("/") || path.contains("\\")) { path = path.replace("/", File.separator); path = path.replace("\\", File.separator); } if (path.startsWith("~" + File.separator)) { path = new File(homeDir, path.substring(2)).getAbsolutePath(); } if (!new File(path).isAbsolute()) { path = new File(workingDir, path).getAbsolutePath(); } String[] tokens = path.split(Pattern.quote(File.separator)); LinkedList<String> finalTokens = new LinkedList<>(); for (String token : tokens) { if (token.equals("..")) { if (!finalTokens.isEmpty()) { finalTokens.removeLast(); } } else if (!token.equals(".")) { finalTokens.addLast(token); } } return new File(File.separator + Joiner.on(File.separator).join(finalTokens)); } @Inject  FilePathResolver();   FilePathResolver(File homeDir, File workingDir, @Nullable File cdapHomeDir); File resolvePathToFile(String path); static final String CDAP_HOME; }### Answer:
@Test public void testResolve() { File homeDir = new File("/home/bob"); File workingDir = new File("/working/dir"); File cdapHomeDir = new File("/opt/cdap"); FilePathResolver resolver = new FilePathResolver(homeDir, workingDir, cdapHomeDir); File file = resolver.resolvePathToFile("~/~t~est..1~123"); File expectedFile = new File(homeDir, "~t~est..1~123"); Assert.assertEquals(expectedFile, file); file = resolver.resolvePathToFile("~/123/../~t~est..1~123"); expectedFile = new File(homeDir, "~t~est..1~123"); Assert.assertEquals(expectedFile, file); file = resolver.resolvePathToFile("/../~t~est..1~123"); expectedFile = new File("/~t~est..1~123"); Assert.assertEquals(expectedFile, file); file = resolver.resolvePathToFile("/../../~t~est..1~123"); expectedFile = new File("/~t~est..1~123"); Assert.assertEquals(expectedFile, file); file = resolver.resolvePathToFile("/./~t~est..1~123"); expectedFile = new File("/~t~est..1~123"); Assert.assertEquals(expectedFile, file); file = resolver.resolvePathToFile("~t~est..1~123"); expectedFile = new File(workingDir, "~t~est..1~123"); Assert.assertEquals(expectedFile, file); file = resolver.resolvePathToFile("123/../~t~est..1~123"); expectedFile = new File(workingDir, "~t~est..1~123"); Assert.assertEquals(expectedFile, file); file = resolver.resolvePathToFile("$CDAP_HOME/sdf"); expectedFile = new File(cdapHomeDir, "sdf"); Assert.assertEquals(expectedFile, file); file = resolver.resolvePathToFile("$CDAP_HOME-ff/sdf"); expectedFile = new File(cdapHomeDir.getAbsolutePath() + "-ff", "sdf"); Assert.assertEquals(expectedFile, file); file = resolver.resolvePathToFile("$CDAP_HOME_/sdf"); expectedFile = new File(workingDir, "$CDAP_HOME_/sdf"); Assert.assertEquals(expectedFile, file); file = resolver.resolvePathToFile("$CDAP_HOME9/sdf"); expectedFile = new File(workingDir, "$CDAP_HOME9/sdf"); Assert.assertEquals(expectedFile, file); file = resolver.resolvePathToFile("$CDAP_HOMEf/sdf"); expectedFile = new File(workingDir, "$CDAP_HOMEf/sdf"); Assert.assertEquals(expectedFile, file); file = resolver.resolvePathToFile("$CDAP_HOMEF/sdf"); expectedFile = new File(workingDir, "$CDAP_HOMEF/sdf"); Assert.assertEquals(expectedFile, file); }