Class ComplianceKit

java.lang.Object
ca.marcusdunn.jsonlens.testkit.ComplianceKit

public final class ComplianceKit extends Object

Runs the test suites of RFC 9535 and RFC 6902 on a model, as JUnit dynamic tests.

The model reads each document from its JSON text, with the parser of its own library. The suites are in the JAR, with their licenses: the JSONPath Compliance Test Suite (BSD-2), and the JSON Patch tests (Apache-2.0).

// The suites as JUnit dynamic tests, for example in a test class that is not a contract test.
@TestFactory
Stream<DynamicTest> jsonPathSuite() {
    return ComplianceKit.jsonPath(new CollectionsModel(), TestkitSnippets::parse);
}
  • Method Details

    • jsonPath

      public static <N> Stream<org.junit.jupiter.api.DynamicTest> jsonPath(JsonModel<N> model, Function<String,N> parser)
      Returns a test for each valid query of the JSONPath Compliance Test Suite.
      Type Parameters:
      N - the node type of the model
      Parameters:
      model - the model under test
      parser - reads a JSON text into a node of the model
      Returns:
      the tests
    • jsonPatchInPlace

      public static <N, M extends JsonModel<N> & JsonFactory<N> & JsonEditor<N>> Stream<org.junit.jupiter.api.DynamicTest> jsonPatchInPlace(M model, Function<String,N> parser)
      Returns a test for each test of the JSON Patch test suite, in place.
      Type Parameters:
      N - the node type of the model
      M - the type of the model
      Parameters:
      model - the model under test
      parser - reads a JSON text into a node of the model
      Returns:
      the tests
    • jsonPatchToCopy

      public static <N, M extends JsonModel<N> & JsonFactory<N>> Stream<org.junit.jupiter.api.DynamicTest> jsonPatchToCopy(M model, Function<String,N> parser)
      Returns a test for each test of the JSON Patch test suite, to a copy. Use it for a model that builds values but does not change them.
      Type Parameters:
      N - the node type of the model
      M - the type of the model
      Parameters:
      model - the model under test
      parser - reads a JSON text into a node of the model
      Returns:
      the tests