PersonEducationResourceConverter extends AbstractConverter<PersonEducationResource, PersonEducation> { @Override public PersonEducation convert(final PersonEducationResource source, final PersonEducation target) { if (source.getPersonId() != null) { Person person = new Person(); person.setId(source.getPersonId()); target.setPerson(person); } if (source.getEducationTypeId() != null) { EducationType educationType = new EducationType(); educationType.setId(source.getEducationTypeId()); target.setEducationType(educationType); } if (source.getPersonPaperId() != null) { PersonPaper personPaper = new PersonPaper(); personPaper.setId(source.getPersonPaperId()); target.setPersonPaper(personPaper); } target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); return target; }  @Override PersonEducation convert(final PersonEducationResource source, final PersonEducation target); @Override PersonEducation convert(final PersonEducationResource 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 expected = new PersonEducation(); expected.setPerson(person); expected.setEducationType(educationType); expected.setPersonPaper(personPaper); expected.setId(id); expected.setBegDate(begDate); expected.setEndDate(endDate); PersonEducationResource source = new PersonEducationResource(); source.setPersonId(personId); source.setEducationTypeId(educationTypeId); source.setPersonPaperId(personPaperId); source.setId(id); source.setBegDate(begDate); source.setEndDate(endDate); PersonEducation actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PersonEducation expected = new PersonEducation(); PersonEducationResource source = new PersonEducationResource(); PersonEducation actual = unit.convert(source); assertEquals(expected, actual); }