DepartmentAddressResourceConverter extends AbstractConverter<DepartmentAddressResource, DepartmentAddress> { @Override public DepartmentAddress convert(final DepartmentAddressResource source, final DepartmentAddress target) { if (source.getDepartmentId() != null) { Department department = new Department(); department.setId(source.getDepartmentId()); target.setDepartment(department); } 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); } target.setZipCode(source.getZipCode()); target.setStreet(source.getStreet()); target.setHouse(source.getHouse()); target.setApartment(source.getApartment()); return target; }  @Override DepartmentAddress convert(final DepartmentAddressResource source, final DepartmentAddress target); @Override DepartmentAddress convert(final DepartmentAddressResource source);  }
@Test public void testConvert() throws Exception { Long departmentId = 1L; Department department = new Department(); department.setId(departmentId); Long addressTypeId = 2L; AddressType addressType = new AddressType(); addressType.setId(addressTypeId); Long adminUnitId = 3L; AdminUnit adminUnit = new AdminUnit(); adminUnit.setId(adminUnitId); Long streetTypeId = 4L; StreetType streetType = new StreetType(); streetType.setId(streetTypeId); String zipCode = "zip Code"; String street = "street "; String house = "house"; String apartment = "1L"; DepartmentAddressResource source = new DepartmentAddressResource(); source.setDepartmentId(departmentId); source.setAddressTypeId(addressTypeId); source.setAdminUnitId(adminUnitId); source.setStreetTypeId(streetTypeId); source.setZipCode(zipCode); source.setStreet(street); source.setHouse(house); source.setApartment(apartment); DepartmentAddress expected = new DepartmentAddress(); expected.setDepartment(department); expected.setAddressType(addressType); expected.setAdminUnit(adminUnit); expected.setStreetType(streetType); expected.setZipCode(zipCode); expected.setStreet(street); expected.setHouse(house); expected.setApartment(apartment); DepartmentAddress actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { DepartmentAddressResource source = new DepartmentAddressResource(); DepartmentAddress expected = new DepartmentAddress(); DepartmentAddress actual = unit.convert(source); assertEquals(expected, actual); }