PersonEducationConverter extends AbstractConverter<PersonEducation, PersonEducationResource> { @Override public PersonEducationResource convert(final PersonEducation source, final PersonEducationResource target) { if (source.getPerson() != null) { target.setPersonId(source.getPerson().getId()); } if (source.getEducationType() != null) { target.setEducationTypeId(source.getEducationType().getId()); } if (source.getPersonPaper() != null) { target.setPersonPaperId(source.getPersonPaper().getId()); } target.setId(source.getId()); target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); return target; }  @Override PersonEducationResource convert(final PersonEducation source, final PersonEducationResource target); @Override PersonEducationResource convert(final PersonEducation source);  }
@Test public void testConvert() throws Exception { Long personId = 2L; Person person = new Person(); person.setId(personId); Long educationTypeId = 3L; EducationType educationType = new EducationType(); educationType.setId(educationTypeId); Long personPaperId = 4L; PersonPaper personPaper = new PersonPaper(); personPaper.setId(personPaperId); Long id = 1L; Date begDate = new Date(); Date endDate = new Date(); PersonEducation source = new PersonEducation(); source.setPerson(person); source.setEducationType(educationType); source.setPersonPaper(personPaper); source.setId(id); source.setBegDate(begDate); source.setEndDate(endDate); PersonEducationResource expected = new PersonEducationResource(); expected.setPersonId(personId); expected.setEducationTypeId(educationTypeId); expected.setPersonPaperId(personPaperId); expected.setId(id); expected.setBegDate(begDate); expected.setEndDate(endDate); PersonEducationResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PersonEducation source = new PersonEducation(); PersonEducationResource expected = new PersonEducationResource(); PersonEducationResource actual = unit.convert(source); assertEquals(expected, actual); }