PersonEnrolmentSubjectResourceConverter extends AbstractConverter<PersonEnrolmentSubjectResource, PersonEnrolmentSubject> { @Override public PersonEnrolmentSubject convert(final PersonEnrolmentSubjectResource source, final PersonEnrolmentSubject target) { target.setMark(source.getMark()); if (source.getPersonId() != null) { Person person = new Person(); person.setId(source.getPersonId()); target.setPerson(person); } if (source.getPersonPaperId() != null) { PersonPaper personPaper = new PersonPaper(); personPaper.setId(source.getPersonPaperId()); target.setPersonPaper(personPaper); } if (source.getEnrolmentSubjectId() != null) { EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(source.getEnrolmentSubjectId()); target.setEnrolmentSubject(enrolmentSubject); } return target; }  @Override PersonEnrolmentSubject convert(final PersonEnrolmentSubjectResource source, final PersonEnrolmentSubject target); @Override PersonEnrolmentSubject convert(final PersonEnrolmentSubjectResource source);  }
@Test public void testConvert() throws Exception { Double mark = 5.0; Long personId = 2L; Person person = new Person(); person.setId(personId); Long personPaperId = 3L; PersonPaper personPaper = new PersonPaper(); personPaper.setId(personPaperId); Long enrolmentSubjectId = 4L; EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(enrolmentSubjectId); PersonEnrolmentSubjectResource source = new PersonEnrolmentSubjectResource(); source.setPersonId(personId); source.setPersonPaperId(personPaperId); source.setEnrolmentSubjectId(enrolmentSubjectId); source.setMark(mark); PersonEnrolmentSubject expected = new PersonEnrolmentSubject(); expected.setMark(mark); expected.setPerson(person); expected.setPersonPaper(personPaper); expected.setEnrolmentSubject(enrolmentSubject); PersonEnrolmentSubject actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { Double mark = 5.0; PersonEnrolmentSubjectResource source = new PersonEnrolmentSubjectResource(); source.setMark(mark); PersonEnrolmentSubject expected = new PersonEnrolmentSubject(); expected.setMark(mark); PersonEnrolmentSubject actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PersonEnrolmentSubjectResource source = new PersonEnrolmentSubjectResource(); PersonEnrolmentSubject expected = new PersonEnrolmentSubject(); PersonEnrolmentSubject actual = unit.convert(source); assertEquals(expected, actual); }