private boolean compareArrays(JSONArray expected, JSONArray actual) { if (strictArrayOrder) { return compareArraysByStrictOrder(expected, actual); } return compareArraysByLenientOrder(expected, actual); }
public JsonAssert ignoreFields(String... ignoredFields) { comparison.setIgnoredFields(ignoredFields); return this; }
@Test public void only_statics() { TestUtils.hasOnlyPrivateConstructors(DefaultIndexSettings.class); } }
private static void verifyCanUpdateProjectsVisibilityToPrivateResponse(TestResponse response, boolean canUpdateProjectsVisibilityToPrivate) { assertJson(response.getInput()) .isSimilarTo("{" + " \"organization\": {" + " \"canUpdateProjectsVisibilityToPrivate\": " + canUpdateProjectsVisibilityToPrivate + "," + " }" + "}"); } }
public JsonAssert isSimilarTo(URL expected) { return isSimilarTo(urlToString(expected)); }
private boolean isSimilar_strict_array_order(String expected, String actual) { return new JsonComparison().withStrictArrayOrder().areSimilar(expected, actual); } }
private boolean isSimilar_strict_timezone(String expected, String actual) { return new JsonComparison().withTimezone().areSimilar(expected, actual); }
@Test public void strict_timezone() { assertThat(new JsonComparison().withTimezone().isStrictTimezone()).isTrue(); // same instant, same timezone assertThat(isSimilar_strict_timezone("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T15:50:45+0100\"}")).isTrue(); assertThat(isSimilar_strict_timezone("[\"2010-05-18T15:50:45+0100\"]", "[\"2010-05-18T15:50:45+0100\"]")).isTrue(); // same instant, but different timezone assertThat(isSimilar_strict_timezone("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T18:50:45+0400\"}")).isFalse(); // different time assertThat(isSimilar_strict_timezone("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T15:51:45+0100\"}")).isFalse(); }
public JsonAssert isSimilarTo(String expected) { boolean similar = comparison.areSimilar(expected, actualJson); if (!similar) { throw new ComparisonFailure("Not a super-set of expected JSON -", pretty(expected), pretty(actualJson)); } return this; }
public static JsonAssert assertJson(URL actualJson) { return new JsonAssert(urlToString(actualJson)); }
private boolean areSimilar(String expected, String actual) { return new JsonComparison().areSimilar(expected, actual); }
public JsonAssert withStrictTimezone() { comparison.withTimezone(); return this; }
public JsonAssert withStrictArrayOrder() { comparison.withStrictArrayOrder(); return this; }
@Test public void lenient_timezone() { // lenient mode by default assertThat(new JsonComparison().isStrictTimezone()).isFalse(); // same instant, same timezone assertThat(areSimilar("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T15:50:45+0100\"}")).isTrue(); // same instant, but different timezone assertThat(areSimilar("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T18:50:45+0400\"}")).isTrue(); // different time assertThat(areSimilar("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T15:51:45+0100\"}")).isFalse(); }
public ExceptionCauseMatcher andNoMessage() { return new ExceptionCauseMatcher(type, EXPECT_NO_MESSAGE_CONSTANT); }
public static JsonAssert assertJson(String actualJson) { return new JsonAssert(actualJson); }
@Test public void constructor_is_private() { TestUtils.hasOnlyPrivateConstructors(Uuids.class); } }
public static ExceptionCauseMatcher hasType(Class<? extends Throwable> type) { return new ExceptionCauseMatcher(type, null); }
@Test public void not_instantiable() { // only static methods. Bad pattern, should be improved. TestUtils.hasOnlyPrivateConstructors(KeyValueFormat.class); }