PersonPensionResourceConverter extends AbstractConverter<PersonPensionResource, PersonPension> { @Override public PersonPension convert(final PersonPensionResource source, final PersonPension target) { if (source.getPersonId() != null) { Person person = new Person(); person.setId(source.getPersonId()); target.setPerson(person); } if (source.getPensionTypeId() != null) { PensionType paperType = new PensionType(); paperType.setId(source.getPensionTypeId()); target.setPensionType(paperType); } target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); return target; }  @Override PersonPension convert(final PersonPensionResource source, final PersonPension target); @Override PersonPension convert(final PersonPensionResource 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 expected = new PersonPension(); expected.setPerson(person); expected.setPensionType(contactType); expected.setBegDate(begDate); expected.setEndDate(endDate); PersonPensionResource source = new PersonPensionResource(); source.setPersonId(personId); source.setPensionTypeId(contactTypeId); source.setBegDate(begDate); source.setEndDate(endDate); source.setId(id); PersonPension actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PersonPension expected = new PersonPension(); PersonPensionResource source = new PersonPensionResource(); PersonPension actual = unit.convert(source); assertEquals(expected, actual); }