OfframpAuthPatchMapping extends PatchMapping { @Override public PatchOperation convertOperation(Road road, PatchOperation modelOperation) { checkArgument(modelOperation.getOperation() != REMOVE, "only add or replace are supported"); checkArgument(modelOperation.getValue() instanceof Map, "value must be a map"); Map<?, ?> map = (Map<?, ?>) modelOperation.getValue(); if (!map.isEmpty()) { Object firstItem = map.values().iterator().next(); checkArgument(firstItem instanceof List, "map value must be an array"); List<?> list = (List<?>) firstItem; checkArgument(!list.isEmpty(), "array type must not be empty"); checkArgument(list.get(0) instanceof String, "array type must be a string"); } return PatchOperation.replace(PATH, modelOperation.getValue()); }  @Override String getPath(); @Override PatchOperation convertOperation(Road road, PatchOperation modelOperation);  }
@Test(expected = IllegalArgumentException.class) public void remove() throws Exception { PatchOperation op = PatchOperation.remove(PATH); underTest.convertOperation(null, op); }
@Test(expected = IllegalArgumentException.class) public void valueNotMap() throws Exception { PatchOperation op = PatchOperation.add(PATH, "notMap"); underTest.convertOperation(null, op); }
@Test(expected = IllegalArgumentException.class) public void mapValueNotList() throws Exception { Map<String, String> value = singletonMap("AUTHORITY", "notList"); PatchOperation op = PatchOperation.add(PATH, value); underTest.convertOperation(null, op); }
@Test(expected = IllegalArgumentException.class) public void mapValueTypeNotString() throws Exception { List<Integer> grants = singletonList(0); Map<String, List<Integer>> value = singletonMap("AUTHORITY", grants); PatchOperation op = PatchOperation.add(PATH, value); underTest.convertOperation(null, op); }