DefaultSessionService implements SessionService { @Override public User getUser() { Object principal = SecurityContextHolder.getContext().getAuthentication().getDetails(); LOG.info(MessageFormat.format("Getting session user: {0}", principal)); return ((Session) principal).getUser(); }  @Override User getUser(); @Override List<String> getRoles(); @Override List<String> getGroups(); @Override Group getDefaultGroup(); @Override void verifyGroup(final String title); @Override Session getSession();  }
@Test public void testGetUser() throws Exception { User expected = new User(); Session session = new Session(); session.setUser(expected); when(context.getAuthentication()).thenReturn(authentification); when(authentification.getDetails()).thenReturn(session); User actual = unit.getUser(); assertEquals(expected, actual); }