PersonFamilyConverter extends AbstractConverter<PersonFamily, PersonFamilyResource> { @Override public PersonFamilyResource convert(final PersonFamily source, final PersonFamilyResource target) { if (source.getPerson() != null) { target.setPersonId(source.getPerson().getId()); } if (source.getFamilyType() != null) { target.setFamilyTypeId(source.getFamilyType().getId()); } target.setId(source.getId()); target.setName(source.getName()); target.setBirthDate(source.getBirthDate()); return target; }  @Override PersonFamilyResource convert(final PersonFamily source, final PersonFamilyResource target); @Override PersonFamilyResource convert(final PersonFamily 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 source = new PersonFamily(); source.setPerson(person); source.setFamilyType(familyType); source.setId(id); source.setName(name); source.setBirthDate(birthdate); PersonFamilyResource expected = new PersonFamilyResource(); expected.setPersonId(personId); expected.setFamilyTypeId(familyTypeId); expected.setId(id); expected.setName(name); expected.setBirthDate(birthdate); PersonFamilyResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PersonFamily source = new PersonFamily(); PersonFamilyResource expected = new PersonFamilyResource(); PersonFamilyResource actual = unit.convert(source); assertEquals(expected, actual); }