/** * Sets listener to customize diff format */ public static void setDifferenceListener(DifferenceListener listener) { configuration = configuration.withDifferenceListener(listener); }
/** * Sets the tolerance for floating number comparison. If set to null, requires exact match of the values. * For example, if set to 0.01, ignores all differences lower than 0.01, so 1 and 0.9999 are considered equal. */ public static void setTolerance(BigDecimal numericComparisonTolerance) { configuration = configuration.withTolerance(numericComparisonTolerance); }
/** * Set's string that will be ignored in comparison. Default value is "${json-unit.ignore}" */ public static void setIgnorePlaceholder(String ignorePlaceholder) { configuration = configuration.withIgnorePlaceholder(ignorePlaceholder); }
/** * Creates empty configuration and sets options. */ public static Configuration when(Option first, Option... next) { return Configuration.empty().withOptions(first, next); }
/** * Adds a matcher to be used in ${json-unit.matches:matcherName} macro. */ public static Configuration withMatcher(String matcherName, Matcher<?> matcher) { return Configuration.empty().withMatcher(matcherName, matcher); }
/** * Creates empty configuration and sets numerical comparison tolerance. */ public static Configuration withTolerance(double tolerance) { return Configuration.empty().withTolerance(tolerance); }
/** * Adds comparison options. * * @param first * @param next * @return */ public Configuration when(Option first, Option... next) { return withOptions(first, next); }
/** * Sets DifferenceListener. */ public static Configuration withDifferenceListener(DifferenceListener differenceListener) { return Configuration.empty().withDifferenceListener(differenceListener); } }
/** * Sets paths to be ignored. */ public static Configuration whenIgnoringPaths(String... paths) { return Configuration.empty().whenIgnoringPaths(paths); }
public ConfigurableJsonMatcher<T> whenIgnoringPaths(String... paths) { configuration = configuration.whenIgnoringPaths(paths); return this; }
/** * When set to true, treats null nodes in actual value as absent. In other words * if you expect {"test":{"a":1}} this {"test":{"a":1, "b": null}} will pass the test. * * @deprecated use setOptions(Option.TREATING_NULL_AS_ABSENT) */ @Deprecated public static void setTreatNullAsAbsent(boolean treatNullAsAbsent) { if (treatNullAsAbsent) { configuration = configuration.withOptions(TREATING_NULL_AS_ABSENT); } else { configuration = configuration.withOptions(configuration.getOptions().without(TREATING_NULL_AS_ABSENT)); } }
/** * Finds element in the expected elements. */ private List<Integer> indexOf(List<NodeWithIndex> expectedElements, Node actual) { List<Integer> result = new ArrayList<>(); int i = 0; for (NodeWithIndex expected : expectedElements) { Diff diff = new Diff(expected.getNode(), actual, Path.create("", path.toElement(i).getFullPath()), configuration.withDifferenceListener(dummyDifferenceListener()), NULL_LOGGER, NULL_LOGGER, DEFAULT_DIFFERENCE_STRING); if (diff.similar()) { result.add(i); } i++; } return result; }
/** * Adds a matcher to be used in ${json-unit.matches:matcherName} macro. */ public ConfigurableJsonMatcher<T> withMatcher(String matcherName, Matcher<?> matcher) { configuration = configuration.withMatcher(matcherName, matcher); return this; }
@Override public String toString() { Set<Option> options = configuration.getOptions().values(); return "when comparing as JSON" + (!options.isEmpty() ? " with " + options : ""); } }
/** * Creates JsonUnitResultMatchers to be used for JSON assertions. * * @return */ public static JsonUnitResultMatchers json() { return new JsonUnitResultMatchers("", Configuration.empty()); }
public static DifferenceListener getDifferenceListener() { return configuration.getDifferenceListener(); }
/** * Adds comparison options. * * @param first * @param next * @return */ public Configuration when(Option first, Option... next) { return withOptions(first, next); }
/** * Creates empty configuration and sets numerical comparison tolerance. */ public static Configuration withTolerance(BigDecimal tolerance) { return Configuration.empty().withTolerance(tolerance); }
/** * Sets DifferenceListener. */ public static Configuration withDifferenceListener(DifferenceListener differenceListener) { return Configuration.empty().withDifferenceListener(differenceListener); } }
/** * Creates empty configuration and sets options. */ public static Configuration when(Option first, Option... next) { return Configuration.empty().withOptions(first, next); }