AddMultiValues implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class); if (properties != null) { String[] currentValues = properties.get(name, String[].class); List<String> valuesList = new ArrayList<>(); if (currentValues != null && currentValues.length > 0) { Collections.addAll(valuesList, currentValues); } Collections.addAll(valuesList, values); properties.put(name, valuesList.toArray(new String[] {})); return "Adding values " + Arrays.toString(values) + " to multi-value property " + name + ": " + Arrays.toString(currentValues) + " results in " + valuesList + " for resource " + resource.getPath(); } return "WARNING: could not get ModifiableValueMap for resource " + resource.getPath(); } AddMultiValues(@Nonnull String name, @Nonnull String[] values); @Override String doAction(@Nonnull Resource resource);  }
@Test public void doAction() throws PersistenceException { AddMultiValues action = new AddMultiValues(ATTR, new String[] {VAL1, VAL2}); action.doAction(resource); verify(valueMap, times(1)).put(ATTR, new String[] {VAL1, VAL2}); }
@Test public void doAction_existingAttribute() throws PersistenceException { when(valueMap.get(ATTR, String[].class)).thenReturn(new String[] {VAL3}); AddMultiValues action = new AddMultiValues(ATTR, new String[] {VAL1, VAL2}); action.doAction(resource); verify(valueMap, times(1)).put(ATTR, new String[] {VAL3, VAL1, VAL2}); }