UserModelDataMapper { public UserModel transform(User user) { if (user == null) { throw new IllegalArgumentException("Cannot transform a null value"); } UserModel userModel = new UserModel(user.getUserId()); userModel.setFullName(user.getFullName()); return userModel; }  UserModel transform(User user); Collection<UserModel> transform(Collection<User> usersCollection);  }
@Test public void testTransformUser() { User user = createFakeUser(); UserModel userModel = userModelDataMapper.transform(user); assertThat(userModel, is(instanceOf(UserModel.class))); assertThat(userModel.getUserId(), is(FAKE_USER_ID)); assertThat(userModel.getFullName(), is(FAKE_FULLNAME)); }
@Test public void testTransformUserCollection() { User mockUserOne = mock(User.class); User mockUserTwo = mock(User.class); List<User> userList = new ArrayList<>(5); userList.add(mockUserOne); userList.add(mockUserTwo); Collection<UserModel> userModelList = userModelDataMapper.transform(userList); assertThat(userModelList.toArray()[0], is(instanceOf(UserModel.class))); assertThat(userModelList.toArray()[1], is(instanceOf(UserModel.class))); assertThat(userModelList.size(), is(2)); }