EnrolmentTypeResourceConverter extends AbstractConverter<EnrolmentTypeResource, EnrolmentType> { @Override public EnrolmentType convert(final EnrolmentTypeResource source, final EnrolmentType target) { target.setName(source.getName()); target.setAbbrName(source.getAbbrName()); if (source.getParentId() != null) { EnrolmentType parent = new EnrolmentType(); parent.setId(source.getParentId()); target.setParent(parent); } return target; }  @Override EnrolmentType convert(final EnrolmentTypeResource source, final EnrolmentType target); @Override EnrolmentType convert(final EnrolmentTypeResource source);  }
@Test public void testConvert() throws Exception { String name = "1234"; String abbrName = "abbrName"; EnrolmentTypeResource source = new EnrolmentTypeResource(); source.setName(name); source.setAbbrName(abbrName); EnrolmentType expected = new EnrolmentType(); expected.setName(name); expected.setAbbrName(abbrName); EnrolmentType 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); EnrolmentTypeResource source = new EnrolmentTypeResource(); source.setName(name); source.setAbbrName(abbrName); source.setParentId(parentId); EnrolmentType expected = new EnrolmentType(); expected.setName(name); expected.setAbbrName(abbrName); expected.setParent(parent); EnrolmentType actual = unit.convert(source); assertEquals(expected, actual); }