Class JsonbTester<T>
- java.lang.Object
- org.springframework.boot.test.json.AbstractJsonMarshalTester<T>
- org.springframework.boot.test.json.JsonbTester<T>
- Type Parameters:
T
- the type under test
public class JsonbTester<T> extends AbstractJsonMarshalTester<T>
AssertJ based JSON tester backed by Jsonb. Usually instantiated viainitFields(Object, Jsonb)
, for example:public class ExampleObjectJsonTests { private JsonbTester<ExampleObject> json; @Before public void setup() { Jsonb jsonb = JsonbBuilder.create(); JsonbTester.initFields(this, jsonb); } @Test public void testWriteJson() throws IOException { ExampleObject object = // ... assertThat(json.write(object)).isEqualToJson("expected.json"); } }
SeeAbstractJsonMarshalTester
for more details.- Since:
- 2.0.0
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.boot.test.json.AbstractJsonMarshalTester
AbstractJsonMarshalTester.FieldInitializer<M>
Constructor Summary
Constructors Modifier Constructor Description JsonbTester(Class<?> resourceLoadClass, org.springframework.core.ResolvableType type, javax.json.bind.Jsonb jsonb)
Create a newJsonbTester
instance.protected
JsonbTester(javax.json.bind.Jsonb jsonb)
Create a new uninitializedJsonbTester
instance.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
initFields(Object testInstance, javax.json.bind.Jsonb jsonb)
Utility method to initializeJsonbTester
fields.static void
initFields(Object testInstance, org.springframework.beans.factory.ObjectFactory<javax.json.bind.Jsonb> jsonb)
Utility method to initializeJsonbTester
fields.protected T
readObject(Reader reader, org.springframework.core.ResolvableType type)
Read from the specified reader to create an object of the specified type.protected String
writeObject(T value, org.springframework.core.ResolvableType type)
Write the specified object to a JSON string.Methods inherited from class org.springframework.boot.test.json.AbstractJsonMarshalTester
getResourceLoadClass, getType, initialize, parse, parse, parseObject, parseObject, read, read, read, read, read, readObject, readObject, readObject, readObject, readObject, readObject, write
Constructor Detail
JsonbTester
protected JsonbTester(javax.json.bind.Jsonb jsonb)
Create a new uninitializedJsonbTester
instance.- Parameters:
jsonb
- the Jsonb instance
JsonbTester
public JsonbTester(Class<?> resourceLoadClass, org.springframework.core.ResolvableType type, javax.json.bind.Jsonb jsonb)
Create a newJsonbTester
instance.- Parameters:
resourceLoadClass
- the source class used to load resourcestype
- the type under testjsonb
- the Jsonb instance- See Also:
initFields(Object, Jsonb)
Method Detail
writeObject
protected String writeObject(T value, org.springframework.core.ResolvableType type) throws IOException
Description copied from class:AbstractJsonMarshalTester
Write the specified object to a JSON string.- Specified by:
writeObject
in classAbstractJsonMarshalTester<T>
- Parameters:
value
- the source value (nevernull
)type
- the resulting type (nevernull
)- Returns:
- the JSON string
- Throws:
IOException
- on write error
readObject
protected T readObject(Reader reader, org.springframework.core.ResolvableType type) throws IOException
Description copied from class:AbstractJsonMarshalTester
Read from the specified reader to create an object of the specified type.- Specified by:
readObject
in classAbstractJsonMarshalTester<T>
- Parameters:
reader
- the source reader (nevernull
)type
- the resulting type (nevernull
)- Returns:
- the resulting object
- Throws:
IOException
- on read error
initFields
public static void initFields(Object testInstance, javax.json.bind.Jsonb jsonb)
Utility method to initializeJsonbTester
fields. Seeclass-level documentation
for example usage.- Parameters:
testInstance
- the test instancejsonb
- the Jsonb instance
initFields
public static void initFields(Object testInstance, org.springframework.beans.factory.ObjectFactory<javax.json.bind.Jsonb> jsonb)
Utility method to initializeJsonbTester
fields. Seeclass-level documentation
for example usage.- Parameters:
testInstance
- the test instancejsonb
- an object factory to create the Jsonb instance