PersonLanguageResourceConverter extends AbstractConverter<PersonLanguageResource, PersonLanguage> { @Override public PersonLanguage convert(final PersonLanguageResource source, final PersonLanguage target) { if (source.getPersonId() != null) { Person person = new Person(); person.setId(source.getPersonId()); target.setPerson(person); } if (source.getLanguageId() != null) { Language language = new Language(); language.setId(source.getLanguageId()); target.setLanguage(language); } if (source.getLanguageLevelId() != null) { LanguageLevel languageLevel = new LanguageLevel(); languageLevel.setId(source.getLanguageLevelId()); target.setLanguageLevel(languageLevel); } return target; }  @Override PersonLanguage convert(final PersonLanguageResource source, final PersonLanguage target); @Override PersonLanguage convert(final PersonLanguageResource 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 expected = new PersonLanguage(); expected.setId(id); expected.setPerson(person); expected.setLanguage(language); expected.setLanguageLevel(languageLevel); PersonLanguageResource source = new PersonLanguageResource(); source.setPersonId(personId); source.setLanguageId(languageId); source.setLanguageLevelId(languageLevelId); source.setId(id); PersonLanguage actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PersonLanguage expected = new PersonLanguage(); PersonLanguageResource source = new PersonLanguageResource(); PersonLanguage actual = unit.convert(source); assertEquals(expected, actual); }