final User currentUser = mgr.getUserManager().getCurrentUser();
membershipManager.createMembershipForUser(project.getId(), currentUser.getId(), roles);
final List<Membership> memberships1 = membershipManager.getMemberships(project.getIdentifier());
assertEquals(1, memberships1.size());
final Membership createdMembership = memberships1.get(0);
assertEquals(currentUser.getId(), createdMembership.getUser()
.getId());
assertEquals(roles.size(), createdMembership.getRoles().size());
final Membership membershipById = membershipManager.getMembership(createdMembership
.getId());
assertEquals(createdMembership, membershipById);
final Membership emptyMembership = MembershipFactory.create(createdMembership.getId());
emptyMembership.setProject(createdMembership.getProject());
emptyMembership.setUser(createdMembership.getUser());
emptyMembership.addRoles(Collections.singletonList(roles.get(0)));
membershipManager.update(emptyMembership);
final Membership updatedEmptyMembership = membershipManager.getMembership(createdMembership.getId());
assertEquals(1, updatedEmptyMembership.getRoles().size());
membershipManager.delete(updatedEmptyMembership);
}