Search in sources :

Example 1 with MarvelResultsDeserializer

use of saulmm.avengers.rest.utils.deserializers.MarvelResultsDeserializer in project Avengers by saulmm.

the class GsonDeserializersTest method testThatACollectionDeserialzierDeserializesACollection.

@Test
public void testThatACollectionDeserialzierDeserializesACollection() throws Exception {
    MarvelResultsDeserializer<CollectionItem> marvelResultsDeserializer = new MarvelResultsDeserializer<>();
    JsonElement collectionElement = new JsonParser().parse(getComicsCollectionJsonString());
    Type t = new TypeToken<List<CollectionItem>>() {
    }.getType();
    List<CollectionItem> collectionList = marvelResultsDeserializer.deserialize(collectionElement, t, mock(JsonDeserializationContext.class));
    assertThat(collectionList.isEmpty(), is(false));
    assertNotNull(collectionList.get(0).getThumbnail());
}
Also used : Type(java.lang.reflect.Type) JsonDeserializationContext(com.google.gson.JsonDeserializationContext) JsonElement(com.google.gson.JsonElement) List(java.util.List) CollectionItem(saulmm.avengers.entities.CollectionItem) MarvelResultsDeserializer(saulmm.avengers.rest.utils.deserializers.MarvelResultsDeserializer) JsonParser(com.google.gson.JsonParser) Test(org.junit.Test)

Example 2 with MarvelResultsDeserializer

use of saulmm.avengers.rest.utils.deserializers.MarvelResultsDeserializer in project Avengers by saulmm.

the class GsonDeserializersTest method testThatACharacterDeseralizersDeserializesACharacter.

@Test
public void testThatACharacterDeseralizersDeserializesACharacter() throws Exception {
    MarvelResultsDeserializer<MarvelCharacter> marvelResultsDeserializer = new MarvelResultsDeserializer<>();
    JsonElement characterElement = new JsonParser().parse(getCharacterJsonString());
    Type t = new TypeToken<List<MarvelCharacter>>() {
    }.getType();
    List<MarvelCharacter> characterList = marvelResultsDeserializer.deserialize(characterElement, t, mock(JsonDeserializationContext.class));
    assertThat(characterList.isEmpty(), is(false));
    assertThat(characterList.get(0).getName(), is("3-D Man"));
}
Also used : Type(java.lang.reflect.Type) JsonDeserializationContext(com.google.gson.JsonDeserializationContext) JsonElement(com.google.gson.JsonElement) List(java.util.List) MarvelCharacter(saulmm.avengers.entities.MarvelCharacter) MarvelResultsDeserializer(saulmm.avengers.rest.utils.deserializers.MarvelResultsDeserializer) JsonParser(com.google.gson.JsonParser) Test(org.junit.Test)

Aggregations

JsonDeserializationContext (com.google.gson.JsonDeserializationContext)2 JsonElement (com.google.gson.JsonElement)2 JsonParser (com.google.gson.JsonParser)2 Type (java.lang.reflect.Type)2 List (java.util.List)2 Test (org.junit.Test)2 MarvelResultsDeserializer (saulmm.avengers.rest.utils.deserializers.MarvelResultsDeserializer)2 CollectionItem (saulmm.avengers.entities.CollectionItem)1 MarvelCharacter (saulmm.avengers.entities.MarvelCharacter)1