### Question:
JsonPermissionConfiguration implements PermissionConfiguration { @Override public Set<Permission> getPermissionsForRoles(Collection<String> roles) { return rolePermissions.stream() .filter(rolePerm -> roles.contains(rolePerm.roleName)) .flatMap(rolePerm -> rolePerm.permissions.stream()) .collect(Collectors.toSet()); } JsonPermissionConfiguration(InputStream permissionConfig); @Override Set<Permission> getPermissionsForRoles(Collection<String> roles);  }### Answer:
@Test public void returnsThePermissionsOfTheRoles() throws Exception { String rolePermissions = "[" + "{\n" + "\t\"roleName\": \"USER\",\n" + "\t\"permissions\": [\"REMOVE_DATASET\"]\n" + "},\n" + "{\n" + "\t\"roleName\": \"ADMIN\",\n" + "\t\"permissions\": [\"IMPORT_DATA\"]\n" + "},\n" + "{\n" + "\t\"roleName\": \"OTHER_ROLE\",\n" + "\t\"permissions\": [\"EDIT_COLLECTION_METADATA\"]\n" + "}" + "]"; ByteArrayInputStream configuration = new ByteArrayInputStream(rolePermissions.getBytes()); JsonPermissionConfiguration instance = new JsonPermissionConfiguration(configuration); Set<Permission> permissions = instance.getPermissionsForRoles(Lists.newArrayList("USER", "ADMIN")); assertThat(permissions, containsInAnyOrder(Permission.REMOVE_DATASET, Permission.IMPORT_DATA)); }
@Test public void returnsNothingWhenNoRolesAreConfigured() throws Exception { ByteArrayInputStream configuration = new ByteArrayInputStream("[]".getBytes()); JsonPermissionConfiguration instance = new JsonPermissionConfiguration(configuration); Set<Permission> permissions = instance.getPermissionsForRoles(Lists.newArrayList("USER")); assertThat(permissions, is(empty())); }