BenefitConverter extends AbstractConverter<Benefit, BenefitResource> { @Override public BenefitResource convert(final Benefit source, final BenefitResource target) { target.setId(source.getId()); target.setAbbrName(source.getAbbrName()); target.setName(source.getName()); target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); target.setDescription(source.getDescription()); if (source.getParent() != null) { target.setParentId(source.getParent().getId()); } if (source.getBenefitType() != null) { target.setBenefitTypeId(source.getBenefitType().getId()); } return target; }  @Override BenefitResource convert(final Benefit source, final BenefitResource target); @Override BenefitResource convert(final Benefit source);  }
@Test public void testConvert() throws Exception { Long parentId = 1L; Long benefitTypeId = 2L; String abbrName = "fdsf"; Date begDate = new Date(); Date endDate = new Date(); String description = "descriptipp"; Benefit source = new Benefit(); source.setAbbrName(abbrName); BenefitType benefitType = new BenefitType(); benefitType.setId(benefitTypeId); source.setBenefitType(benefitType); source.setBegDate(begDate); source.setDescription(description); source.setEndDate(endDate); source.setName(source.getName()); Benefit parent = new Benefit(); parent.setId(parentId); source.setParent(parent); BenefitResource expected = new BenefitResource(); expected.setAbbrName(abbrName); expected.setBenefitTypeId(benefitTypeId); expected.setBegDate(begDate); expected.setDescription(description); expected.setEndDate(endDate); expected.setName(source.getName()); expected.setParentId(parentId); BenefitResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String abbrName = "fdsf"; Date begDate = new Date(); Date endDate = new Date(); String description = "descriptipp"; Benefit source = new Benefit(); source.setAbbrName(abbrName); source.setBegDate(begDate); source.setDescription(description); source.setEndDate(endDate); source.setName(source.getName()); BenefitResource expected = new BenefitResource(); expected.setAbbrName(abbrName); expected.setBegDate(begDate); expected.setDescription(description); expected.setEndDate(endDate); expected.setName(source.getName()); BenefitResource actual = unit.convert(source); assertEquals(expected, actual); }