UserEntityJsonMapper { public List<UserEntity> transformUserEntityCollection(String userListJsonResponse) throws JsonSyntaxException { List<UserEntity> userEntityCollection; try { Type listOfUserEntityType = new TypeToken<List<UserEntity>>() {}.getType(); userEntityCollection = this.gson.fromJson(userListJsonResponse, listOfUserEntityType); return userEntityCollection; } catch (JsonSyntaxException jsonException) { throw jsonException; } } UserEntityJsonMapper(); UserEntity transformUserEntity(String userJsonResponse); List<UserEntity> transformUserEntityCollection(String userListJsonResponse);  }
@Test public void testTransformUserEntityCollectionHappyCase() { Collection<UserEntity> userEntityCollection = userEntityJsonMapper.transformUserEntityCollection( JSON_RESPONSE_USER_COLLECTION); assertThat(((UserEntity) userEntityCollection.toArray()[0]).getUserId(), is(1)); assertThat(((UserEntity) userEntityCollection.toArray()[1]).getUserId(), is(12)); assertThat(userEntityCollection.size(), is(2)); }
@Test public void testTransformUserEntityCollectionNotValidResponse() { expectedException.expect(JsonSyntaxException.class); userEntityJsonMapper.transformUserEntityCollection("Tony Stark"); }