DepartmentAddressConverter extends AbstractConverter<DepartmentAddress, DepartmentAddressResource> { @Override public DepartmentAddressResource convert(final DepartmentAddress source, final DepartmentAddressResource target) { if (source.getDepartment() != null) { target.setDepartmentId(source.getDepartment().getId()); } if (source.getAddressType() != null) { target.setAddressTypeId(source.getAddressType().getId()); } if (source.getAdminUnit() != null) { target.setAdminUnitId(source.getAdminUnit().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 DepartmentAddressResource convert(final DepartmentAddress source, final DepartmentAddressResource target); @Override DepartmentAddressResource convert(final DepartmentAddress 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); Long id = 9L; String zipCode = "zip Code"; String street = "street "; String house = "house"; String apartment = "1L"; DepartmentAddressResource expected = new DepartmentAddressResource(); expected.setDepartmentId(departmentId); expected.setAddressTypeId(addressTypeId); expected.setAdminUnitId(adminUnitId); expected.setStreetTypeId(streetTypeId); expected.setZipCode(zipCode); expected.setStreet(street); expected.setHouse(house); expected.setApartment(apartment); expected.setId(id); DepartmentAddress source = new DepartmentAddress(); source.setId(id); source.setDepartment(department); source.setAddressType(addressType); source.setAdminUnit(adminUnit); source.setStreetType(streetType); source.setZipCode(zipCode); source.setStreet(street); source.setHouse(house); source.setApartment(apartment); DepartmentAddressResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { DepartmentAddressResource expected = new DepartmentAddressResource(); DepartmentAddress source = new DepartmentAddress(); DepartmentAddressResource actual = unit.convert(source); assertEquals(expected, actual); }