Collected implements VirtualMetadataConfiguration { public List<String> getValues(Context context, Item item) { List<String> resultValues = new LinkedList<>(); List<String> value = this.getFields(); for (String s : value) { String[] splittedString = s.split("\\."); List<MetadataValue> resultList = itemService.getMetadata(item, splittedString.length > 0 ? splittedString[0] : null, splittedString.length > 1 ? splittedString[1] : null, splittedString.length > 2 ? splittedString[2] : null, Item.ANY, false); for (MetadataValue metadataValue : resultList) { if (StringUtils.isNotBlank(metadataValue.getValue())) { resultValues.add(metadataValue.getValue()); } } } return resultValues; }  List<String> getFields(); void setFields(List<String> fields); @Override void setUseForPlace(boolean useForPlace); @Override boolean getUseForPlace(); @Override void setPopulateWithNameVariant(boolean populateWithNameVariant); @Override boolean getPopulateWithNameVariant(); List<String> getValues(Context context, Item item);  }
@Test public void testGetValues() { List<String> list = new ArrayList<>(); List<String> valueList = new ArrayList<>(); List<MetadataValue> metadataValueList = new ArrayList<>(); MetadataValue metadataValue = mock(MetadataValue.class); Item item = mock(Item.class); metadataValueList.add(metadataValue); String s = "dc.title"; list.add(s); List<String> splittedString = Splitter.on('.').splitToList(s); collected.setFields(list); valueList.add("TestValue"); when(itemService.getMetadata(item, splittedString.size() > 0 ? splittedString.get(0) : null, splittedString.size() > 1 ? splittedString.get(1) : null, splittedString.size() > 2 ? splittedString.get(2) : null, Item.ANY, false)).thenReturn(metadataValueList); when(metadataValue.getValue()).thenReturn("TestValue"); assertEquals("TestGetValues 0", valueList, collected.getValues(context, item)); }