DefaultGroupService implements GroupService { @Override public List<User> members(Group group) { final List<Membership> memberships = membershipRepository.findByGroup(group); final List<User> users = new ArrayList<>(); for (Membership membership : memberships) { users.add(membership.getUser()); } return users; } 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 testListingGroupMembers() { 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); final List<User> users = service.members(group); assertThat(users, is(notNullValue())); assertThat(users, hasSize(1)); assertThat(users.get(0), is(notNullValue())); assertThat(users.get(0).getId(), is(user.getId())); }