EnrolmentTypeConverter extends AbstractConverter<EnrolmentType, EnrolmentTypeResource> { @Override public EnrolmentTypeResource convert(final EnrolmentType source, final EnrolmentTypeResource target) { target.setId(source.getId()); if (source.getParent() != null) { target.setParentId(source.getParent().getId()); } target.setName(source.getName()); target.setAbbrName(source.getAbbrName()); return target; }  @Override EnrolmentTypeResource convert(final EnrolmentType source, final EnrolmentTypeResource target); @Override EnrolmentTypeResource convert(final EnrolmentType source);  }
@Test public void testConvert() throws Exception { String name = "1234"; String abbrName = "abbrName"; EnrolmentType source = new EnrolmentType(); source.setName(name); source.setAbbrName(abbrName); EnrolmentTypeResource expected = new EnrolmentTypeResource(); expected.setName(name); expected.setAbbrName(abbrName); EnrolmentTypeResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithRelation() throws Exception { String name = "1234"; String abbrName = "abbrName"; Long parentId = 1L; EnrolmentType parent = new EnrolmentType(); parent.setId(parentId); EnrolmentType source = new EnrolmentType(); source.setName(name); source.setAbbrName(abbrName); source.setParent(parent);; EnrolmentTypeResource expected = new EnrolmentTypeResource(); expected.setName(name); expected.setAbbrName(abbrName); expected.setParentId(parentId); EnrolmentTypeResource actual = unit.convert(source); assertEquals(expected, actual); }