DepartmentNameResourceConverter extends AbstractConverter<DepartmentNameResource, DepartmentName> { @Override public DepartmentName convert(final DepartmentNameResource source, final DepartmentName target) { if (source.getDepartmentId() != null) { Department department = new Department(); department.setId(source.getDepartmentId()); target.setDepartment(department); } if (source.getLanguageId() != null) { Language language = new Language(); language.setId(source.getLanguageId()); target.setLanguage(language); } target.setAbbrName(source.getAbbrName()); target.setName(source.getName()); return target; }  @Override DepartmentName convert(final DepartmentNameResource source, final DepartmentName target); @Override DepartmentName convert(final DepartmentNameResource source);  }
@Test public void testConvert() throws Exception { Long id = 1L; String abbrName = "abbr name"; String name = "fgsdfds"; Long departmentId = 2L; Department department = new Department(); department.setId(departmentId); Long languageId = 2L; Language language = new Language(); language.setId(languageId); DepartmentName expected = new DepartmentName(); expected.setId(id); expected.setDepartment(department); expected.setLanguage(language); expected.setAbbrName(abbrName); expected.setName(name); DepartmentNameResource source = new DepartmentNameResource(); source.setId(id); source.setDepartmentId(departmentId); source.setLanguageId(languageId); source.setAbbrName(abbrName); source.setName(name); DepartmentName actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { DepartmentName expected = new DepartmentName(); DepartmentNameResource source = new DepartmentNameResource(); DepartmentName actual = unit.convert(source); assertEquals(expected, actual); }