DefaultSessionService implements SessionService { @Override public List<String> getGroups() { List<String> groups = new ArrayList<>(); User user = getUser(); for (Group group : user.getGroups()) { groups.add(group.getTitle()); } return groups; }  @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 testGetGroups() throws Exception { String groupTitle1 = "developers"; Group group1 = new Group(); group1.setTitle(groupTitle1); String groupTitle2 = "users"; Group group2 = new Group(); group2.setTitle(groupTitle2); List<Group> groups = Arrays.asList(group1, group2); User user = new User(); user.setGroups(groups); Session session = new Session(); session.setUser(user); List<String> expected = Arrays.asList(groupTitle1, groupTitle2); when(context.getAuthentication()).thenReturn(authentification); when(authentification.getDetails()).thenReturn(session); List<String> actual = unit.getGroups(); assertEquals(expected, actual); }