PersonFamilyResourceConverter extends AbstractConverter<PersonFamilyResource, PersonFamily> { @Override public PersonFamily convert(final PersonFamilyResource source, final PersonFamily target) { if (source.getPersonId() != null) { Person person = new Person(); person.setId(source.getPersonId()); target.setPerson(person); } if (source.getFamilyTypeId() != null) { FamilyType familyType = new FamilyType(); familyType.setId(source.getFamilyTypeId()); target.setFamilyType(familyType); } target.setName(source.getName()); target.setBirthDate(source.getBirthDate()); return target; }  @Override PersonFamily convert(final PersonFamilyResource source, final PersonFamily target); @Override PersonFamily convert(final PersonFamilyResource source);  }
@Test public void testConvert() throws Exception { Long personId = 2L; Person person = new Person(); person.setId(personId); Long familyTypeId = 3L; FamilyType familyType = new FamilyType(); familyType.setId(familyTypeId); Long id = 1L; String name = "name"; Date birthdate = new Date(); PersonFamily expected = new PersonFamily(); expected.setPerson(person); expected.setFamilyType(familyType); expected.setId(id); expected.setName(name); expected.setBirthDate(birthdate); PersonFamilyResource source = new PersonFamilyResource(); source.setPersonId(personId); source.setFamilyTypeId(familyTypeId); source.setId(id); source.setName(name); source.setBirthDate(birthdate); PersonFamily actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PersonFamily expected = new PersonFamily(); PersonFamilyResource source = new PersonFamilyResource(); PersonFamily actual = unit.convert(source); assertEquals(expected, actual); }