BenefitResourceConverter extends AbstractConverter<BenefitResource, Benefit> { @Override public Benefit convert(final BenefitResource source, final Benefit 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.getParentId() != null) { Benefit parent = new Benefit(); parent.setId(source.getParentId()); target.setParent(parent); } if (source.getBenefitTypeId() != null) { BenefitType benefitType = new BenefitType(); benefitType.setId(source.getBenefitTypeId()); target.setBenefitType(benefitType); } return target; }  @Override Benefit convert(final BenefitResource source, final Benefit target); @Override Benefit convert(final BenefitResource 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"; String name = "name"; BenefitType benefitType = new BenefitType(); benefitType.setId(benefitTypeId); Benefit parent = new Benefit(); parent.setId(parentId); Benefit expected = new Benefit(); expected.setAbbrName(abbrName); expected.setBenefitType(benefitType); expected.setBegDate(begDate); expected.setDescription(description); expected.setEndDate(endDate); expected.setName(name); expected.setParent(parent); BenefitResource source = new BenefitResource(); source.setAbbrName(abbrName); source.setBenefitTypeId(benefitTypeId); source.setBegDate(begDate); source.setDescription(description); source.setEndDate(endDate); source.setName(name); source.setParentId(parentId); Benefit 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"; String name = "name"; Benefit expected = new Benefit(); expected.setAbbrName(abbrName); expected.setBegDate(begDate); expected.setDescription(description); expected.setEndDate(endDate); expected.setName(name); BenefitResource source = new BenefitResource(); source.setAbbrName(abbrName); source.setBegDate(begDate); source.setDescription(description); source.setEndDate(endDate); source.setName(name); Benefit actual = unit.convert(source); assertEquals(expected, actual); }