TimePeriodConverter extends AbstractConverter<TimePeriod, TimePeriodResource> { @Override public TimePeriodResource convert(final TimePeriod source, final TimePeriodResource target) { target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); target.setId(source.getId()); target.setName(source.getName()); target.setNumValue(source.getNumValue()); if (source.getParent() != null) { target.setParentId(source.getParent().getId()); } if (source.getTimePeriodType() != null) { target.setTimePeriodTypeId(source.getTimePeriodType().getId()); } return target; }  @Override TimePeriodResource convert(final TimePeriod source, final TimePeriodResource target); @Override TimePeriodResource convert(final TimePeriod source);  }
@Test public void testConvert() throws Exception { Long parentId = 2L; TimePeriod parent = new TimePeriod(); parent.setId(parentId); Long timePeriodTypeId = 3L; TimePeriodType timePeriodType = new TimePeriodType(); timePeriodType.setId(timePeriodTypeId); Date begDate = new Date(); Date endDate = new Date(); Long id = 1L; String name = "name"; Integer numValue = 1; TimePeriod source = new TimePeriod(); source.setBegDate(begDate); source.setEndDate(endDate); source.setId(id); source.setName(name); source.setNumValue(numValue); source.setParent(parent); source.setTimePeriodType(timePeriodType); TimePeriodResource expected = new TimePeriodResource(); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setId(id); expected.setName(name); expected.setNumValue(numValue); expected.setParentId(parentId); expected.setTimePeriodTypeId(timePeriodTypeId); TimePeriodResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { Date begDate = new Date(); Date endDate = new Date(); Long id = 1L; String name = "name"; Integer numValue = 1; TimePeriod source = new TimePeriod(); source.setBegDate(begDate); source.setEndDate(endDate); source.setId(id); source.setName(name); source.setNumValue(numValue); TimePeriodResource expected = new TimePeriodResource(); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setId(id); expected.setName(name); expected.setNumValue(numValue); TimePeriodResource actual = unit.convert(source); assertEquals(expected, actual); }