FileUtils { public static String expandUserHome(final String path) { if (path.startsWith("~/") || path.startsWith("~\\")) { return System.getProperty("user.home") + correctPath(SystemUtils.IS_OS_WINDOWS, path.substring(1)); } else { return path; } }  static String expandUserHome(final String path);  }
@Test public void expandUserHome_tildeNoHomeShortcut() { assertEquals("~foo/bar", FileUtils.expandUserHome("~foo/bar")); }
@Test public void expandUserHome_noHomeShortcut() { assertEquals("/foo/bar", FileUtils.expandUserHome("/foo/bar")); }
@Test public void expandUserHome_withHomeShortcut() { String homeDir = System.getProperty("user.home"); String expandedPath = FileUtils.expandUserHome("~/foobar"); if (SystemUtils.IS_OS_WINDOWS) { assertEquals(homeDir + "\\foobar", expandedPath); } else { assertEquals(homeDir + "/foobar", expandedPath); } }