Replaying handler for JSON libraries
Overview
This library provides a replaying JSON handlers for other JSON processing libraries.
Consult the documentation and the usage description for further information:
Maven
This library is hosted in the Maven Central Repository. You can use it with the following coordinates:
<dependency>
<groupId>net.markenwerk</groupId>
<artifactId>utils-json-handler-replay</artifactId>
<version>1.0.1</version>
</dependency>
Usage
Replaying handler
A RecordingJsonHandler
is a JsonHandler
that creates a JsonReplay
of the described JSON document. A JsonReplay
represents a sequence of JsonEvents
and is able to replay these events to another JsonHandler
.
// a JsonDocument
JsonDocument document = ...
// a JsonHandler
JsonHandler handler = ...
// returns a JsonReplay
JsonReplay replay = document.handle(new RecordingJsonHandler());
// replay the JsonDocument to the JsonHandler
replay.replay(handler);
A RecordingJsonHandler
is useful when testing a component that takes a JsonHandler
, because the generated JsonReplay
can be used to easily check, if the correct callback methods have been called.
// a JsonReplay
JsonReply replay = ...
// check the replay against an expected sequence of JsonEvents
replay.assertEquals(
new DocumentBeginJsonEvent(),
new NullJsonEvent(),
new DocumentEndJsonEvent(),
);