SpecOfferSubjectConverter extends AbstractConverter<SpecOfferSubject, SpecOfferSubjectResource> { @Override public SpecOfferSubjectResource convert(final SpecOfferSubject source, final SpecOfferSubjectResource target) { target.setAlternative(source.getAlternative()); target.setId(source.getId()); target.setIsMajor(source.getIsMajor()); target.setMark(source.getMark()); target.setWeightSubject(source.getWeightSubject()); if (source.getSpecOffer() != null) { target.setSpecOfferId(source.getSpecOffer().getId()); } if (source.getEnrolmentSubject() != null) { target.setEnrolmentSubjectId(source.getEnrolmentSubject().getId()); } return target; }  @Override SpecOfferSubjectResource convert(final SpecOfferSubject source, final SpecOfferSubjectResource target); @Override SpecOfferSubjectResource convert(final SpecOfferSubject source);  }
@Test public void testConvert() throws Exception { Boolean alternative = false; Long id = 1L; Boolean isMajor = false; Double mark = 1.5; Long specOfferId = 2L; SpecOffer specOffer = new SpecOffer(); specOffer.setId(specOfferId); Long enrolmentSubjectId = 3L; EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(enrolmentSubjectId); SpecOfferSubject source = new SpecOfferSubject(); source.setAlternative(alternative); source.setId(id); source.setIsMajor(isMajor); source.setMark(mark); source.setSpecOffer(specOffer); source.setEnrolmentSubject(enrolmentSubject); SpecOfferSubjectResource expected = new SpecOfferSubjectResource(); expected.setAlternative(alternative); expected.setId(id); expected.setIsMajor(isMajor); expected.setMark(mark); expected.setSpecOfferId(specOfferId); expected.setEnrolmentSubjectId(enrolmentSubjectId); SpecOfferSubjectResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { Boolean alternative = false; Long id = 1L; Boolean isMajor = false; Double mark = 1.5; SpecOfferSubject source = new SpecOfferSubject(); source.setAlternative(alternative); source.setId(id); source.setIsMajor(isMajor); source.setMark(mark); SpecOfferSubjectResource expected = new SpecOfferSubjectResource(); expected.setAlternative(alternative); expected.setId(id); expected.setIsMajor(isMajor); expected.setMark(mark); SpecOfferSubjectResource actual = unit.convert(source); assertEquals(expected, actual); }