DataDirectoryLocator { public File locate() { String os = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); String path; if (os.contains("mac")) { path = System.getProperty("user.home") + "/Library/Application Support/" + APP_DIR; } else if (os.contains("windows")) { String appData = System.getenv("APPDATA"); if (Strings.isNullOrEmpty(appData)) { appData = System.getProperty("user.home") + "AppData\\Roaming"; } path = appData + "\\" + APP_DIR; } else { throw new IllegalStateException(os); } if (Demo.isEnabled()) { path += "-demo"; } return new File(path); }  File locate();  }
@Test public void getDataDirectory() { File file = new DataDirectoryLocator().locate(); if (isMac()) { assertEquals(System.getProperty("user.home") + "/Library/Application Support/GreensOpinionFinance", file.getPath()); } else if (isWindows()) { assertEquals(System.getProperty("user.home") + "\\AppData\\Roaming\\GreensOpinionFinance", file.getPath()); } else { fail("Unsupported os: " + System.getProperty("os.name")); } assertTrue(file.getParentFile().exists()); assertTrue(file.getParentFile().isDirectory()); }