TimePeriodResourceConverter extends AbstractConverter<TimePeriodResource, TimePeriod> { @Override public TimePeriod convert(final TimePeriodResource source, final TimePeriod target) { target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); target.setName(source.getName()); target.setNumValue(source.getNumValue()); if (source.getTimePeriodTypeId() != null) { TimePeriodType timePeriodType = new TimePeriodType(); timePeriodType.setId(source.getTimePeriodTypeId()); target.setTimePeriodType(timePeriodType); } if (source.getParentId() != null) { TimePeriod parent = new TimePeriod(); parent.setId(source.getParentId()); target.setParent(parent); } return target; }  @Override TimePeriod convert(final TimePeriodResource source, final TimePeriod target); @Override TimePeriod convert(final TimePeriodResource 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 expected = new TimePeriod(); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setName(name); expected.setNumValue(numValue); expected.setParent(parent); expected.setTimePeriodType(timePeriodType); TimePeriodResource source = new TimePeriodResource(); source.setBegDate(begDate); source.setEndDate(endDate); source.setId(id); source.setName(name); source.setNumValue(numValue); source.setParentId(parentId); source.setTimePeriodTypeId(timePeriodTypeId); TimePeriod 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 expected = new TimePeriod(); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setName(name); expected.setNumValue(numValue); TimePeriodResource source = new TimePeriodResource(); source.setBegDate(begDate); source.setEndDate(endDate); source.setId(id); source.setName(name); source.setNumValue(numValue); TimePeriod actual = unit.convert(source); assertEquals(expected, actual); }