userGroup.setName("usergroup name");
userGroup.setUsers(users);
userGroup.setStatus(Status.SUCCESS);
// do mapping
UserGroupPrime userGroupPrime = mapper.map(userGroup, UserGroupPrime.class);
// prove access to generic type information
Method setter = UserGroupPrime.class.getMethod("setUsers", List.class);
Type[] parameterTypes = setter.getGenericParameterTypes();
assertEquals(1, parameterTypes.length);
ParameterizedType parameterType = (ParameterizedType) parameterTypes[0];
assertEquals(List.class, parameterType.getRawType());
assertEquals(UserPrime.class, parameterType.getActualTypeArguments()[0]);
// check group
assertNotNull(userGroupPrime);
assertEquals(userGroup.getName(), userGroupPrime.getName());
// check resulting collection
List<?> usersPrime = userGroupPrime.getUsers();
assertNotNull(usersPrime);
assertEquals(2, usersPrime.size());
assertTrue("Expecting instance of UserPrime.", usersPrime.get(0) instanceof UserPrime);
assertTrue("Expecting instance of UserPrime.", usersPrime.get(1) instanceof UserPrime);
assertEquals("SUCCESS", userGroupPrime.getStatusPrime().name());
// Map the other way
UserGroup userGroupMapBack = mapper.map(userGroupPrime, UserGroup.class);
Set<?> usersGroupPrime = userGroupMapBack.getUsers();
assertNotNull(usersGroupPrime);