small testing cleaup

This commit is contained in:
eugenp 2014-09-11 18:42:37 +03:00
parent ee27f3d75a
commit 2b879ce8c3
1 changed files with 12 additions and 12 deletions

View File

@ -65,28 +65,28 @@ public class GsonSerializationTest {
@Test @Test
public void givenDate_whenSerializing_thenCorrect() { public void givenDate_whenSerializing_thenCorrect() {
Date sourceDate = new Date(1000000L); final Date sourceDate = new Date(1000000L);
Gson gson = new Gson(); final Gson gson = new Gson();
Type sourceDateType = new TypeToken<Date>() { final Type sourceDateType = new TypeToken<Date>() {
}.getType(); }.getType();
String jsonDate = gson.toJson(sourceDate, sourceDateType); String jsonDate = gson.toJson(sourceDate, sourceDateType);
// test
System.out.println("jsonDate:\n" + jsonDate); System.out.println("jsonDate:\n" + jsonDate);
String expectedResult = "\"Jan 1, 1970 3:16:40 AM\""; final String expectedResult = "\"Jan 1, 1970 3:16:40 AM\"";
assertTrue(jsonDate.equals(expectedResult)); assertTrue(jsonDate.equals(expectedResult));
} }
@Test @Test
public void givenUsingCustomDeserializer_whenFieldNotMatchesCriteria_thenIgnored() { public void givenUsingCustomDeserializer_whenFieldNotMatchesCriteria_thenIgnored() {
SourceClass sourceObject = new SourceClass(-1, "minus 1"); final SourceClass sourceObject = new SourceClass(-1, "minus 1");
GsonBuilder gsonBuildr = new GsonBuilder(); final GsonBuilder gsonBuildr = new GsonBuilder();
gsonBuildr.registerTypeAdapter(SourceClass.class, new IgnoringFieldsNotMatchingCriteriaSerializer()); gsonBuildr.registerTypeAdapter(SourceClass.class, new IgnoringFieldsNotMatchingCriteriaSerializer());
Gson gson = gsonBuildr.create(); final Gson gson = gsonBuildr.create();
Type sourceObjectType = new TypeToken<SourceClass>() { final Type sourceObjectType = new TypeToken<SourceClass>() {
}.getType(); }.getType();
String jsonString = gson.toJson(sourceObject, sourceObjectType); String jsonString = gson.toJson(sourceObject, sourceObjectType);
String expectedResult = "{\"stringValue\":\"minus 1\"}"; final String expectedResult = "{\"stringValue\":\"minus 1\"}";
assertEquals(expectedResult, jsonString); assertEquals(expectedResult, jsonString);
} }