NetworkAddressEntityDataMapper { public NetworkAddressEntity transformInverse(NetworkAddress networkAddress) { if (networkAddress == null) { return null; } return NetworkAddressEntity.builder() .ip(networkAddress.ip()) .port(networkAddress.port()) .build(); } @Inject  NetworkAddressEntityDataMapper(); NetworkAddress transform(NetworkAddressEntity networkAddressEntity); Collection<NetworkAddress> transform(
      Collection<NetworkAddressEntity> networkAddressEntities); NetworkAddressEntity transformInverse(NetworkAddress networkAddress); Collection<NetworkAddressEntity> transformInverse(
      Collection<NetworkAddress> networkAddresses);  }
@Test public void shouldReturnNullNetworkAddressEntityGivenNullNetworkAddress() throws Exception { NetworkAddress networkAddress = null; NetworkAddressEntity networkAddressEntity = networkAddressEntityDataMapper.transformInverse(networkAddress); assertThat(networkAddressEntity, nullValue()); }
@Test public void shouldProperlyMapNetworkAddressIntoNetworkAddressEntity() throws Exception { NetworkAddress networkAddress = NetworkAddress.builder() .ip("192.168.24.33") .port(9991) .build(); NetworkAddressEntity networkAddressEntity = networkAddressEntityDataMapper.transformInverse(networkAddress); assertThat(networkAddressEntity, notNullValue()); assertThat(networkAddressEntity, instanceOf(NetworkAddressEntity.class)); assertThat(networkAddressEntity.ip(), is("192.168.24.33")); assertThat(networkAddressEntity.port(), is(9991)); }
@Test public void shouldProperlyMapNetworkAddressCollectionIntoNetworkAddressEntityCollection() throws Exception { NetworkAddress networkAddress1 = NetworkAddress.builder() .ip("192.168.24.33") .port(9991) .build(); NetworkAddress networkAddress2 = NetworkAddress.builder() .ip("192.168.53.88") .port(9944) .build(); ArrayList<NetworkAddress> networkAddresses = new ArrayList<>(); networkAddresses.add(networkAddress1); networkAddresses.add(networkAddress2); Collection<NetworkAddressEntity> networkAddressEntities = networkAddressEntityDataMapper.transformInverse(networkAddresses); assertThat(networkAddressEntities, notNullValue()); assertThat(networkAddressEntities.size(), is(2)); NetworkAddressEntity networkAddressEntity1 = (NetworkAddressEntity) networkAddressEntities.toArray()[0]; assertThat(networkAddressEntity1, notNullValue()); assertThat(networkAddressEntity1.ip(), is("192.168.24.33")); assertThat(networkAddressEntity1.port(), is(9991)); NetworkAddressEntity networkAddressEntity2 = (NetworkAddressEntity) networkAddressEntities.toArray()[1]; assertThat(networkAddressEntity2, notNullValue()); assertThat(networkAddressEntity2.ip(), is("192.168.53.88")); assertThat(networkAddressEntity2.port(), is(9944)); }