Group implements Comparable<Group> { public final Group collectResourcesOfType(final ResourceType type) { notNull(type); final List<Resource> filteredResources = new ArrayList<>(); for (final Resource resource : getResources()) { if (type == resource.getType()) { if (filteredResources.contains(resource)) { LOG.warn("Duplicated resource detected: " + resource + ". This resource won't be included more than once!"); } else { filteredResources.add(resource); } } } final Group filteredGroup = new Group(getName()); filteredGroup.setResources(filteredResources); return filteredGroup; } Group();  Group(final String name); final boolean hasResourcesOfType(final ResourceType resourceType); boolean hasResource(final String resourceUri); void replace(final Resource resource, final List<Resource> expandedResources); final Group collectResourcesOfType(final ResourceType type); List<Resource> getResources(); Group addResource(final Resource resource); final void setResources(final List<Resource> resources); String getName(); @Override int compareTo(final Group o); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString();  }
@Test(expected = NullPointerException.class) public void cannotCollectResourcesWithNullType() { final Group group = new Group("group"); group.collectResourcesOfType(null); }