### Question:
RoleService { public List<Long> updatePermissionsInRole(final long roleId, final Iterable<Long> permissionsId) throws NotFoundEntityException { return addRemovePermissionToFromRole(roleId, permissionsId, ActionOverRolePermissions.UPDATE_PERMISSIONS); }  BRole createDefaultRole(); List<Long> addPermissionsToRole(final long roleId, final Iterable<Long> permissionsId); List<Long> removePermissionsFromRole(final long roleId, final Iterable<Long> permissionsId); List<Long> updatePermissionsInRole(final long roleId, final Iterable<Long> permissionsId); BRole getRole(final long id); Page<BPermission> getAllPermissionsByRoleId(final long id, final Pageable pageable); static final String ROLE_NOT_FOUND; }### Answer:
@Test @Transactional public void updatePermissionsInRole() { BPermission p1 = permissionRepository.save(EntityUtil.getSamplePermission(random.nextString())); assertNotNull(p1); BPermission p2 = permissionRepository.save(EntityUtil.getSamplePermission(random.nextString())); assertNotNull(p2); BRole r = EntityUtil.getSampleRole(random.nextString()); r.addPermission(p1, p2); assertNotNull(roleRepository.save(r)); assertTrue(r.getPermissions().contains(p1)); assertTrue(r.getPermissions().contains(p2)); BPermission p3 = permissionRepository.save(EntityUtil.getSamplePermission(random.nextString())); assertNotNull(p3); BPermission p4 = permissionRepository.save(EntityUtil.getSamplePermission(random.nextString())); assertNotNull(p4); Collection<Long> pIDs = new LinkedList<>(); pIDs.add(p3.getId()); pIDs.add(p4.getId()); try { final List<Long> updated = roleService.updatePermissionsInRole(r.getId(), pIDs); assertNotNull(updated); assertEquals(updated.size(), pIDs.size()); assertTrue(updated.contains(p3.getId())); assertTrue(updated.contains(p4.getId())); assertFalse(updated.contains(p1.getId())); assertFalse(updated.contains(p2.getId())); Optional<BRole> role = roleRepository.findById(r.getId()); assertTrue(role.isPresent()); final Set<BPermission> rPermissions = role.get().getPermissions(); assertFalse(rPermissions.contains(p1)); assertFalse(rPermissions.contains(p2)); assertTrue(rPermissions.contains(p3)); assertTrue(rPermissions.contains(p4)); } catch (NotFoundEntityException e) { LOGGER.error(e.getLocalizedMessage()); fail("Could not update the role permissions"); } }