SpecOfferTypeResourceConverter extends AbstractConverter<SpecOfferTypeResource, SpecOfferType> { @Override public SpecOfferType convert(final SpecOfferTypeResource source, final SpecOfferType target) { target.setAbbrName(source.getAbbrName()); target.setId(source.getId()); target.setName(source.getName()); if (source.getTimePeriodId() != null) { TimePeriod timePeriod = new TimePeriod(); timePeriod.setId(source.getTimePeriodId()); target.setTimePeriod(timePeriod); } return target; }  @Override SpecOfferType convert(final SpecOfferTypeResource source, final SpecOfferType target); @Override SpecOfferType convert(final SpecOfferTypeResource source);  }
@Test public void testConvert() throws Exception { String name = "first blood"; String abbrName = "fb"; Long id = 1L; Long timePeriodId = 2L; TimePeriod timePeriod = new TimePeriod(); timePeriod.setId(timePeriodId); SpecOfferType expected = new SpecOfferType(); expected.setName(name); expected.setAbbrName(abbrName); expected.setId(id); expected.setTimePeriod(timePeriod); SpecOfferTypeResource source = new SpecOfferTypeResource(); source.setName(name); source.setAbbrName(abbrName); source.setTimePeriodId(timePeriodId); source.setId(id); SpecOfferType actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String name = "first blood"; String abbrName = "fb"; Long id = 1L; SpecOfferType expected = new SpecOfferType(); expected.setName(name); expected.setAbbrName(abbrName); expected.setId(id); SpecOfferTypeResource source = new SpecOfferTypeResource(); source.setName(name); source.setAbbrName(abbrName); source.setId(id); SpecOfferType actual = unit.convert(source); assertEquals(expected, actual); }