public void testEquivalentTo() { Predicate<Object> equalTo1 = Equivalence.equals().equivalentTo("1"); assertTrue(equalTo1.apply("1")); assertFalse(equalTo1.apply("2")); assertFalse(equalTo1.apply(null)); Predicate<Object> isNull = Equivalence.equals().equivalentTo(null); assertFalse(isNull.apply("1")); assertFalse(isNull.apply("2")); assertTrue(isNull.apply(null)); new EqualsTester() .addEqualityGroup(equalTo1, Equivalence.equals().equivalentTo("1")) .addEqualityGroup(isNull) .addEqualityGroup(Equivalence.identity().equivalentTo("1")) .testEquals(); }
@Nullable private JsonPointer findUnchangedValue(final JsonNode value) { final Predicate<JsonNode> predicate = EQUIVALENCE.equivalentTo(value); for (final Map.Entry<JsonPointer, JsonNode> entry: unchanged.entrySet()) if (predicate.apply(entry.getValue())) return entry.getKey(); return null; }
@Nullable private JsonPointer findUnchangedValue(final JsonNode value) { final Map<JsonPointer, JsonNode> unchangedValues = unchangedValuesSupplier.get(); if (unchangedValues.isEmpty()) { return null; } final Predicate<JsonNode> predicate = EQUIVALENCE.equivalentTo(value); for (final Map.Entry<JsonPointer, JsonNode> entry : unchangedValues.entrySet()) { if (predicate.apply(entry.getValue())) { return entry.getKey(); } } return null; } }
private int findPreviouslyRemoved(final JsonNode value) { final Predicate<JsonNode> predicate = EQUIVALENCE.equivalentTo(value); DiffOperation op; for (int i = 0; i < diffs.size(); i++) { op = diffs.get(i); if (op.getType() == DiffOperation.Type.REMOVE && predicate.apply(op.getOldValue())) return i; } return -1; } }
private String formatSubcomponentDeclaration(SubcomponentDeclaration subcomponentDeclaration) { ImmutableList<TypeMirror> moduleSubcomponents = getModuleSubcomponents(subcomponentDeclaration.moduleAnnotation()); int index = Iterables.indexOf( moduleSubcomponents, MoreTypes.equivalence() .equivalentTo(subcomponentDeclaration.subcomponentType().asType())); StringBuilder annotationValue = new StringBuilder(); if (moduleSubcomponents.size() != 1) { annotationValue.append("{"); } annotationValue.append( formatArgumentInList( index, moduleSubcomponents.size(), subcomponentDeclaration.subcomponentType().getQualifiedName() + ".class")); if (moduleSubcomponents.size() != 1) { annotationValue.append("}"); } return String.format( "@%s(subcomponents = %s) for %s", simpleName(subcomponentDeclaration.moduleAnnotation()), annotationValue, subcomponentDeclaration.contributingModule().get()); } }
@Test(dataProvider = "getPatchesOnly") public void generatedPatchAppliesCleanly(final JsonNode source, final JsonNode target) { final JsonPatch patch = JsonPatch.generate(source, target, ReplaceMode.SAFE); final Predicate<JsonNode> predicate = EQUIVALENCE.equivalentTo(target); final JsonNode actual = patch.apply(source); assertThat(predicate.apply(actual)).overridingErrorMessage( "Generated patch failed to apply\nexpected: %s\nactual: %s", target, actual ).isTrue(); }
@Test(dataProvider = "getPatchesOnly") public void generatedPatchAppliesCleanly(final JsonNode first, final JsonNode second) throws JsonPatchException { final JsonPatch patch = JsonDiff.asJsonPatch(first, second); final Predicate<JsonNode> predicate = EQUIVALENCE.equivalentTo(second); final JsonNode actual = patch.apply(first); assertThat(predicate.apply(actual)).overridingErrorMessage( "Generated patch failed to apply\nexpected: %s\nactual: %s", second, actual ).isTrue(); }
@Test( dataProvider = "getLiteralPatches", dependsOnMethods = "generatedPatchAppliesCleanly" ) public void generatedPatchesAreWhatIsExpected(final String message, final JsonNode first, final JsonNode second, final JsonNode expected) { final JsonNode actual = JsonDiff.asJson(first, second); final Predicate<JsonNode> predicate = EQUIVALENCE.equivalentTo(expected); assertThat(predicate.apply(actual)).overridingErrorMessage( "patch is not what was expected\nscenario: %s\n" + "expected: %s\nactual: %s\n", message, expected, actual ).isTrue(); } }
@Test(dataProvider = "getLiteralPatches", dependsOnMethods = "generatedPatchAppliesCleanly") public void generatedPatchesAreWhatIsExpected(final String message, final JsonNode source, final JsonNode target, final JsonNode expected) { final JsonNode actual = JsonPatch.generate(source, target, ReplaceMode.SAFE).toJson(); final Predicate<JsonNode> predicate = EQUIVALENCE.equivalentTo(expected); assertThat(predicate.apply(actual)).overridingErrorMessage( "patch is not what was expected\nscenario: %s\n" + "expected: %s\nactual: %s\n", message, expected, actual ).isTrue(); } }
public void testEquivalentTo() { Predicate<Object> equalTo1 = Equivalence.equals().equivalentTo("1"); assertTrue(equalTo1.apply("1")); assertFalse(equalTo1.apply("2")); assertFalse(equalTo1.apply(null)); Predicate<Object> isNull = Equivalence.equals().equivalentTo(null); assertFalse(isNull.apply("1")); assertFalse(isNull.apply("2")); assertTrue(isNull.apply(null)); new EqualsTester() .addEqualityGroup(equalTo1, Equivalence.equals().equivalentTo("1")) .addEqualityGroup(isNull) .addEqualityGroup(Equivalence.identity().equivalentTo("1")) .testEquals(); } public void testEqualsEquivalent() {