Class ModelVerifier<N>

java.lang.Object
ca.marcusdunn.jsonlens.testkit.ModelVerifier<N>
Type Parameters:
N - the node type of the model

public final class ModelVerifier<N> extends Object

Checks the rules of a JsonModel on a document, and returns each Violation.

The verifier visits each value of the document. For each value, it calls the methods of the model for the kind of the value, and it compares the results with each other:

Thus an override of a default method must give the result of the default method. The verifier calls a method for a kind only for a node of that kind, as jsonlens does. It does not throw: an exception or a null result of the model is a violation.

JsonModel<Object> model = new CollectionsModel();
List<Violation> violations = ModelVerifier.of(model).verify(Map.of("a", List.of(1, "x")));
// Each violation names a rule, the location of a value, and what the model did.
  • Method Details

    • of

      public static <N> ModelVerifier<N> of(JsonModel<N> model)
      Returns a verifier for a model.
      Type Parameters:
      N - the node type of the model
      Parameters:
      model - the model to check
      Returns:
      the verifier
    • verify

      public List<Violation> verify(N root)
      Checks each value of a document.
      Parameters:
      root - the root value of the document
      Returns:
      the violations, in the order of the visits; an empty list if the model obeys each rule