### Question:
MetadataService extends AbstractService { public List<AttributeElement> getAttributeElements(Attribute attribute) { notNull(attribute, "attribute"); return getAttributeElements(attribute.getDefaultDisplayForm()); } MetadataService(final RestTemplate restTemplate, final GoodDataSettings settings); @SuppressWarnings("unchecked") T createObj(Project project, T obj); T getObjByUri(String uri, Class<T> cls); Collection<Obj> getObjsByUris(Project project, Collection<String> uris); @SuppressWarnings("unchecked") T updateObj(T obj); void removeObj(Obj obj); void removeObjByUri(String uri); T getObjById(Project project, String id, Class<T> cls); String getObjUri(Project project, Class<T> cls, Restriction... restrictions); T getObj(Project project, Class<T> cls, Restriction... restrictions); Collection<Entry> find(Project project, Class<T> cls, Restriction... restrictions); Collection<String> findUris(Project project,
                                                             Class<T> cls,
                                                             Restriction... restrictions); @SuppressWarnings("unchecked") Collection<Entry> usedBy(Project project, Obj obj, boolean nearest, Class<? extends Obj>... types); @SuppressWarnings("unchecked") Collection<Entry> usedBy(Project project, String uri, boolean nearest, Class<? extends Obj>... types); @SuppressWarnings("unchecked") Collection<Usage> usedBy(Project project, Collection<String> uris, boolean nearest, Class<? extends Obj>... types); Collection<String> findUris(Project project, Restriction... restrictions); Map<String, String> identifiersToUris(Project project, Collection<String> identifiers); List<AttributeElement> getAttributeElements(Attribute attribute); List<AttributeElement> getAttributeElements(DisplayForm displayForm); static final UriTemplate OBJ_TEMPLATE; }### Answer:
@Test public void testGetAttributeElementsEmpty() { final DisplayForm attrDisplayForm = mock(AttributeDisplayForm.class); when(attrDisplayForm.getElementsUri()).thenReturn("elementsUri"); final Attribute attr = mock(Attribute.class); when(attr.getDefaultDisplayForm()).thenReturn(attrDisplayForm); when(restTemplate.getForObject("elementsUri", AttributeElements.class)) .thenReturn(readObjectFromResource("/md/attributeElements-empty.json", AttributeElements.class)); final List<AttributeElement> elements = service.getAttributeElements(attr); assertThat(elements, hasSize(0)); }
@Test public void testGetAttributeElements() { final DisplayForm attrDisplayForm = mock(AttributeDisplayForm.class); when(attrDisplayForm.getElementsUri()).thenReturn("elementsUri"); final Attribute attr = mock(Attribute.class); when(attr.getDefaultDisplayForm()).thenReturn(attrDisplayForm); final AttributeElement result1 = mock(AttributeElement.class); final AttributeElement result2 = mock(AttributeElement.class); final AttributeElements attrElements = readObjectFromResource("/md/attributeElements-empty.json", AttributeElements.class); attrElements.getElements().addAll(asList(result1, result2)); when(restTemplate.getForObject("elementsUri", AttributeElements.class)).thenReturn(attrElements); final List<AttributeElement> elements = service.getAttributeElements(attr); assertThat(elements, allOf(hasItem(result1), hasItem(result2))); }