### Question:
NodePath { public Optional<JsonNode> findMatchingDescendant(JsonNode rootNode) { JsonNode current = rootNode; for (PathElement element : elements) { current = element.child(current); if (current == null) { return Optional.empty(); } } return Optional.ofNullable(current); } NodePath(String path);   NodePath(List<PathElement> elements); List<PathElement> elements(); PathElement lastElement(); Optional<JsonNode> findMatchingDescendant(JsonNode rootNode); boolean override(JsonNode rootNode, JsonNode leaf); boolean override(JsonNode rootNode, String value); @Override String toString();  }### Answer:
@Test public void canGetTopLevelProperty() { assertThat(new NodePath("text").findMatchingDescendant(root), matches(isTextNode("abc"))); }
@Test public void canGetArrayElements() { assertThat(new NodePath("array[0]").findMatchingDescendant(root), matches(isTextNode("alpha"))); assertThat(new NodePath("array[1]").findMatchingDescendant(root), matches(isTextNode("beta"))); assertThat(new NodePath("array[2]").findMatchingDescendant(root), matches(isTextNode("gamma"))); }
@Test public void canGetObjectField() { assertThat(new NodePath("object.field1").findMatchingDescendant(root), matches(isTextNode("foo"))); assertThat(new NodePath("object.field2").findMatchingDescendant(root), matches(isTextNode("bar"))); }
@Test public void canGetFieldsWithinArrayElementObjects() { assertThat(new NodePath("array2[0].arrayObjectField1").findMatchingDescendant(root), matches(isTextNode("abc"))); assertThat(new NodePath("array2[0].arrayObjectField2").findMatchingDescendant(root), matches(isTextNode("def"))); }