PersonContactResourceConverter extends AbstractConverter<PersonContactResource, PersonContact> { @Override public PersonContact convert(final PersonContactResource source, final PersonContact target) { if (source.getPersonId() != null) { Person person = new Person(); person.setId(source.getPersonId()); target.setPerson(person); } if (source.getContactTypeId() != null) { ContactType contactType = new ContactType(); contactType.setId(source.getContactTypeId()); target.setContactType(contactType); } target.setValue(source.getValue()); return target; }  @Override PersonContact convert(final PersonContactResource source, final PersonContact target); @Override PersonContact convert(final PersonContactResource source);  }
@Test public void testConvert() throws Exception { Long id = 1L; String value = "sfas"; Long personId = 2L; Person person = new Person(); person.setId(personId); Long contactTypeId = 3L; ContactType contactType = new ContactType(); contactType.setId(contactTypeId); PersonContact expected = new PersonContact(); expected.setPerson(person); expected.setContactType(contactType); expected.setValue(value); PersonContactResource source = new PersonContactResource(); source.setPersonId(personId); source.setContactTypeId(contactTypeId); source.setId(id); source.setValue(value); PersonContact actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PersonContact expected = new PersonContact(); PersonContactResource source = new PersonContactResource(); PersonContact actual = unit.convert(source); assertEquals(expected, actual); }