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