PartnerConverter extends AbstractConverter<Partner, PartnerResource> { @Override public PartnerResource convert(final Partner source, final PartnerResource target) { target.setAbbrName(source.getAbbrName()); target.setBegDate(source.getBegDate()); target.setEmail(source.getEmail()); target.setEndDate(source.getEndDate()); target.setId(source.getId()); target.setManager(source.getManager()); target.setName(source.getName()); target.setPhone(source.getPhone()); target.setId(source.getId()); if (source.getParent() != null) { target.setParentId(source.getParent().getId()); } return target; }  @Override PartnerResource convert(final Partner source, final PartnerResource target); @Override PartnerResource convert(final Partner source);  }
@Test public void testConvert() throws Exception { String abbrName = "abbr name"; Date begDate = new Date(); String email = "Email"; Date endDate = new Date(); Long id = 1L; String manager = "manager"; String name = "name"; Long parentId = 2L; String phone = "phone"; Partner parent = new Partner(); parent.setId(parentId); Partner source = new Partner(); source.setAbbrName(abbrName); source.setBegDate(begDate); source.setEmail(email); source.setEndDate(endDate); source.setId(id); source.setManager(manager); source.setName(name); source.setParent(parent); source.setPhone(phone); PartnerResource expected = new PartnerResource(); expected.setAbbrName(abbrName); expected.setBegDate(begDate); expected.setEmail(email); expected.setEndDate(endDate); expected.setId(id); expected.setManager(manager); expected.setName(name); expected.setParentId(parentId); expected.setPhone(phone); PartnerResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String abbrName = "abbr name"; Date begDate = new Date(); String email = "Email"; Date endDate = new Date(); Long id = 1L; String manager = "manager"; String name = "name"; String phone = "phone"; Partner source = new Partner(); source.setAbbrName(abbrName); source.setBegDate(begDate); source.setEmail(email); source.setEndDate(endDate); source.setId(id); source.setManager(manager); source.setName(name); source.setPhone(phone); PartnerResource expected = new PartnerResource(); expected.setAbbrName(abbrName); expected.setBegDate(begDate); expected.setEmail(email); expected.setEndDate(endDate); expected.setId(id); expected.setManager(manager); expected.setName(name); expected.setPhone(phone); PartnerResource actual = unit.convert(source); assertEquals(expected, actual); }