PersonNameConverter extends AbstractConverter<PersonName, PersonNameResource> { @Override public PersonNameResource convert(final PersonName source, final PersonNameResource target) { if (source.getLanguage() != null) { target.setLanguageId(source.getLanguage().getId()); } if (source.getPerson() != null) { target.setPersonId(source.getPerson().getId()); } target.setName(source.getName()); target.setFirstName(source.getFirstName()); target.setFatherName(source.getFatherName()); target.setSurname(source.getSurname()); target.setId(source.getId()); return target; }  @Override PersonNameResource convert(final PersonName source, final PersonNameResource target); @Override PersonNameResource convert(final PersonName 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 expected = new PersonNameResource(); expected.setFatherName(fatherName); expected.setFirstName(firstName); expected.setLanguageId(languageId); expected.setName(name); expected.setPersonId(personId); expected.setSurname(surname); PersonName source = new PersonName(); source.setLanguage(language); source.setPerson(person); source.setFirstName(firstName); source.setFatherName(fatherName); source.setSurname(surname); source.setName(name); PersonNameResource 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 expected = new PersonNameResource(); expected.setFatherName(fatherName); expected.setFirstName(firstName); expected.setName(name); expected.setSurname(surname); PersonName source = new PersonName(); source.setFirstName(firstName); source.setFatherName(fatherName); source.setSurname(surname); source.setName(name); PersonNameResource actual = unit.convert(source); assertEquals(expected, actual); }