PersonAddressResourceConverter extends AbstractConverter<PersonAddressResource, PersonAddress> { @Override public PersonAddress convert(final PersonAddressResource source, final PersonAddress target) { if (source.getPersonId() != null) { Person person = new Person(); person.setId(source.getPersonId()); target.setPerson(person); } if (source.getAddressTypeId() != null) { AddressType addressType = new AddressType(); addressType.setId(source.getAddressTypeId()); target.setAddressType(addressType); } if (source.getAdminUnitId() != null) { AdminUnit adminUnit = new AdminUnit(); adminUnit.setId(source.getAdminUnitId()); target.setAdminUnit(adminUnit); } if (source.getStreetTypeId() != null) { StreetType streetType = new StreetType(); streetType.setId(source.getStreetTypeId()); target.setStreetType(streetType); } if (source.getAssetId() != null) { Asset asset = new Asset(); asset.setId(source.getAssetId()); target.setAsset(asset); } target.setZipCode(source.getZipCode()); target.setHouse(source.getHouse()); target.setStreet(source.getStreet()); target.setApartment(source.getApartment()); target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); return target; }  @Override PersonAddress convert(final PersonAddressResource source, final PersonAddress target); @Override PersonAddress convert(final PersonAddressResource source);  }
@Test public void testConvert() throws Exception { Long addressTypeId = 1L; AddressType addressType = new AddressType(); addressType.setId(addressTypeId); Long adminUnitId = 2L; AdminUnit adminUnit = new AdminUnit(); adminUnit.setId(adminUnitId); Long assetId = 3L; Asset asset = new Asset(); asset.setId(assetId); Long personId = 4L; Person person = new Person(); person.setId(personId); Long streetTypeId = 5L; StreetType streetType = new StreetType(); streetType.setId(streetTypeId); String zipCode = "zip cide"; String street = "street"; String apartment = "apartment"; Date begDate = new Date(); Date endDate = new Date(); Long id = 2L; String house = "house"; PersonAddress expected = new PersonAddress(); expected.setAddressType(addressType); expected.setAdminUnit(adminUnit); expected.setAsset(asset); expected.setPerson(person); expected.setStreetType(streetType); expected.setZipCode(zipCode); expected.setStreet(street); expected.setApartment(apartment); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setHouse(house); expected.setId(id); PersonAddressResource source = new PersonAddressResource(); source.setAddressTypeId(addressTypeId); source.setAdminUnitId(adminUnitId); source.setAssetId(assetId); source.setPersonId(personId); source.setStreetTypeId(streetTypeId); source.setZipCode(zipCode); source.setStreet(street); source.setApartment(apartment); source.setBegDate(begDate); source.setEndDate(endDate); source.setHouse(house); source.setId(id); PersonAddress actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String zipCode = "zip cide"; String street = "street"; String apartment = "apartment"; Date begDate = new Date(); Date endDate = new Date(); Long id = 2L; String house = "house"; PersonAddress expected = new PersonAddress(); expected.setZipCode(zipCode); expected.setStreet(street); expected.setApartment(apartment); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setHouse(house); expected.setId(id); PersonAddressResource source = new PersonAddressResource(); source.setZipCode(zipCode); source.setStreet(street); source.setApartment(apartment); source.setBegDate(begDate); source.setEndDate(endDate); source.setHouse(house); source.setId(id); PersonAddress actual = unit.convert(source); assertEquals(expected, actual); }