### Question:
QueryImpl implements Query, ResourceInstance { @Override public boolean isCollectionResource() { return getKeyValueMap().get(getResourceDefinition().getType()) == null; } QueryImpl(Map<Resource.Type, String> keyValueMap,
                   ResourceDefinition resourceDefinition,
                   ClusterController clusterController); @Override void addProperty(String propertyId, TemporalInfo temporalInfo); @Override void addLocalProperty(String property); @Override Result execute(); @Override Predicate getPredicate(); @Override Set<String> getProperties(); @Override void setUserPredicate(Predicate predicate); @Override void setPageRequest(PageRequest pageRequest); @Override void setSortRequest(SortRequest sortRequest); @Override void setRenderer(Renderer renderer); @Override void setRequestInfoProps(Map<String, String> requestInfoProperties); @Override Map<String, String> getRequestInfoProps(); @Override void setKeyValueMap(Map<Resource.Type, String> keyValueMap); @Override Map<Resource.Type, String> getKeyValueMap(); @Override Query getQuery(); @Override ResourceDefinition getResourceDefinition(); @Override boolean isCollectionResource(); @Override Map<String, ResourceInstance> getSubResources(); @Override boolean equals(Object o); @Override int hashCode();  }### Answer:
@Test public void testIsCollection__True() { ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class); Map<Resource.Type, String> mapIds = new HashMap<>(); mapIds.put(Resource.Type.Cluster, "cluster"); mapIds.put(Resource.Type.Service, null); expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes(); expect(resourceDefinition.getSubResourceDefinitions()).andReturn(Collections.emptySet()).anyTimes(); replay(resourceDefinition); ResourceInstance instance = new TestQuery(mapIds, resourceDefinition); assertTrue(instance.isCollectionResource()); verify(resourceDefinition); }
@Test public void testIsCollection__False() { ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class); Map<Resource.Type, String> mapIds = new HashMap<>(); mapIds.put(Resource.Type.Cluster, "cluster"); mapIds.put(Resource.Type.Service, "service"); expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes(); expect(resourceDefinition.getSubResourceDefinitions()).andReturn(Collections.emptySet()).anyTimes(); replay(resourceDefinition); ResourceInstance instance = new TestQuery(mapIds, resourceDefinition); assertFalse(instance.isCollectionResource()); verify(resourceDefinition); }