DepartmentConverter extends AbstractConverter<Department, DepartmentResource> { @Override public DepartmentResource convert(final Department source, final DepartmentResource target) { target.setAbbrName(source.getAbbrName()); target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); target.setId(source.getId()); target.setManager(source.getManager()); target.setName(source.getName()); target.setIdentifir(source.getIdentifir()); if (source.getOrder() != null) { target.setOrderId(source.getOrder().getId()); } if (source.getParent() != null) { target.setParentId(source.getParent().getId()); } if (source.getDepartmentType() != null) { target.setDepartmentTypeId(source.getDepartmentType().getId()); } return target; }  @Override DepartmentResource convert(final Department source, final DepartmentResource target); @Override DepartmentResource convert(final Department source);  }
@Test public void testConvert() throws Exception { String name = "name"; String abbrName = "abbr name"; Date begDate = new Date(); Date endDate = new Date(); String indetifir = "123"; Department parent = new Department(); parent.setId(1L); DepartmentType departmentType = new DepartmentType(); departmentType.setId(2L); Long orderId = 4L; Order order = new Order(); order.setId(orderId); Department department = new Department(); department.setAbbrName(abbrName); department.setBegDate(begDate); department.setEndDate(endDate); department.setName(name); department.setParent(parent); department.setDepartmentType(departmentType); department.setOrder(order); department.setIdentifir(indetifir); DepartmentResource expected = new DepartmentResource(); expected.setAbbrName(abbrName); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setName(name); expected.setDepartmentTypeId(departmentType.getId()); expected.setParentId(parent.getId()); expected.setOrderId(orderId); expected.setIdentifir(indetifir); DepartmentResource actual = unit.convert(department); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String name = "name"; String abbrName = "abbr name"; Date begDate = new Date(); Date endDate = new Date(); Department department = new Department(); department.setAbbrName(abbrName); department.setBegDate(begDate); department.setEndDate(endDate); department.setName(name); DepartmentResource expected = new DepartmentResource(); expected.setAbbrName(abbrName); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setName(name); DepartmentResource actual = unit.convert(department); assertEquals(expected, actual); }