AssetAddressConverter extends AbstractConverter<AssetAddress, AssetAddressResource> { @Override public AssetAddressResource convert(final AssetAddress source, final AssetAddressResource target) { if (source.getAdminUnit() != null) { target.setAdminUnitId(source.getAdminUnit().getId()); } if (source.getAsset() != null) { target.setAssetId(source.getAsset().getId()); } if (source.getAddressType() != null) { target.setAddressTypeId(source.getAddressType().getId()); } if (source.getStreetType() != null) { target.setStreetTypeId(source.getStreetType().getId()); } target.setId(source.getId()); target.setZipCode(source.getZipCode()); target.setStreet(source.getStreet()); target.setHouse(source.getHouse()); target.setApartment(source.getApartment()); return target; }  @Override AssetAddressResource convert(final AssetAddress source, final AssetAddressResource target); @Override AssetAddressResource convert(final AssetAddress source);  }
@Test public void testConvert() throws Exception { Long adminUnitId = 1L; AdminUnit adminUnit = new AdminUnit(); adminUnit.setId(adminUnitId); Long assetId = 2L; Asset asset = new Asset(); asset.setId(assetId); Long addressTypeId = 3L; AddressType addressType = new AddressType(); addressType.setId(addressTypeId); Long streetTypeId = 4L; StreetType streetType = new StreetType(); streetType.setId(streetTypeId); String zipCode = "zip code"; String street = "street"; String house = "house"; String apartment = "apartment"; AssetAddressResource expected = new AssetAddressResource(); expected.setAdminUnitId(adminUnitId); expected.setAssetId(assetId); expected.setAddressTypeId(addressTypeId); expected.setStreetTypeId(streetTypeId); expected.setZipCode(zipCode); expected.setStreet(street); expected.setHouse(house); expected.setApartment(apartment); AssetAddress source = new AssetAddress(); source.setAdminUnit(adminUnit); source.setAsset(asset); source.setAddressType(addressType); source.setStreetType(streetType); source.setZipCode(zipCode); source.setStreet(street); source.setHouse(house); source.setApartment(apartment); AssetAddressResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { AssetAddressResource expected = new AssetAddressResource(); AssetAddress source = new AssetAddress(); AssetAddressResource actual = unit.convert(source); assertEquals(expected, actual); }