PersonPensionConverter extends AbstractConverter<PersonPension, PersonPensionResource> { @Override public PersonPensionResource convert(final PersonPension source, final PersonPensionResource target) { if (source.getPensionType() != null) { target.setPensionTypeId(source.getPensionType().getId()); } if (source.getPerson() != null) { target.setPersonId(source.getPerson().getId()); } target.setId(source.getId()); target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); return target; }  @Override PersonPensionResource convert(final PersonPension source, final PersonPensionResource target); @Override PersonPensionResource convert(final PersonPension source);  }
@Test public void testConvert() throws Exception { Long id = 1L; Long personId = 2L; Person person = new Person(); person.setId(personId); Long contactTypeId = 3L; PensionType contactType = new PensionType(); contactType.setId(contactTypeId); Date begDate = new Date(); Date endDate = new Date(); PersonPension source = new PersonPension(); source.setPerson(person); source.setPensionType(contactType); source.setId(id); source.setBegDate(begDate); source.setEndDate(endDate); PersonPensionResource expected = new PersonPensionResource(); expected.setPersonId(personId); expected.setPensionTypeId(contactTypeId); expected.setId(id); expected.setBegDate(begDate); expected.setEndDate(endDate); PersonPensionResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PersonPension source = new PersonPension(); PersonPensionResource expected = new PersonPensionResource(); PersonPensionResource actual = unit.convert(source); assertEquals(expected, actual); }