PersonLanguageConverter extends AbstractConverter<PersonLanguage, PersonLanguageResource> { @Override public PersonLanguageResource convert(final PersonLanguage source, final PersonLanguageResource target) { if (source.getPerson() != null) { target.setPersonId(source.getPerson().getId()); } if (source.getLanguage() != null) { target.setLanguageId(source.getLanguage().getId()); } if (source.getLanguageLevel() != null) { target.setLanguageLevelId(source.getLanguageLevel().getId()); } target.setId(source.getId()); return target; }  @Override PersonLanguageResource convert(final PersonLanguage source, final PersonLanguageResource target); @Override PersonLanguageResource convert(final PersonLanguage source);  }
@Test public void testConvert() throws Exception { Long id = 6L; Long personId = 1L; Person person = new Person(); person.setId(personId); Long languageId = 2L; Language language = new Language(); language.setId(languageId); Long languageLevelId = 3L; LanguageLevel languageLevel = new LanguageLevel(); languageLevel.setId(languageLevelId); PersonLanguage source = new PersonLanguage(); source.setId(id); source.setPerson(person); source.setLanguage(language); source.setLanguageLevel(languageLevel); PersonLanguageResource expected = new PersonLanguageResource(); expected.setPersonId(personId); expected.setLanguageId(languageId); expected.setLanguageLevelId(languageLevelId); expected.setId(id); PersonLanguageResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PersonLanguage source = new PersonLanguage(); PersonLanguageResource expected = new PersonLanguageResource(); PersonLanguageResource actual = unit.convert(source); assertEquals(expected, actual); }