ImmutableResources implements Resources { public static ImmutableResources of(final Iterable<Resource> resources) { checkNotNull(resources, "resources"); final Map<ResourceKey, Resource> resourcesMap = new HashMap<>(); resources.forEach(resource -> { final Resource existingResource = resourcesMap.put(resource.getResourceKey(), resource); if (null != existingResource) { final String msgTemplate = "There is more than one Resource with the path <{0}>!"; throw new IllegalArgumentException(MessageFormat.format(msgTemplate, resource.getPath())); } }); return new ImmutableResources(resourcesMap); } private  ImmutableResources(final Map<ResourceKey, Resource> theResources); static ImmutableResources of(final Iterable<Resource> resources); static Resources fromJson(final JsonObject jsonObject); @Override Optional<Resource> getResource(final ResourceKey resourceKey); @Override Resources setResource(final Resource resource); @Override Resources removeResource(final ResourceKey resourceKey); @Override int getSize(); @Override boolean isEmpty(); @Override JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate); @Override Iterator<Resource> iterator(); @Override Stream<Resource> stream(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test(expected = IllegalArgumentException.class) public void createResourcesWithSamePathsShouldFail() { final Collection<Resource> resourceList = new ArrayList<>(); resourceList.add(Resource.newInstance(ResourceKey.newInstance(RESOURCE_TYPE, KNOWN_RESOURCE_PATH_1), EffectedPermissions.newInstance(PERMISSIONS_ALL, PoliciesModelFactory.noPermissions()))); resourceList.add(Resource.newInstance(ResourceKey.newInstance(RESOURCE_TYPE, KNOWN_RESOURCE_PATH_1), EffectedPermissions.newInstance(PoliciesModelFactory.noPermissions(), PoliciesModelFactory.newPermissions(TestConstants.Policy.PERMISSION_READ)))); ImmutableResources.of(resourceList); }