### Question:
ChildrenAsPropertyResource extends ResourceWrapper { @Override public final Iterator<Resource> listChildren() { return IteratorUtils.getIterator(this.orderedCache); } ChildrenAsPropertyResource(Resource resource);  ChildrenAsPropertyResource(Resource resource, String propertyName);  ChildrenAsPropertyResource(Resource resource, String propertyName, Comparator<Resource> comparator); @Override final Iterator<Resource> listChildren(); @Override final Iterable<Resource> getChildren(); @Override final Resource getChild(String name); @Override final Resource getParent(); final Resource create(String name, String primaryType); final Resource create(String name, String primaryType, Map<String, Object> data); final void delete(String name); final void deleteAll(); final void persist(); static final Comparator<Resource> RESOURCE_NAME_COMPARATOR; }### Answer:
@Test public void testGet_Unsorted() throws Exception { valueMap.put("animals", sortedJSON.toString()); List<Resource> expected = new ArrayList<Resource>(); expected.add(new SyntheticChildAsPropertyResource(resource, "entry-1", new ValueMapDecorator(entry1))); expected.add(new SyntheticChildAsPropertyResource(resource, "entry-2", new ValueMapDecorator(entry2))); expected.add(new SyntheticChildAsPropertyResource(resource, "entry-3", new ValueMapDecorator(entry3))); ChildrenAsPropertyResource childrenAsPropertyResource = new ChildrenAsPropertyResource(resource, "animals"); List<Resource> actual = IteratorUtils.toList(childrenAsPropertyResource.listChildren()); Assert.assertEquals(expected.size(), actual.size()); for (int i = 0; i < expected.size(); i++) { Assert.assertEquals(expected.get(i).getName(), actual.get(i).getName()); } }
@Test public void testGet_Sorted() throws Exception { valueMap.put("animals", unsortedJSON.toString()); List<Resource> expected = new ArrayList<Resource>(); expected.add(new SyntheticChildAsPropertyResource(resource, "entry-1", new ValueMapDecorator(entry1))); expected.add(new SyntheticChildAsPropertyResource(resource, "entry-2", new ValueMapDecorator(entry2))); expected.add(new SyntheticChildAsPropertyResource(resource, "entry-3", new ValueMapDecorator(entry3))); childrenAsPropertyResource = new ChildrenAsPropertyResource(resource, "animals", ChildrenAsPropertyResource.RESOURCE_NAME_COMPARATOR);; List<Resource> actual = IteratorUtils.toList(childrenAsPropertyResource.listChildren()); Assert.assertEquals(expected.size(), actual.size()); for (int i = 0; i < expected.size(); i++) { Assert.assertEquals(expected.get(i).getName(), actual.get(i).getName()); } }