AssetAddressResourceConverter extends AbstractConverter<AssetAddressResource, AssetAddress> { @Override public AssetAddress convert(final AssetAddressResource source, final AssetAddress target) { if (source.getAdminUnitId() != null) { AdminUnit adminUnit = new AdminUnit(); adminUnit.setId(source.getAdminUnitId()); target.setAdminUnit(adminUnit); } if (source.getAssetId() != null) { Asset asset = new Asset(); asset.setId(source.getAssetId()); target.setAsset(asset); } if (source.getAddressTypeId() != null) { AddressType addressType = new AddressType(); addressType.setId(source.getAddressTypeId()); target.setAddressType(addressType); } if (source.getStreetTypeId() != null) { StreetType streetType = new StreetType(); streetType.setId(source.getStreetTypeId()); target.setStreetType(streetType); } target.setZipCode(source.getZipCode()); target.setStreet(source.getStreet()); target.setHouse(source.getHouse()); target.setApartment(source.getApartment()); return target; }  @Override AssetAddress convert(final AssetAddressResource source, final AssetAddress target); @Override AssetAddress convert(final AssetAddressResource 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 source = new AssetAddressResource(); source.setAdminUnitId(adminUnitId); source.setAssetId(assetId); source.setAddressTypeId(addressTypeId); source.setStreetTypeId(streetTypeId); source.setZipCode(zipCode); source.setStreet(street); source.setHouse(house); source.setApartment(apartment); AssetAddress expected = new AssetAddress(); expected.setAdminUnit(adminUnit); expected.setAsset(asset); expected.setAddressType(addressType); expected.setStreetType(streetType); expected.setZipCode(zipCode); expected.setStreet(street); expected.setHouse(house); expected.setApartment(apartment); AssetAddress actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { AssetAddressResource source = new AssetAddressResource(); AssetAddress expected = new AssetAddress(); AssetAddress actual = unit.convert(source); assertEquals(expected, actual); }