DepartmentContactResourceConverter extends AbstractConverter<DepartmentContactResource, DepartmentContact> { @Override public DepartmentContact convert(final DepartmentContactResource source, final DepartmentContact target) { if (source.getDepartmentId() != null) { Department department = new Department(); department.setId(source.getDepartmentId()); target.setDepartment(department); } if (source.getContactTypeId() != null) { ContactType contactType = new ContactType(); contactType.setId(source.getContactTypeId()); target.setContactType(contactType); } target.setValue(source.getValue()); return target; }  @Override DepartmentContact convert(final DepartmentContactResource source, final DepartmentContact target); @Override DepartmentContact convert(final DepartmentContactResource 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 expected = new DepartmentContact(); expected.setDepartment(department); expected.setContactType(contactType); expected.setValue(value); DepartmentContactResource source = new DepartmentContactResource(); source.setDepartmentId(departmentId); source.setContactTypeId(contactTypeId); source.setId(id); source.setValue(value); DepartmentContact actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { DepartmentContact expected = new DepartmentContact(); DepartmentContactResource source = new DepartmentContactResource(); DepartmentContact actual = unit.convert(source); assertEquals(expected, actual); }