JsonNodeTransformer { public JsonNode transform(JsonNode jsonNode, List<String> pointers) { pointers.forEach(p -> transform(jsonNode, p.replaceAll(UNION_PATTERN, "/"))); return jsonNode; }  JsonNode transform(JsonNode jsonNode, List<String> pointers);  }
@Test public void unnestedValue() throws Exception { doReturn(TextNode.valueOf("bar")).when(obfuscator).apply(TextNode.valueOf("foo")); JsonNode result = underTest.transform(f1Unnested, singletonList("/f1")); assertThat(result, is(mapper.createObjectNode().put("f1", "bar"))); }
@Test public void nestedValue() throws Exception { doReturn(TextNode.valueOf("bar")).when(obfuscator).apply(TextNode.valueOf("foo")); JsonNode result = underTest.transform(nested, singletonList("/f1/f2")); assertThat(result.get("f1"), is(mapper.createObjectNode().put("f2", "bar"))); }
@Test public void mapValue() throws Exception { doReturn(TextNode.valueOf("bar")).when(obfuscator).apply(TextNode.valueOf("foo")); JsonNode result = underTest.transform(nested, singletonList("/*/f2")); assertThat(result.get("f1"), is(mapper.createObjectNode().put("f2", "bar"))); }
@Test public void arrayValue() throws Exception { doReturn(TextNode.valueOf("bar")).when(obfuscator).apply(TextNode.valueOf("foo")); JsonNode result = underTest.transform(array, singletonList("/*/f2")); assertThat(result.get(0), is(mapper.createObjectNode().put("f2", "bar"))); }
@Test public void unionValue() throws Exception { doReturn(TextNode.valueOf("bar")).when(obfuscator).apply(TextNode.valueOf("foo")); JsonNode result = underTest.transform(f1Unnested, singletonList("/0/f1")); assertThat(result, is(mapper.createObjectNode().put("f1", "bar"))); }
@Test public void missingParent() throws Exception { underTest.transform(nested, singletonList("/missing/f2")); assertThat(nested.get("missing/f2"), is(nullValue())); }
@Test public void missingField() throws Exception { underTest.transform(nested, singletonList("/f1/missing")); assertThat(nested.get("missing"), is(nullValue())); }