MetadataPatchMapping extends PatchMapping { @Override public PatchOperation convertOperation(Road road, PatchOperation modelOperation) { checkArgument(isAddOrReplace(modelOperation), "You can only change the value of metadata"); checkArgument(modelOperation.getValue() instanceof Map, "metadata must be an object"); checkArgument(modelOperation.getValue() != null, "metadata cannot be null"); return PatchOperation.replace("/metadata", modelOperation.getValue()); }  @Override String getPath(); @Override PatchOperation convertOperation(Road road, PatchOperation modelOperation);  }
@Test(expected = IllegalArgumentException.class) public void metadata_cannot_be_set_to_null() throws Exception { mapping.convertOperation(road, PatchOperation.replace("/metadata", null)); }
@Test public void add_converts_to_replace() throws Exception { PatchOperation operation = mapping.convertOperation(road, PatchOperation.add("/metadata", emptyMap())); assertThat(operation, is(PatchOperation.replace("/metadata", emptyMap()))); }
@Test(expected = IllegalArgumentException.class) public void remove_patch_fails() throws Exception { mapping.convertOperation(road, PatchOperation.remove("/metadata")); }
@Test(expected = IllegalArgumentException.class) public void setting_to_a_non_map_fails() throws Exception { mapping.convertOperation(road, PatchOperation.add("/metadata", emptyList())); }