java.lang.Object
net.javacrumbs.jsonunit.assertj.JsonAssertions

public final class JsonAssertions extends Object
  • Field Details

    • JSON

      public static final org.assertj.core.api.InstanceOfAssertFactory<Object,JsonAssert.ConfigurableJsonAssert> JSON
      Allows to move from standard AssertJ asserts to JsonUnit. For example assertThat(resp) .hasFieldOrPropertyWithValue("trackingId", "abcd-0001") //<- Assertj API .extracting("json").asInstanceOf(JSON) .isObject().containsEntry("foo", "bar"); // <- JsonUnit API
  • Method Details

    • assertThatJson

      @NotNull public static @NotNull JsonAssert.ConfigurableJsonAssert assertThatJson(@Nullable @Nullable Object actual)
    • assertThatJson

      @NotNull public static @NotNull JsonAssert.ConfigurableJsonAssert assertThatJson(@NotNull @NotNull Object actual, @NotNull @NotNull JsonAssertions.JsonAssertionCallback... callbacks)
      Assert json properties with possibility to chain assertion callbacks like this
      
       assertThatJson("{\"test1\":2, \"test2\":1}",
                   json -> json.inPath("test1").isEqualTo(2),
                   json -> json.inPath("test2").isEqualTo(1)
               );
       
    • json

      @NotNull public static @NotNull Object json(Object input)
      JSON to be used in expected part of the assertion,
      Parameters:
      input -
      Returns:
      Object suitable for comparison. Implementation type may change in the future.
    • value

      @NotNull public static @NotNull Object value(Object input)
      Value passed here is not parsed as JSON but used as it is
    • jsonUnitJson

      public static org.assertj.core.api.AssertFactory<Object,JsonAssert.ConfigurableJsonAssert> jsonUnitJson()
      Returns AssertFactory allowing to move from standard AssertJ to JsonUnit. For example: assertThat(mvc.get().uri("/sample")) .hasStatusOk() .bodyJson() .convertTo(jsonUnitJson()) .inPath("result.array") <-- JsonUnit assert .isArray() .containsExactly(1, 2, 3);