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