PublicActivityAwardResourceConverter extends AbstractConverter<PublicActivityAwardResource, PublicActivityAward> { @Override public PublicActivityAward convert(final PublicActivityAwardResource source, final PublicActivityAward target) { target.setAwardName(source.getAwardName()); target.setBonus(source.getBonus()); target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); if (source.getPublicActivityId() != null) { PublicActivity publicActivity = new PublicActivity(); publicActivity.setId(source.getPublicActivityId()); target.setPublicActivity(publicActivity); } if (source.getEnrolmentSubjectId() != null) { EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(source.getEnrolmentSubjectId()); target.setEnrolmentSubject(enrolmentSubject); } return target; }  @Override PublicActivityAward convert(final PublicActivityAwardResource source, final PublicActivityAward target); @Override PublicActivityAward convert(final PublicActivityAwardResource 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 expected = new PublicActivityAward(); expected.setId(id); expected.setPublicActivity(publicActivity); expected.setEnrolmentSubject(enrolmentSubject); expected.setAwardName(awardname); expected.setBonus(bonus); expected.setBegDate(begDate); expected.setEndDate(endDate); PublicActivityAwardResource source = new PublicActivityAwardResource(); source.setId(id); source.setPublicActivityId(publicActivityId); source.setEnrolmentSubjectId(enrolmentSubjectId); source.setAwardName(awardname); source.setBonus(bonus); source.setBegDate(begDate); source.setEndDate(endDate); PublicActivityAward actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFiedls() throws Exception { PublicActivityAward expected = new PublicActivityAward(); PublicActivityAwardResource source = new PublicActivityAwardResource(); PublicActivityAward actual = unit.convert(source); assertEquals(expected, actual); }