SessionConverter extends AbstractConverter<Session, SessionResource> { @Override public SessionResource convert(final Session source, final SessionResource target) { List<String> roles = getRoles(source); List<String> groups = getGroups(source); target.setGroups(groups); target.setRoles(roles); if (source.getUser() != null) { target.setLogin(source.getUser().getLogin()); } return target; }  @Override SessionResource convert(final Session source, final SessionResource target); @Override SessionResource convert(final Session source);  }
@Test public void testConvert() throws Exception { String group1Title = "group1"; String group2Title = "group2"; Group group1 = new Group(); group1.setTitle(group1Title); Group group2 = new Group(); group2.setTitle(group2Title); Role role1 = new Role(); String role1String = "role1"; role1.setTitle(role1String); String role2String = "role2"; Role role2 = new Role(); role2.setTitle(role2String); String login = "login"; User user = new User(); user.setLogin(login); Session session = new Session(); session.setUser(user); session.setGroups(Arrays.asList(group1, group2)); session.setRoles(Arrays.asList(role1, role2)); List<String> groupStrings = Arrays.asList(group1Title, group2Title); List<String> roleStrings = Arrays.asList(role1String,role2String); SessionResource expected = new SessionResource(); expected.setLogin(login); expected.setGroups(groupStrings); expected.setRoles(roleStrings); SessionResource actual = unit.convert(session); assertEquals(expected, actual); }