DepartmentContactConverter extends AbstractConverter<DepartmentContact, DepartmentContactResource> { @Override public DepartmentContactResource convert(final DepartmentContact source, final DepartmentContactResource target) { if (source.getDepartment() != null) { target.setDepartmentId(source.getDepartment().getId()); } if (source.getContactType() != null) { target.setContactTypeId(source.getContactType().getId()); } target.setId(source.getId()); target.setValue(source.getValue()); return target; }  @Override DepartmentContactResource convert(final DepartmentContact source, final DepartmentContactResource target); @Override DepartmentContactResource convert(final DepartmentContact source);  }
@Test public void testConvert() throws Exception { Long id = 1L; String value = "sfas"; Long departmentId = 2L; Department department = new Department(); department.setId(departmentId); Long contactTypeId = 3L; ContactType contactType = new ContactType(); contactType.setId(contactTypeId); DepartmentContact source = new DepartmentContact(); source.setDepartment(department); source.setContactType(contactType); source.setId(id); source.setValue(value); DepartmentContactResource expected = new DepartmentContactResource(); expected.setDepartmentId(departmentId); expected.setContactTypeId(contactTypeId); expected.setId(id); expected.setValue(value); DepartmentContactResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { DepartmentContact source = new DepartmentContact(); DepartmentContactResource expected = new DepartmentContactResource(); DepartmentContactResource actual = unit.convert(source); assertEquals(expected, actual); }