Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,52 @@
*
*/
public class JsonUtilTest {


// Test class used to ensure exception is thrown inside of JsonUtil
public class ClassWithPrivateFields {
ClassWithPrivateFields(int id, String name){
id = id;
name = name;
}
int id;
String name;
}

@Test
public void testSerialize() throws SerializationException{
public void testSerialize() throws SerializationException {
Card card = new Card.Builder().number("12345").build();
String cardStr = JsonUtil.serialize(card);
Assert.assertNotNull(cardStr);
String result = "{\n \"number\" : \"12345\"\n}";
Assert.assertEquals(cardStr, result);
}


@Test
public void testNullSerialize() throws SerializationException {
String cardStr = JsonUtil.serialize(null);
Assert.assertNull(cardStr);
}

@Test(expectedExceptions = SerializationException.class)
public void testErrorSerialize() throws SerializationException {
// Serializing this causes a InvalidDefinitionException to be thrown
ClassWithPrivateFields classWithPrivateFields = new ClassWithPrivateFields(1, "John");
JsonUtil.serialize(classWithPrivateFields);
}

@Test
public void testDeserialize() throws SerializationException {
String cardStr = "{\"number\":\"12345\"}";
Card card = (Card) JsonUtil.deserialize(cardStr, new TypeReference<Card>() {} );
Assert.assertEquals(card.getNumber(), "12345");
}


@Test(expectedExceptions = SerializationException.class)
public void testErrorDeserialize() throws SerializationException {
String cardStr = "{\"number\":\"12345\"\"}";
JsonUtil.deserialize(cardStr, new TypeReference<Card>() {} );
}

@SuppressWarnings("unchecked")
@Test
public void testDeserializeList() throws SerializationException {
Expand All @@ -57,5 +85,5 @@ public void testDeserializeList() throws SerializationException {
Assert.assertEquals(cards.get(0).getNumber(), "12345");
}


}