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
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:
- fixed cases for each method, for example the seven kinds, exact numbers, and names that are not normalized;
ModelVerifieron a corpus of documents, and on random documents fromRandomJson;- the JSONPath Compliance Test Suite, from
ComplianceKit.jsonPath(JsonModel, java.util.function.Function).
// 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanTells if the parser and the model keep duplicate member names.model()Returns the model under test.protected abstract NParses a JSON text with the JSON library of the model.protected intReturns the number of random documents that the verifier test checks.protected booleanTells if the JSON library reads numbers with any exponent, for example1e99999999999.
-
Constructor Details
-
JsonModelContract
protected JsonModelContract()Makes the contract test. A subclass gives the model and a parser.
-
-
Method Details
-
model
-
parse
-
readsAnyExponent
protected boolean readsAnyExponent()Tells if the JSON library reads numbers with any exponent, for example1e99999999999. Then the comparison test also uses such numbers.- Returns:
trueif the library reads numbers with any exponent;falseby 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:
trueif the model keeps each member of a duplicate name;falseby default
-