SpecialtyConverter extends AbstractConverter<Specialty, SpecialtyResource> { @Override public SpecialtyResource convert(final Specialty source, final SpecialtyResource target) { target.setId(source.getId()); target.setAbbrName(source.getAbbrName()); target.setBegDate(source.getBegDate()); target.setCipher(source.getCipher()); target.setEndDate(source.getEndDate()); target.setName(source.getName()); if (source.getSpecialtyType() != null) { target.setSpecialtyTypeId(source.getSpecialtyType().getId()); } if (source.getParent() != null) { target.setParentId(source.getParent().getId()); } return target; }  @Override SpecialtyResource convert(final Specialty source, final SpecialtyResource target); @Override SpecialtyResource convert(final Specialty source);  }
@Test public void testConvert() throws Exception { String name = "name"; String abbrName = "abbr name"; Date begDate = new Date(); Date endDate = new Date(); String cipher = "cipher"; Specialty parent = new Specialty(); parent.setId(1L); SpecialtyType specialtyType = new SpecialtyType(); specialtyType.setId(2L); Specialty specialty = new Specialty(); specialty.setAbbrName(abbrName); specialty.setBegDate(begDate); specialty.setCipher(cipher); specialty.setEndDate(endDate); specialty.setName(name); specialty.setParent(parent); specialty.setSpecialtyType(specialtyType); SpecialtyResource expected = new SpecialtyResource(); expected.setAbbrName(abbrName); expected.setBegDate(begDate); expected.setCipher(cipher); expected.setEndDate(endDate); expected.setName(name); expected.setSpecialtyTypeId(specialtyType.getId()); expected.setParentId(parent.getId()); SpecialtyResource actual = unit.convert(specialty); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String name = "name"; String abbrName = "abbr name"; Date begDate = new Date(); Date endDate = new Date(); String cipher = "cipher"; Specialty specialty = new Specialty(); specialty.setAbbrName(abbrName); specialty.setBegDate(begDate); specialty.setCipher(cipher); specialty.setEndDate(endDate); specialty.setName(name); SpecialtyResource expected = new SpecialtyResource(); expected.setAbbrName(abbrName); expected.setBegDate(begDate); expected.setCipher(cipher); expected.setEndDate(endDate); expected.setName(name); SpecialtyResource actual = unit.convert(specialty); assertEquals(expected, actual); }