PublicActivityAwardConverter extends AbstractConverter<PublicActivityAward, PublicActivityAwardResource> { @Override public PublicActivityAwardResource convert(final PublicActivityAward source, final PublicActivityAwardResource target) { target.setId(source.getId()); target.setAwardName(source.getAwardName()); target.setBonus(source.getBonus()); target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); if (source.getPublicActivity() != null) { target.setPublicActivityId(source.getPublicActivity().getId()); } if (source.getEnrolmentSubject() != null) { target.setEnrolmentSubjectId(source.getEnrolmentSubject().getId()); } return target; }  @Override PublicActivityAwardResource convert(final PublicActivityAward source, final PublicActivityAwardResource target); @Override PublicActivityAwardResource convert(final PublicActivityAward source);  }
@Test public void testConvert() throws Exception { Long id = 1L; Long publicActivityId = 2L; PublicActivity publicActivity = new PublicActivity(); publicActivity.setId(publicActivityId); Long enrolmentSubjectId = 3L; EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(enrolmentSubjectId); String awardname = "award name"; Double bonus = 2.1; Date begDate = new Date(); Date endDate = new Date(); PublicActivityAward source = new PublicActivityAward(); source.setId(id); source.setPublicActivity(publicActivity); source.setEnrolmentSubject(enrolmentSubject); source.setAwardName(awardname); source.setBonus(bonus); source.setBegDate(begDate); source.setEndDate(endDate); PublicActivityAwardResource expected = new PublicActivityAwardResource(); expected.setId(id); expected.setPublicActivityId(publicActivityId); expected.setEnrolmentSubjectId(enrolmentSubjectId); expected.setAwardName(awardname); expected.setBonus(bonus); expected.setBegDate(begDate); expected.setEndDate(endDate); PublicActivityAwardResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFiedls() throws Exception { PublicActivityAward source = new PublicActivityAward(); PublicActivityAwardResource expected = new PublicActivityAwardResource(); PublicActivityAwardResource actual = unit.convert(source); assertEquals(expected, actual); }