Util { public static String getSessionBaseDir() throws IllegalArgumentException { String basePath = getAbsRootDir(); if (DshipContext.INSTANCE.get(Constants.SESSION_DIR) != null) { try { basePath = URLDecoder.decode(DshipContext.INSTANCE.get(Constants.SESSION_DIR), "UTF-8"); } catch (UnsupportedEncodingException e) { } } File baseDir = new File(basePath); if (!baseDir.exists()) { baseDir.mkdirs(); } else if (baseDir.isFile()) { throw new IllegalArgumentException("SessionDir must be directory, now is a file."); } return basePath; }  static String getAbsRootDir(); static String getSessionBaseDir(); static String getSessionDir(String sid); static String getStack(Exception e); static File[] sortFiles(File[] fs); static void checkSession(String sid); static boolean isWindows(); static String toHumanReadableString(String in); static boolean isIgnoreCharset(String charset); static String toReadableBytes(long bytes); static String toReadableMilliseconds(long millis); static String toReadableNumber(long number); static String pluralize(String word, long count);  }
@Test public void testGetSessionBaseDir() { String path = Util.getSessionBaseDir(); System.err.println(path); String sessionDir = path + "/custom_session_dir" + System.currentTimeMillis(); DshipContext.INSTANCE.put(Constants.SESSION_DIR, sessionDir); assertEquals("custom_session_dir", sessionDir, Util.getSessionBaseDir()); assertTrue("custom_session_dir", (new File(sessionDir).exists())); DshipContext.INSTANCE.remove(Constants.SESSION_DIR); try { String sessionFile = path + "/custom_session_file" + System.currentTimeMillis(); File file = new File(sessionFile); file.createNewFile(); DshipContext.INSTANCE.put(Constants.SESSION_DIR, sessionFile); Util.getSessionBaseDir(); fail("custom session dir can't be file"); } catch (Exception e) { DshipContext.INSTANCE.remove(Constants.SESSION_DIR); } DshipContext.INSTANCE.remove(Constants.SESSION_DIR); }