EnrolmentEnrolmentSubjectResourceConverter extends	AbstractConverter<EnrolmentEnrolmentSubjectResource, EnrolmentEnrolmentSubject> { @Override public EnrolmentEnrolmentSubject convert(final EnrolmentEnrolmentSubjectResource source, final EnrolmentEnrolmentSubject target) { target.setId(source.getId()); target.setMark(source.getMark()); if (source.getEnrolmentId() != null) { Enrolment enrolment = new Enrolment(); enrolment.setId(source.getEnrolmentId()); target.setEnrolment(enrolment); } if (source.getEnrolmentSubjectId() != null) { EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(source.getEnrolmentSubjectId()); target.setEnrolmentSubject(enrolmentSubject); } if (source.getPersonEnrolmentSubjectId() != null) { PersonEnrolmentSubject personEnrolmentSubject = new PersonEnrolmentSubject(); personEnrolmentSubject.setId(source.getPersonEnrolmentSubjectId()); target.setPersonEnrolmentSubject(personEnrolmentSubject); } return target; }  @Override EnrolmentEnrolmentSubject convert(final EnrolmentEnrolmentSubjectResource source, final EnrolmentEnrolmentSubject target); @Override EnrolmentEnrolmentSubject convert(final EnrolmentEnrolmentSubjectResource source);  }
@Test public void testConvert() throws Exception { Long enrolmentId = 1L; Enrolment enrolment= new Enrolment(); enrolment.setId(enrolmentId); Long enrolmentSubjectId = 2L; EnrolmentSubject enrolmentSubject=new EnrolmentSubject(); enrolmentSubject.setId(enrolmentSubjectId); Long personEnrolmentSubjectId = 3L; PersonEnrolmentSubject personEnrolmentSubject = new PersonEnrolmentSubject(); personEnrolmentSubject.setId(personEnrolmentSubjectId); Double mark = 1.2; EnrolmentEnrolmentSubjectResource source = new EnrolmentEnrolmentSubjectResource(); source.setEnrolmentId(enrolmentId); source.setEnrolmentSubjectId(enrolmentSubjectId); source.setPersonEnrolmentSubjectId(personEnrolmentSubjectId); source.setMark(mark); EnrolmentEnrolmentSubject expected = new EnrolmentEnrolmentSubject(); expected.setEnrolment(enrolment); expected.setEnrolmentSubject(enrolmentSubject); expected.setPersonEnrolmentSubject(personEnrolmentSubject); expected.setMark(mark); EnrolmentEnrolmentSubject actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { Double mark = 1.2; EnrolmentEnrolmentSubject expected = new EnrolmentEnrolmentSubject(); expected.setMark(mark); EnrolmentEnrolmentSubjectResource source = new EnrolmentEnrolmentSubjectResource(); source.setMark(mark); EnrolmentEnrolmentSubject actual = unit.convert(source); assertEquals(expected, actual); }