UserEntityDataMapper { public User transform(UserEntity userEntity) { User user = null; if (userEntity != null) { user = new User(userEntity.getUserId()); user.setCoverUrl(userEntity.getCoverUrl()); user.setFullName(userEntity.getFullname()); user.setDescription(userEntity.getDescription()); user.setFollowers(userEntity.getFollowers()); user.setEmail(userEntity.getEmail()); } return user; } UserEntityDataMapper(); User transform(UserEntity userEntity); List<User> transform(Collection<UserEntity> userEntityCollection);  }
@Test public void testTransformUserEntity() { UserEntity userEntity = createFakeUserEntity(); User user = userEntityDataMapper.transform(userEntity); assertThat(user, is(instanceOf(User.class))); assertThat(user.getUserId(), is(FAKE_USER_ID)); assertThat(user.getFullName(), is(FAKE_FULLNAME)); }
@Test public void testTransformUserEntityCollection() { UserEntity mockUserEntityOne = mock(UserEntity.class); UserEntity mockUserEntityTwo = mock(UserEntity.class); List<UserEntity> userEntityList = new ArrayList<UserEntity>(5); userEntityList.add(mockUserEntityOne); userEntityList.add(mockUserEntityTwo); Collection<User> userCollection = userEntityDataMapper.transform(userEntityList); assertThat(userCollection.toArray()[0], is(instanceOf(User.class))); assertThat(userCollection.toArray()[1], is(instanceOf(User.class))); assertThat(userCollection.size(), is(2)); }