Skip to content

Include JsonAssertions as custom AssertJ asserts #19

@jhannes

Description

@jhannes

Motivating test case:

import static org.jsonbuddy.asserts.JsonAssertions.assertThat;

assertThat(jsonOrder)
     .isNotEmpty()
     .hasProperty("date")
     .hasString("status", "ORDERED") // Throws assertion failure if givenName is missing
     .object("customer")
        .hasNumber("creditLevel", 100);

assertThat(jsonOrder)
    .array("tags")
        .isNotEmpty()
       .strings()
           .contains("urgent", "international");

assertThat(jsonOrder)
    .array("orderLines")
      .contains(new JsonObject().put("productId", 1).put("quantity", 8))
     .get(1)
         .isNotEmpty()
         .hasProperty("productId")
         .hasNumber("quantity", 1000);

This should be used in:

  • JsonGeneratorTest
  • JsonBuildTest

See http://joel-costigliola.github.io/assertj/assertj-core-custom-assertions.html for details.

This requires assertj to be a optional dependency instead of a test dependency.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions