PointerLocationEvaluator implements Function<JsonPointer, PointerLocation> { @Override public PointerLocation apply(final JsonPointer evaluationPointer) { checkNotNull(evaluationPointer, "pointer to be evaluated"); PointerLocation result = PointerLocation.DIFFERENT; if (isOnReferencePointer(evaluationPointer)) { final int evaluationPointerLevelCount = evaluationPointer.getLevelCount(); final int referencePointerLevelCount = referencePointer.getLevelCount(); if (evaluationPointerLevelCount < referencePointerLevelCount) { result = PointerLocation.ABOVE; } else if (evaluationPointerLevelCount > referencePointerLevelCount) { result = PointerLocation.BELOW; } else { result = PointerLocation.SAME; } } return result; } PointerLocationEvaluator(final JsonPointer referencePointer); @Override PointerLocation apply(final JsonPointer evaluationPointer);  }
@Test public void evaluationPointerIsDifferent() { final JsonPointer evaluationPointer = JsonFactory.newPointer("john/titor"); final PointerLocation pointerLocation = underTest.apply(evaluationPointer); assertThat(pointerLocation).isSameAs(PointerLocation.DIFFERENT); }
@Test public void evaluationPointerIsAbove() { final JsonPointer evaluationPointer = JsonFactory.newPointer("foo/bar/baz"); final PointerLocation pointerLocation = underTest.apply(evaluationPointer); assertThat(pointerLocation).isSameAs(PointerLocation.ABOVE); }
@Test public void evaluationPointerIsSame() { final JsonPointer evaluationPointer = JsonFactory.newPointer(REFERENCE_POINTER.toString()); final PointerLocation pointerLocation = underTest.apply(evaluationPointer); assertThat(pointerLocation).isSameAs(PointerLocation.SAME); }
@Test public void evaluationPointerIsBelow() { final JsonPointer evaluationPointer = REFERENCE_POINTER.addLeaf(JsonFactory.newKey("peng")); final PointerLocation pointerLocation = underTest.apply(evaluationPointer); assertThat(pointerLocation).isSameAs(PointerLocation.BELOW); }