PersonNameResourceConverter extends AbstractConverter<PersonNameResource, PersonName> { @Override public PersonName convert(final PersonNameResource source, final PersonName 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); } target.setName(source.getName()); target.setFirstName(source.getFirstName()); target.setFatherName(source.getFatherName()); target.setSurname(source.getSurname()); return target; }  @Override PersonName convert(final PersonNameResource source, final PersonName target); @Override PersonName convert(final PersonNameResource source);  }
@Test public void testConvert() throws Exception { Long languageId = 1L; Language language = new Language(); language.setId(languageId); Long personId = 2L; Person person = new Person(); person.setId(personId); String name = "name"; String firstName = "first name"; String fatherName = "father name"; String surname = "surname"; PersonNameResource source = new PersonNameResource(); source.setFatherName(fatherName); source.setFirstName(firstName); source.setLanguageId(languageId); source.setName(name); source.setPersonId(personId); source.setSurname(surname); PersonName expected = new PersonName(); expected.setLanguage(language); expected.setPerson(person); expected.setFirstName(firstName); expected.setFatherName(fatherName); expected.setSurname(surname); expected.setName(name); PersonName actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String name = "name"; String firstName = "first name"; String fatherName = "father name"; String surname = "surname"; PersonNameResource source = new PersonNameResource(); source.setFatherName(fatherName); source.setFirstName(firstName); source.setName(name); source.setSurname(surname); PersonName expected = new PersonName(); expected.setFirstName(firstName); expected.setFatherName(fatherName); expected.setSurname(surname); expected.setName(name); PersonName actual = unit.convert(source); assertEquals(expected, actual); }