PublicActivityConverter extends AbstractConverter<PublicActivity, PublicActivityResource> { @Override public PublicActivityResource convert(final PublicActivity source, final PublicActivityResource target) { target.setId(source.getId()); target.setName(source.getName()); target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); if (source.getPublicActivityTypeType() != null) { target.setPublicActivityTypeId(source.getPublicActivityTypeType().getId()); } if (source.getTimePeriod() != null) { target.setTimePeriodId(source.getTimePeriod().getId()); } return target; }  @Override PublicActivityResource convert(final PublicActivity source, final PublicActivityResource target); @Override PublicActivityResource convert(final PublicActivity source);  }
@Test public void testConvert() throws Exception { Long id = 1L; String name = "name"; Date begDate = new Date(); Date endDate = new Date(); Long publicActiveTypeId = 2L; PublicActivityType publicActiveType = new PublicActivityType(); publicActiveType.setId(publicActiveTypeId); Long timePeriodId = 3L; TimePeriod timePeriod = new TimePeriod(); timePeriod.setId(timePeriodId); PublicActivity source = new PublicActivity(); source.setId(id); source.setName(name); source.setBegDate(begDate); source.setEndDate(endDate); source.setPublicActivityType(publicActiveType); source.setTimePeriod(timePeriod); PublicActivityResource expected = new PublicActivityResource(); expected.setId(id); expected.setName(name); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setPublicActivityTypeId(publicActiveTypeId); expected.setTimePeriodId(timePeriodId); PublicActivityResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PublicActivity source = new PublicActivity(); PublicActivityResource expected = new PublicActivityResource(); PublicActivityResource actual = unit.convert(source); assertEquals(expected, actual); }