EnrolmentBenefitConverter extends AbstractConverter<EnrolmentBenefit, EnrolmentBenefitResource> { @Override public EnrolmentBenefitResource convert(final EnrolmentBenefit source, final EnrolmentBenefitResource target) { target.setId(source.getId()); if (source.getEnrolment() != null) { target.setEnrolmentId(source.getEnrolment().getId()); } if (source.getBenefit() != null) { target.setBenefitId(source.getBenefit().getId()); } if (source.getPersonPaper() != null) { target.setPersonPaperId(source.getPersonPaper().getId()); } return target; }  @Override EnrolmentBenefitResource convert(final EnrolmentBenefit source, final EnrolmentBenefitResource target); @Override EnrolmentBenefitResource convert(final EnrolmentBenefit source);  }
@Test public void testConvert() throws Exception { Long enrolmentId = 1L; Enrolment enrolment = new Enrolment(); enrolment.setId(enrolmentId); Long benefitId = 2L; Benefit benefit = new Benefit(); benefit.setId(benefitId); Long personpaperId = 3L; PersonPaper personpaper = new PersonPaper(); personpaper.setId(personpaperId); EnrolmentBenefit source = new EnrolmentBenefit(); source.setEnrolment(enrolment); source.setBenefit(benefit); source.setPersonPaper(personpaper); EnrolmentBenefitResource expected = new EnrolmentBenefitResource(); expected.setBenefitId(benefitId); expected.setEnrolmentId(enrolmentId); expected.setPersonPaperId(personpaperId); EnrolmentBenefitResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { EnrolmentBenefit source = new EnrolmentBenefit(); EnrolmentBenefitResource expected = new EnrolmentBenefitResource(); EnrolmentBenefitResource actual = unit.convert(source); assertEquals(expected, actual); }