AuthenticationUtil { public static long getAuthenticationCreationTime(HttpSession session) { Long time = (Long) session.getAttribute(AUTHENTICATION_CREATION_TIME); if (time != null) { long seconds = TimeUnit.SECONDS.convert(time, TimeUnit.MILLISECONDS); return TimeUnit.MILLISECONDS.convert(seconds, TimeUnit.SECONDS); } else { return 0; } } private  AuthenticationUtil(); static void setAuthenticationCreationTime(HttpSession session, long time); static long getAuthenticationCreationTime(HttpSession session);  }
@Test public void getAuthenticationCreationTime() { Calendar c = new GregorianCalendar(2012, Calendar.JUNE, 17); c.set(Calendar.MILLISECOND, 123); long time = c.getTimeInMillis(); when(session.getAttribute("authenticationCreationTime")).thenReturn(time); assertEquals(time / 1000L * 1000L, AuthenticationUtil.getAuthenticationCreationTime(session)); }