FileUtil { public static File getSessionDirectory(String sessionId) { String dirBase = PropertyUtil.getProperty(SESSION_DIR_BASE_KEY); if (dirBase == null || "".equals(dirBase)) { dirBase = File.separator + "temp"; } String dirName = getSessionDirectoryName(sessionId); return new File(dirBase + File.separator + dirName); }  static String getSessionDirectoryName(String sessionId); static File getSessionDirectory(String sessionId); static boolean makeSessionDirectory(String sessionId); static boolean removeSessionDirectory(String sessionId); static boolean rmdirs(File dir);  }
@Test public void testGetSessionDirectory01() throws Exception { String input = "01234567abcdefgh"; File result = FileUtil.getSessionDirectory(input); String dirName = StringUtil.toHexString(HashUtil.hashSHA1(input), ""); File hope = new File(TMP_SESSIONS_DIR + dirName); assertEquals(hope, result); }
@Test public void testGetSessionDirectory02() throws Exception { String input = null; try { FileUtil.getSessionDirectory(input); fail(); } catch (NullPointerException e) { return; } }
@Test public void testGetSessionDirectory03() throws Exception { String input = ""; File result = FileUtil.getSessionDirectory(input); String dirName = StringUtil.toHexString(HashUtil.hashSHA1(input), ""); File hope = new File(TMP_SESSIONS_DIR + dirName); assertEquals(hope, result); }
@Test public void testGetSessionDirectory04() throws Exception { String input = "01234567abcdefgh"; deleteProperty("session.dir.base"); File result = FileUtil.getSessionDirectory(input); String dirName = StringUtil.toHexString(HashUtil.hashSHA1(input), ""); File hope = new File(File.separator + "temp" + File.separator + dirName); assertEquals(hope, result); }
@Test public void testGetSessionDirectory05() throws Exception { String input = "01234567abcdefgh"; deleteProperty("session.dir.base"); addProperty("session.dir.base", ""); File result = FileUtil.getSessionDirectory(input); String dirName = StringUtil.toHexString(HashUtil.hashSHA1(input), ""); File hope = new File(File.separator + "temp" + File.separator + dirName); assertEquals(hope, result); }