SpecOfferResourceConverter extends AbstractConverter<SpecOfferResource, SpecOffer> { @Override public SpecOffer convert(final SpecOfferResource source, final SpecOffer target) { if (source.getDepartmentId() != null) { Department department = new Department(); department.setId(source.getDepartmentId()); target.setDepartment(department); } if (source.getEducationFormTypeId() != null) { EducationFormType eduFormType = new EducationFormType(); eduFormType.setId(source.getEducationFormTypeId()); target.setEducationFormType(eduFormType); } if (source.getSpecialtyId() != null) { Specialty specialty = new Specialty(); specialty.setId(source.getSpecialtyId()); target.setSpecialty(specialty); } if (source.getSpecofferTypeId() != null) { SpecOfferType specOfferType = new SpecOfferType(); specOfferType.setId(source.getSpecofferTypeId()); target.setSpecOfferType(specOfferType); } if (source.getTimePeriodId() != null) { TimePeriod timePeriod = new TimePeriod(); timePeriod.setId(source.getTimePeriodId()); target.setTimePeriod(timePeriod); } if (source.getTimePeriodCourseId() != null) { TimePeriod timePeriodCourse = new TimePeriod(); timePeriodCourse.setId(source.getTimePeriodCourseId()); target.setTimePeriodCourse(timePeriodCourse); } target.setBegDate(source.getBegDate()); target.setDocNum(source.getDocNum()); target.setDocSeries(source.getDocSeries()); target.setEndDate(source.getEndDate()); target.setLicCount(source.getLicCount()); target.setStateCount(source.getStateCount()); target.setDuration(source.getDuration()); return target; }  @Override SpecOffer convert(final SpecOfferResource source, final SpecOffer target); @Override SpecOffer convert(final SpecOfferResource source);  }
@Test public void testConvert() throws Exception { Date begDate = new Date(); Department department = new Department(); Long departmentId = 1L; department.setId(departmentId); String docNum = "doc num"; String docSeries = "doc series"; Date endDate = new Date(); String duration = "txt"; Long educationFormTypeId = 2L; EducationFormType eduFormType = new EducationFormType(); eduFormType.setId(educationFormTypeId); Long id = 1L; Integer licCount = 223; Long parentId = 45L; SpecOffer parent = new SpecOffer(); parent.setId(parentId); Long specialtyId = 4L; Specialty specialty = new Specialty(); specialty.setId(specialtyId); Long specOfferTypeId = 5L; SpecOfferType specOfferType = new SpecOfferType(); specOfferType.setId(specOfferTypeId); Integer stateCount = 34; Long timePeriodId = 5L; TimePeriod timePeriod = new TimePeriod(); timePeriod.setId(timePeriodId); Long timePeriodCourseId = 6L; TimePeriod timePeriodCourse = new TimePeriod(); timePeriodCourse.setId(timePeriodCourseId); SpecOffer expected = new SpecOffer(); expected.setBegDate(begDate); expected.setDepartment(department); expected.setDocNum(docNum); expected.setDocSeries(docSeries); expected.setEducationFormType(eduFormType); expected.setEndDate(endDate); expected.setId(id); expected.setLicCount(licCount); expected.setParent(parent); expected.setSpecialty(specialty); expected.setSpecOfferType(specOfferType); expected.setStateCount(stateCount); expected.setTimePeriod(timePeriod); expected.setTimePeriodCourse(timePeriodCourse); expected.setDuration(duration); SpecOfferResource source = new SpecOfferResource(); source.setBegDate(begDate); source.setDepartmentId(departmentId); source.setDocNum(docNum); source.setDocSeries(docSeries); source.setEndDate(endDate); source.setId(id); source.setLicCount(licCount); source.setSpecialtyId(specialtyId); source.setSpecofferTypeId(specOfferTypeId); source.setStateCount(stateCount); source.setTimePeriodId(timePeriodId); source.setEducationFormTypeId(educationFormTypeId); source.setTimePeriodCourseId(timePeriodCourseId); source.setDuration(duration); SpecOffer actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { Date begDate = new Date(); String docNum = "doc num"; String docSeries = "doc series"; Date endDate = new Date(); Long id = 1L; Integer licCount = 223; Integer stateCount = 34; SpecOffer expected = new SpecOffer(); expected.setBegDate(begDate); expected.setDocNum(docNum); expected.setDocSeries(docSeries); expected.setEndDate(endDate); expected.setId(id); expected.setLicCount(licCount); expected.setStateCount(stateCount); SpecOfferResource source = new SpecOfferResource(); source.setBegDate(begDate); source.setDocNum(docNum); source.setDocSeries(docSeries); source.setEndDate(endDate); source.setId(id); source.setLicCount(licCount); source.setStateCount(stateCount); SpecOffer actual = unit.convert(source); assertEquals(expected, actual); }