### Question:
UserService implements UserDetailsService { public Map<String, List<BRole>> getRolesForUser(final Long id) throws NotFoundEntityException { EUser u = getUser(id); return authorizationRepository.getRolesForUserOverAllEntities(u.getId()); }  EUser createDefaultUser(); EUser signUp(final EUser u, final EmailStatus emailStatus); EUser signUp(final EUser u, final EmailStatus emailStatus,
                        final RegistrationPrivilege registrationPrivilege); List<Long> addRolesToUser(final Long userId, final Long entityId,
                                     final Iterable<Long> rolesId); List<Long> removeRolesFromUser(final Long userId, final Long entityId, final Iterable<Long> rolesId); @Override UserDetails loadUserByUsername(final String usernameOrEmail); String getUserAuthoritiesForToken(final String usernameOrEmail, final String separator); Map<String, List<BRole>> getRolesForUser(final Long id); List<BRole> getRolesForUserOverEntity(final Long userId, final Long entityId); Long getEntityIdByUser(final EUser u);  }### Answer:
@Test public void getRolesForUser() { EUser u = userRepository.save(EntityUtil.getSampleUser(random.nextString())); assertNotNull(u); EOwnedEntity e1 = entityRepository.save(EntityUtil.getSampleEntity(random.nextString())); assertNotNull(e1); EOwnedEntity e2 = entityRepository.save(EntityUtil.getSampleEntity(random.nextString())); assertNotNull(e2); BRole r1 = roleRepository.save(EntityUtil.getSampleRole(random.nextString())); assertNotNull(r1); BRole r2 = roleRepository.save(EntityUtil.getSampleRole(random.nextString())); assertNotNull(r2); BRole r3 = roleRepository.save(EntityUtil.getSampleRole(random.nextString())); assertNotNull(r3); BRole r4 = roleRepository.save(EntityUtil.getSampleRole(random.nextString())); assertNotNull(r4); BAuthorization.BAuthorizationPk pk1 = new BAuthorization.BAuthorizationPk(u.getId(), e1.getId(), r1.getId()); BAuthorization auth1 = authorizationRepository.save(new BAuthorization(pk1, u, e1, r1)); assertNotNull(auth1); BAuthorization.BAuthorizationPk pk2 = new BAuthorization.BAuthorizationPk(u.getId(), e1.getId(), r2.getId()); BAuthorization auth2 = authorizationRepository.save(new BAuthorization(pk2, u, e1, r2)); assertNotNull(auth2); BAuthorization.BAuthorizationPk pk3 = new BAuthorization.BAuthorizationPk(u.getId(), e2.getId(), r3.getId()); BAuthorization auth3 = authorizationRepository.save(new BAuthorization(pk3, u, e2, r3)); assertNotNull(auth3); BAuthorization.BAuthorizationPk pk4 = new BAuthorization.BAuthorizationPk(u.getId(), e2.getId(), r4.getId()); BAuthorization auth4 = authorizationRepository.save(new BAuthorization(pk4, u, e2, r4)); assertNotNull(auth4); try { final Map<String, List<BRole>> rolesForUser = userService.getRolesForUser(u.getId()); assertNotNull(rolesForUser); assertFalse(rolesForUser.isEmpty()); final Set<String> keySet = rolesForUser.keySet(); assertTrue(keySet.contains(e1.getUsername())); assertTrue(keySet.contains(e2.getUsername())); assertTrue(rolesForUser.get(e1.getUsername()).contains(r1)); assertTrue(rolesForUser.get(e1.getUsername()).contains(r2)); assertTrue(rolesForUser.get(e2.getUsername()).contains(r3)); assertTrue(rolesForUser.get(e2.getUsername()).contains(r4)); } catch (NotFoundEntityException e) { LOGGER.error(e.getLocalizedMessage()); fail("The username was not found"); } }