SpecialtyResourceConverter extends AbstractConverter<SpecialtyResource, Specialty> { @Override public Specialty convert(final SpecialtyResource source, final Specialty target) { if (source.getParentId() != null) { Specialty parent = new Specialty(); parent.setId(source.getParentId()); target.setParent(parent); } if (source.getSpecialtyTypeId() != null) { SpecialtyType specialtyType = new SpecialtyType(); specialtyType.setId(source.getSpecialtyTypeId()); target.setSpecialtyType(specialtyType); } target.setAbbrName(source.getAbbrName()); target.setBegDate(source.getBegDate()); target.setCipher(source.getCipher()); target.setEndDate(source.getEndDate()); target.setName(source.getName()); return target; }  @Override Specialty convert(final SpecialtyResource source, final Specialty target); @Override Specialty convert(final SpecialtyResource 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 expected = new Specialty(); expected.setAbbrName(abbrName); expected.setBegDate(begDate); expected.setCipher(cipher); expected.setEndDate(endDate); expected.setName(name); expected.setParent(parent); expected.setSpecialtyType(specialtyType); SpecialtyResource specialtyResource = new SpecialtyResource(); specialtyResource.setAbbrName(abbrName); specialtyResource.setBegDate(begDate); specialtyResource.setCipher(cipher); specialtyResource.setEndDate(endDate); specialtyResource.setName(name); specialtyResource.setSpecialtyTypeId(specialtyType.getId()); specialtyResource.setParentId(parent.getId()); Specialty actual = unit.convert(specialtyResource); 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 expected = new Specialty(); expected.setAbbrName(abbrName); expected.setBegDate(begDate); expected.setCipher(cipher); expected.setEndDate(endDate); expected.setName(name); SpecialtyResource specialtyResource = new SpecialtyResource(); specialtyResource.setAbbrName(abbrName); specialtyResource.setBegDate(begDate); specialtyResource.setCipher(cipher); specialtyResource.setEndDate(endDate); specialtyResource.setName(name); Specialty actual = unit.convert(specialtyResource); assertEquals(expected, actual); }