DepartmentSpecialtyResourceConverter extends AbstractConverter<DepartmentSpecialtyResource, DepartmentSpecialty> { @Override public DepartmentSpecialty convert(final DepartmentSpecialtyResource source, final DepartmentSpecialty target) { if (source.getDepartmentId() != null) { Department department = new Department(); department.setId(source.getDepartmentId()); target.setDepartment(department); } if (source.getSpecialtyId() != null) { Specialty specialty = new Specialty(); specialty.setId(source.getSpecialtyId()); target.setSpecialty(specialty); } return target; }  @Override DepartmentSpecialty convert(final DepartmentSpecialtyResource source, final DepartmentSpecialty target); @Override DepartmentSpecialty convert(final DepartmentSpecialtyResource source);  }
@Test public void testConvert() throws Exception { Long id = 1L; Long departmentId = 2L; Long specialtyId = 3L; Specialty specialty = new Specialty(); specialty.setId(specialtyId); Department department = new Department(); department.setId(departmentId); DepartmentSpecialty expected = new DepartmentSpecialty(); expected.setId(id); expected.setDepartment(department); expected.setSpecialty(specialty); DepartmentSpecialtyResource source = new DepartmentSpecialtyResource(); source.setId(id); source.setDepartmentId(departmentId); source.setSpecialtyId(specialtyId); DepartmentSpecialty actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { DepartmentSpecialty expected = new DepartmentSpecialty(); DepartmentSpecialtyResource source = new DepartmentSpecialtyResource(); DepartmentSpecialty actual = unit.convert(source); assertEquals(expected, actual); }