SpecOfferBenefitConverter extends AbstractConverter<SpecOfferBenefit, SpecOfferBenefitResource> { @Override public SpecOfferBenefitResource convert(final SpecOfferBenefit source, final SpecOfferBenefitResource target) { if (source.getBenefit() != null) { target.setBenefitId(source.getBenefit().getId()); } if (source.getSpecOffer() != null) { target.setSpecOfferId(source.getSpecOffer().getId()); } target.setId(source.getId()); return target; }  @Override SpecOfferBenefitResource convert(final SpecOfferBenefit source, final SpecOfferBenefitResource target); @Override SpecOfferBenefitResource convert(final SpecOfferBenefit source);  }
@Test public void testConvert() throws Exception { Long specOfferId = 2L; Long benefitId = 1L; SpecOfferBenefitResource expected = new SpecOfferBenefitResource(); expected.setBenefitId(benefitId); expected.setSpecOfferId(specOfferId); Benefit benefit = new Benefit(); benefit.setId(benefitId); SpecOffer specOffer = new SpecOffer(); specOffer.setId(specOfferId); SpecOfferBenefit source = new SpecOfferBenefit(); source.setBenefit(benefit); source.setSpecOffer(specOffer); SpecOfferBenefitResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { SpecOfferBenefitResource expected = new SpecOfferBenefitResource(); SpecOfferBenefit source = new SpecOfferBenefit(); SpecOfferBenefitResource actual = unit.convert(source); assertEquals(expected, actual); }