PersonEnrolmentSubjectConverter extends AbstractConverter<PersonEnrolmentSubject, PersonEnrolmentSubjectResource> { @Override public PersonEnrolmentSubjectResource convert(final PersonEnrolmentSubject source, final PersonEnrolmentSubjectResource target) { target.setMark(source.getMark()); target.setId(source.getId()); if (source.getPerson() != null) { target.setPersonId(source.getPerson().getId()); } if (source.getPersonPaper() != null) { target.setPersonPaperId(source.getPersonPaper().getId()); } if (source.getEnrolmentSubject() != null) { target.setEnrolmentSubjectId(source.getEnrolmentSubject().getId()); } return target; }  @Override PersonEnrolmentSubjectResource convert(final PersonEnrolmentSubject source, final PersonEnrolmentSubjectResource target); @Override PersonEnrolmentSubjectResource convert(final PersonEnrolmentSubject source);  }
@Test public void testConvert() throws Exception { Long id = 1L; 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); PersonEnrolmentSubject source = new PersonEnrolmentSubject(); source.setId(id); source.setMark(mark); source.setPerson(person); source.setPersonPaper(personPaper); source.setEnrolmentSubject(enrolmentSubject); PersonEnrolmentSubjectResource expected = new PersonEnrolmentSubjectResource(); expected.setId(id); expected.setPersonId(personId); expected.setPersonPaperId(personPaperId); expected.setEnrolmentSubjectId(enrolmentSubjectId); expected.setMark(mark); PersonEnrolmentSubjectResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { Long id = 1L; Double mark = 5.0; PersonEnrolmentSubject source = new PersonEnrolmentSubject(); source.setId(id); source.setMark(mark); PersonEnrolmentSubjectResource expected = new PersonEnrolmentSubjectResource(); expected.setId(id); expected.setMark(mark); PersonEnrolmentSubjectResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PersonEnrolmentSubject source = new PersonEnrolmentSubject(); PersonEnrolmentSubjectResource expected = new PersonEnrolmentSubjectResource(); PersonEnrolmentSubjectResource actual = unit.convert(source); assertEquals(expected, actual); }