DefaultGroupService implements GroupService { @Override public void leave(Group group, User user) { final Membership membership = membershipRepository.findByUserAndGroup(user, group); if (membership == null) { return; } membershipRepository.delete(membership); } DefaultGroupService(GroupRepository groupRepository, MembershipRepository membershipRepository); @Override Group createGroup(String name); @Override void deleteGroup(Group group); @Override void join(Group group, User user); @Override void leave(Group group, User user); @Override List<User> members(Group group); @Override List<Group> groups(User user);  }
@Test public void testBreakingAMembership() { Group group = new Group(); group.setName("My Group"); group = groupRepository.save(group); final User user = userService.createUser("milad", "milad@domain.com", "123456"); final Membership membership = new Membership(); membership.setUser(user); membership.setGroup(group); membershipRepository.save(membership); service.leave(group, user); assertThat(membershipRepository.count(), is(0L)); }