PersonWorkConverter extends AbstractConverter<PersonWork, PersonWorkResource> { @Override public PersonWorkResource convert(final PersonWork source, final PersonWorkResource target) { if (source.getPerson() != null) { target.setPersonId(source.getPerson().getId()); } if (source.getJobType() != null) { target.setJobTypeId(source.getJobType().getId()); } if (source.getSpecStageType() != null) { target.setSpecStageTypeId(source.getSpecStageType().getId()); } target.setId(source.getId()); target.setOrganizationName(source.getOrganizationName()); target.setPostName(source.getPostName()); target.setDescription(source.getDescription()); target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); return target; }  @Override PersonWorkResource convert(final PersonWork source, final PersonWorkResource target); @Override PersonWorkResource convert(final PersonWork 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 source = new PersonWork(); source.setId(id); source.setPerson(person); source.setJobType(jobType); source.setSpecStageType(specStageType); source.setOrganizationName(organizationName); source.setPostName(postName); source.setDescription(description); source.setBegDate(begDate); source.setEndDate(endDate); PersonWorkResource expected = new PersonWorkResource(); expected.setId(id); expected.setPersonId(personId); expected.setJobTypeId(jobTypeId); expected.setSpecStageTypeId(specStageTypeId); expected.setOrganizationName(organizationName); expected.setPostName(postName); expected.setDescription(description); expected.setBegDate(begDate); expected.setEndDate(endDate); PersonWorkResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PersonWork source = new PersonWork(); PersonWorkResource expected = new PersonWorkResource(); PersonWorkResource actual = unit.convert(source); assertEquals(expected, actual); }