Class JsonModelContract<N>

java.lang.Object
ca.marcusdunn.jsonlens.testkit.JsonModelContract<N>
Type Parameters:
N - the node type of the model
Direct Known Subclasses:
JsonFactoryContract

public abstract class JsonModelContract<N> extends Object

Tests that a JsonModel obeys its contract, as JUnit tests.

A test class extends this class, and gives the model and a parser of its JSON library. The parser must keep numbers exact. The tests are:

// The contract test of a model: give the model and a parser of its JSON library.
// The test runs fixed cases, the verifier on random documents, and the RFC 9535 test suite.
static class CollectionsModelContractTest extends JsonModelContract<Object> {

    @Override
    protected JsonModel<Object> model() {
        return new CollectionsModel();
    }

    @Override
    protected Object parse(String json) {
        return TestkitSnippets.parse(json); // The parser must keep numbers exact.
    }
}

JsonFactoryContract and JsonEditorContract add the tests for a model that builds and changes values.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Makes the contract test.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    Tells if the parser and the model keep duplicate member names.
    protected abstract JsonModel<N>
    Returns the model under test.
    protected abstract N
    parse(String json)
    Parses a JSON text with the JSON library of the model.
    protected int
    Returns the number of random documents that the verifier test checks.
    protected boolean
    Tells if the JSON library reads numbers with any exponent, for example 1e99999999999.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JsonModelContract

      protected JsonModelContract()
      Makes the contract test. A subclass gives the model and a parser.
  • Method Details

    • model

      protected abstract JsonModel<N> model()
      Returns the model under test.
      Returns:
      the model under test
    • parse

      protected abstract N parse(String json)
      Parses a JSON text with the JSON library of the model.
      Parameters:
      json - a JSON text
      Returns:
      the root node
    • readsAnyExponent

      protected boolean readsAnyExponent()
      Tells if the JSON library reads numbers with any exponent, for example 1e99999999999. Then the comparison test also uses such numbers.
      Returns:
      true if the library reads numbers with any exponent; false by default
    • randomDocuments

      protected int randomDocuments()
      Returns the number of random documents that the verifier test checks.
      Returns:
      the number of random documents; 100 by default
    • keepsDuplicateNames

      protected boolean keepsDuplicateNames()
      Tells if the parser and the model keep duplicate member names. Then the tests also use documents with duplicate names.
      Returns:
      true if the model keeps each member of a duplicate name; false by default