NetworkAddressModelDataMapper { public NetworkAddress transformInverse(NetworkAddressModel networkAddressModel) { if (networkAddressModel == null) { throw new IllegalArgumentException("Cannot transform a null NetworkAddressModel object."); } return NetworkAddress.builder() .ip(networkAddressModel.ip()) .port(networkAddressModel.port()) .build(); } @Inject  NetworkAddressModelDataMapper(); NetworkAddressModel transform(NetworkAddress networkAddress); Collection<NetworkAddressModel> transform(Collection<NetworkAddress> networkAddresses); NetworkAddress transformInverse(NetworkAddressModel networkAddressModel); Collection<NetworkAddress> transformInverse(
      Collection<NetworkAddressModel> networkAddressModels);  }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionGivenNullNetworkAddressModel() throws Exception { NetworkAddressModel networkAddressModel = null; networkAddressModelDataMapper.transformInverse(networkAddressModel); }
@Test public void shouldProperlyMapNetworkAddressModelIntoNetworkAddress() throws Exception { NetworkAddressModel networkAddressModel = NetworkAddressModel.builder() .ip("192.168.1.45") .port(9999) .build(); NetworkAddress networkAddress = networkAddressModelDataMapper.transformInverse(networkAddressModel); assertThat(networkAddress, notNullValue()); assertThat(networkAddress, instanceOf(NetworkAddress.class)); assertThat(networkAddress.ip(), notNullValue()); assertThat(networkAddress.ip(), is("192.168.1.45")); assertThat(networkAddress.port(), is(9999)); }
@Test public void shouldProperlyMapNetworkAddressModelCollectionIntoNetworkAddressCollection() throws Exception { NetworkAddressModel networkAddressModel1 = NetworkAddressModel.builder() .ip("192.168.1.45") .port(9999) .build(); NetworkAddressModel networkAddressModel2 = NetworkAddressModel.builder() .ip("192.168.1.80") .port(1111) .build(); ArrayList<NetworkAddressModel> networkAddressModels = new ArrayList<>(); networkAddressModels.add(networkAddressModel1); networkAddressModels.add(networkAddressModel2); Collection<NetworkAddress> networkAddresses = networkAddressModelDataMapper.transformInverse(networkAddressModels); assertThat(networkAddresses, notNullValue()); assertThat(networkAddresses.size(), is(2)); NetworkAddress networkAddress1 = (NetworkAddress) networkAddresses.toArray()[0]; assertThat(networkAddress1, notNullValue()); assertThat(networkAddress1, instanceOf(NetworkAddress.class)); assertThat(networkAddress1.ip(), notNullValue()); assertThat(networkAddress1.ip(), is("192.168.1.45")); assertThat(networkAddress1.port(), is(9999)); NetworkAddress networkAddress2 = (NetworkAddress) networkAddresses.toArray()[1]; assertThat(networkAddress2, notNullValue()); assertThat(networkAddress2, instanceOf(NetworkAddress.class)); assertThat(networkAddress2.ip(), notNullValue()); assertThat(networkAddress2.ip(), is("192.168.1.80")); assertThat(networkAddress2.port(), is(1111)); }