DepartmentNameConverter extends AbstractConverter<DepartmentName, DepartmentNameResource> { @Override public DepartmentNameResource convert(final DepartmentName source, final DepartmentNameResource target) { if (source.getDepartment() != null) { target.setDepartmentId(source.getDepartment().getId()); } if (source.getLanguage() != null) { target.setLanguageId(source.getLanguage().getId()); } target.setId(source.getId()); target.setAbbrName(source.getAbbrName()); target.setName(source.getName()); return target; }  @Override DepartmentNameResource convert(final DepartmentName source, final DepartmentNameResource target); @Override DepartmentNameResource convert(final DepartmentName 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 source = new DepartmentName(); source.setId(id); source.setDepartment(department); source.setLanguage(language); source.setAbbrName(abbrName); source.setName(name); DepartmentNameResource expected = new DepartmentNameResource(); expected.setId(id); expected.setDepartmentId(departmentId); expected.setLanguageId(languageId); expected.setAbbrName(abbrName); expected.setName(name); DepartmentNameResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { DepartmentName source = new DepartmentName(); DepartmentNameResource expected = new DepartmentNameResource(); DepartmentNameResource actual = unit.convert(source); assertEquals(expected, actual); }