Concatenate implements VirtualMetadataConfiguration { @Override 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); String resultString = ""; for (int i = 0; i < resultList.size(); i++) { String metadataValueString = resultList.get(i).getValue(); if (StringUtils.isNotBlank(metadataValueString)) { if (StringUtils.isNotBlank(resultString)) { resultString += this.getSeparator(); } resultString += metadataValueString; } } if (StringUtils.isNotBlank(resultString)) { resultValues.add(resultString); } } String result = StringUtils.join(resultValues, this.getSeparator()); List<String> listToReturn = new LinkedList<>(); listToReturn.add(result); return listToReturn; }  List<String> getFields(); void setFields(List<String> fields); String getSeparator(); void setSeparator(String separator); @Override void setUseForPlace(boolean useForPlace); @Override boolean getUseForPlace(); @Override void setPopulateWithNameVariant(boolean populateWithNameVariant); @Override boolean getPopulateWithNameVariant(); @Override 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); concatenate.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, concatenate.getValues(context, item)); }