T
- the type under testpublic class GsonTester<T> extends AbstractJsonMarshalTester<T>
initFields(Object, Gson)
, for example: public class ExampleObjectJsonTests { private GsonTester<ExampleObject> json; @Before public void setup() { Gson gson = new GsonBuilder().create(); GsonTester.initFields(this, gson); } @Test public void testWriteJson() throws IOException { ExampleObject object = //... assertThat(json.write(object)).isEqualToJson("expected.json"); } }See
AbstractJsonMarshalTester
for more details.AbstractJsonMarshalTester.FieldInitializer<M>
Modifier | Constructor and Description |
---|---|
|
GsonTester(Class<?> resourceLoadClass,
ResolvableType type,
com.google.gson.Gson gson)
Create a new
GsonTester instance. |
protected |
GsonTester(com.google.gson.Gson gson)
Create a new uninitialized
GsonTester instance. |
Modifier and Type | Method and Description |
---|---|
static void |
initFields(Object testInstance,
com.google.gson.Gson gson)
Utility method to initialize
GsonTester fields. |
static void |
initFields(Object testInstance,
ObjectFactory<com.google.gson.Gson> gson)
Utility method to initialize
GsonTester fields. |
protected T |
readObject(Reader reader,
ResolvableType type)
Read from the specified reader to create an object of the specified type.
|
protected String |
writeObject(T value,
ResolvableType type)
Write the specified object to a JSON string.
|
getResourceLoadClass, getType, initialize, parse, parse, parseObject, parseObject, read, read, read, read, read, readObject, readObject, readObject, readObject, readObject, readObject, write
protected GsonTester(com.google.gson.Gson gson)
GsonTester
instance.gson
- the Gson instancepublic GsonTester(Class<?> resourceLoadClass, ResolvableType type, com.google.gson.Gson gson)
GsonTester
instance.resourceLoadClass
- the source class used to load resourcestype
- the type under testgson
- the Gson instanceinitFields(Object, Gson)
protected String writeObject(T value, ResolvableType type) throws IOException
AbstractJsonMarshalTester
writeObject
in class AbstractJsonMarshalTester<T>
value
- the source value (never null
)type
- the resulting type (never null
)IOException
- on write errorprotected T readObject(Reader reader, ResolvableType type) throws IOException
AbstractJsonMarshalTester
readObject
in class AbstractJsonMarshalTester<T>
reader
- the source reader (never null
)type
- the resulting type (never null
)IOException
- on read errorpublic static void initFields(Object testInstance, com.google.gson.Gson gson)
GsonTester
fields. See class-level documentation
for example usage.testInstance
- the test instancegson
- the Gson instancepublic static void initFields(Object testInstance, ObjectFactory<com.google.gson.Gson> gson)
GsonTester
fields. See class-level documentation
for example usage.testInstance
- the test instancegson
- an object factory to create the Gson instanceCopyright © 2019 Pivotal Software, Inc.. All rights reserved.