UserEntityJsonMapper { public UserEntity transformUserEntity(String userJsonResponse) throws JsonSyntaxException { try { Type userEntityType = new TypeToken<UserEntity>() {}.getType(); UserEntity userEntity = this.gson.fromJson(userJsonResponse, userEntityType); return userEntity; } catch (JsonSyntaxException jsonException) { throw jsonException; } } UserEntityJsonMapper(); UserEntity transformUserEntity(String userJsonResponse); List<UserEntity> transformUserEntityCollection(String userListJsonResponse);  }
@Test public void testTransformUserEntityHappyCase() { UserEntity userEntity = userEntityJsonMapper.transformUserEntity(JSON_RESPONSE_USER_DETAILS); assertThat(userEntity.getUserId(), is(1)); assertThat(userEntity.getFullname(), is(equalTo("Simon Hill"))); assertThat(userEntity.getEmail(), is(equalTo("jcooper@babbleset.edu"))); }
@Test public void testTransformUserEntityNotValidResponse() { expectedException.expect(JsonSyntaxException.class); userEntityJsonMapper.transformUserEntity("ironman"); }