ConfigHelper { public static File findLocalDirInPath(File startingPath) { try { File currentSearchFolder = startingPath.getCanonicalFile(); while (currentSearchFolder != null) { File possibleAppDir = new File(currentSearchFolder, Config.DIR_APPLICATION); File possibleConfigFile = new File(possibleAppDir, Config.FILE_CONFIG); if (possibleAppDir.exists() && possibleConfigFile.exists()) { return possibleAppDir.getParentFile().getCanonicalFile(); } currentSearchFolder = currentSearchFolder.getParentFile(); } return null; } catch (IOException e) { throw new RuntimeException("Unable to determine local directory starting from: "+startingPath, e); } }  static Config loadConfig(File localDir); static boolean configExists(File localDir); static ConfigTO loadConfigTO(File localDir); static RepoTO loadRepoTO(File localDir, ConfigTO configTO); static File findLocalDirInPath(File startingPath);  }
@Test public void testConfigHelperFindLocalDirInPath() throws Exception { Config testConfig = TestConfigUtil.createTestLocalConfig(); File startingPath = testConfig.getLocalDir(); File actualLocalDir = ConfigHelper.findLocalDirInPath(startingPath); assertNotNull(actualLocalDir); assertEquals(testConfig.getLocalDir(), actualLocalDir.getCanonicalFile()); TestConfigUtil.deleteTestLocalConfigAndData(testConfig); }
@Test public void testConfigHelperFindLocalDirInPathNotExistent() throws IOException { File startingPath = EnvironmentUtil.isWindows() ? new File("C:\\does\\not\\exist") : new File("/does/not/exist"); File actualLocalDir = ConfigHelper.findLocalDirInPath(startingPath); assertNull(actualLocalDir); }
@Test public void testConfigHelperFindLocalDirInPathTwoLevelsDown() throws Exception { Config testConfig = TestConfigUtil.createTestLocalConfig(); new File(testConfig.getAppDir()+"/some/folder").mkdirs(); File startingPath = new File(testConfig.getAppDir()+"/some/folder"); File actualLocalDir = ConfigHelper.findLocalDirInPath(startingPath); assertNotNull(actualLocalDir); assertEquals(testConfig.getLocalDir(), actualLocalDir.getCanonicalFile()); TestConfigUtil.deleteTestLocalConfigAndData(testConfig); }