SpecOfferSubjectResourceConverter extends AbstractConverter<SpecOfferSubjectResource, SpecOfferSubject> { @Override public SpecOfferSubject convert(final SpecOfferSubjectResource source, final SpecOfferSubject target) { target.setAlternative(source.getAlternative()); target.setIsMajor(source.getIsMajor()); target.setMark(source.getMark()); target.setWeightSubject(source.getWeightSubject()); if (source.getSpecOfferId() != null) { SpecOffer specOffer = new SpecOffer(); specOffer.setId(source.getSpecOfferId()); target.setSpecOffer(specOffer); } if (source.getEnrolmentSubjectId() != null) { EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(source.getEnrolmentSubjectId()); target.setEnrolmentSubject(enrolmentSubject); } return target; }  @Override SpecOfferSubject convert(final SpecOfferSubjectResource source, final SpecOfferSubject target); @Override SpecOfferSubject convert(final SpecOfferSubjectResource 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 expected = new SpecOfferSubject(); expected.setAlternative(alternative); expected.setIsMajor(isMajor); expected.setMark(mark); expected.setSpecOffer(specOffer); expected.setEnrolmentSubject(enrolmentSubject); SpecOfferSubjectResource source = new SpecOfferSubjectResource(); source.setAlternative(alternative); source.setId(id); source.setIsMajor(isMajor); source.setMark(mark); source.setSpecOfferId(specOfferId); source.setEnrolmentSubjectId(enrolmentSubjectId); SpecOfferSubject 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 expected = new SpecOfferSubject(); expected.setAlternative(alternative); expected.setIsMajor(isMajor); expected.setMark(mark); SpecOfferSubjectResource source = new SpecOfferSubjectResource(); source.setAlternative(alternative); source.setId(id); source.setIsMajor(isMajor); source.setMark(mark); SpecOfferSubject actual = unit.convert(source); assertEquals(expected, actual); }