PersonAddressConverter extends AbstractConverter<PersonAddress, PersonAddressResource> { @Override public PersonAddressResource convert(final PersonAddress source, final PersonAddressResource target) { if (source.getAddressType() != null) { target.setAddressTypeId(source.getAddressType().getId()); } if (source.getAdminUnit() != null) { target.setAdminUnitId(source.getAdminUnit().getId()); } if (source.getAsset() != null) { target.setAssetId(source.getAsset().getId()); } if (source.getPerson() != null) { target.setPersonId(source.getPerson().getId()); } if (source.getStreetType() != null) { target.setStreetTypeId(source.getStreetType().getId()); } target.setZipCode(source.getZipCode()); target.setStreet(source.getStreet()); target.setApartment(source.getApartment()); target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); target.setHouse(source.getHouse()); target.setId(source.getId()); return target; }  @Override PersonAddressResource convert(final PersonAddress source, final PersonAddressResource target); @Override PersonAddressResource convert(final PersonAddress 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 source = new PersonAddress(); source.setAddressType(addressType); source.setAdminUnit(adminUnit); source.setAsset(asset); source.setPerson(person); source.setStreetType(streetType); source.setZipCode(zipCode); source.setStreet(street); source.setApartment(apartment); source.setBegDate(begDate); source.setEndDate(endDate); source.setHouse(house); source.setId(id); PersonAddressResource expected = new PersonAddressResource(); expected.setAddressTypeId(addressTypeId); expected.setAdminUnitId(adminUnitId); expected.setAssetId(assetId); expected.setPersonId(personId); expected.setStreetTypeId(streetTypeId); expected.setZipCode(zipCode); expected.setStreet(street); expected.setApartment(apartment); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setHouse(house); expected.setId(id); PersonAddressResource 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 source = new PersonAddress(); source.setZipCode(zipCode); source.setStreet(street); source.setApartment(apartment); source.setBegDate(begDate); source.setEndDate(endDate); source.setHouse(house); source.setId(id); PersonAddressResource expected = new PersonAddressResource(); expected.setZipCode(zipCode); expected.setStreet(street); expected.setApartment(apartment); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setHouse(house); expected.setId(id); PersonAddressResource actual = unit.convert(source); assertEquals(expected, actual); }