PublicActivityResourceConverter extends AbstractConverter<PublicActivityResource, PublicActivity> { @Override public PublicActivity convert(final PublicActivityResource source, final PublicActivity target) { target.setName(source.getName()); target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); if (source.getPublicActivityTypeId() != null) { PublicActivityType publicActiveType = new PublicActivityType(); publicActiveType.setId(source.getPublicActivityTypeId()); target.setPublicActivityType(publicActiveType); } if (source.getTimePeriodId() != null) { TimePeriod timePeriod = new TimePeriod(); timePeriod.setId(source.getTimePeriodId()); target.setTimePeriod(timePeriod); } return target; }  @Override PublicActivity convert(final PublicActivityResource source, final PublicActivity target); @Override PublicActivity convert(final PublicActivityResource 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 expected = new PublicActivity(); expected.setId(id); expected.setName(name); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setPublicActivityType(publicActiveType); expected.setTimePeriod(timePeriod); PublicActivityResource source = new PublicActivityResource(); source.setId(id); source.setName(name); source.setBegDate(begDate); source.setEndDate(endDate); source.setPublicActivityTypeId(publicActiveTypeId); source.setTimePeriodId(timePeriodId); PublicActivity actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { PublicActivity expected = new PublicActivity(); PublicActivityResource source = new PublicActivityResource(); PublicActivity actual = unit.convert(source); assertEquals(expected, actual); }