PersonWorkResourceConverter extends AbstractConverter<PersonWorkResource, PersonWork> { @Override public PersonWork convert(final PersonWorkResource source, final PersonWork target) { if (source.getPersonId() != null) { Person person = new Person(); person.setId(source.getPersonId()); target.setPerson(person); } if (source.getJobTypeId() != null) { JobType jobType = new JobType(); jobType.setId(source.getJobTypeId()); target.setJobType(jobType); } if (source.getSpecStageTypeId() != null) { SpecStageType specStageType = new SpecStageType(); specStageType.setId(source.getSpecStageTypeId()); target.setSpecStageType(specStageType); } target.setOrganizationName(source.getOrganizationName()); target.setPostName(source.getPostName()); target.setDescription(source.getDescription()); target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); return target; }  @Override PersonWork convert(final PersonWorkResource source, final PersonWork target); @Override PersonWork convert(final PersonWorkResource source);  }
@Test public void testConvert() throws Exception { Long personId = 1L; Person person = new Person(); person.setId(personId); Long jobTypeId = 2L; JobType jobType = new JobType(); jobType.setId(jobTypeId); Long specStageTypeId = 3L; SpecStageType specStageType = new SpecStageType(); specStageType.setId(specStageTypeId); String organizationName = "Optigra"; String postName = "java developer"; String description = "Super big description"; Date begDate = new Date(); Date endDate = new Date(); Long id = 6L; PersonWork expected = new PersonWork(); expected.setId(id); expected.setPerson(person); expected.setJobType(jobType); expected.setSpecStageType(specStageType); expected.setOrganizationName(organizationName); expected.setPostName(postName); expected.setDescription(description); expected.setBegDate(begDate); expected.setEndDate(endDate); PersonWorkResource source = new PersonWorkResource(); source.setId(id); source.setPersonId(personId); source.setJobTypeId(jobTypeId); source.setSpecStageTypeId(specStageTypeId); source.setOrganizationName(organizationName); source.setPostName(postName); source.setDescription(description); source.setBegDate(begDate); source.setEndDate(endDate); PersonWork actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PersonWork expected = new PersonWork(); PersonWorkResource source = new PersonWorkResource(); PersonWork actual = unit.convert(source); assertEquals(expected, actual); }