DepartmentResourceConverter extends AbstractConverter<DepartmentResource, Department> { @Override public Department convert(final DepartmentResource source, final Department target) { if (source.getDepartmentTypeId() != null) { DepartmentType departmentType = new DepartmentType(); departmentType.setId(source.getDepartmentTypeId()); target.setDepartmentType(departmentType); } if (source.getParentId() != null) { Department parent = new Department(); parent.setId(source.getParentId()); target.setParent(parent); } if (source.getOrderId() != null) { Order order = new Order(); order.setId(source.getOrderId()); target.setOrder(order); } target.setEndDate(source.getEndDate()); target.setBegDate(source.getBegDate()); target.setAbbrName(source.getAbbrName()); target.setManager(source.getManager()); target.setName(source.getName()); target.setIdentifir(source.getIdentifir()); return target; }  @Override Department convert(final DepartmentResource source, final Department target); @Override Department convert(final DepartmentResource source);  }
@Test public void testConvert() throws Exception { String name = "name"; String abbrName = "abbr name"; Date begDate = new Date(); Date endDate = new Date(); String indetifir = "1d 23"; 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 expected = new Department(); expected.setAbbrName(abbrName); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setName(name); expected.setParent(parent); expected.setDepartmentType(departmentType); expected.setId(orderId); expected.setIdentifir(indetifir); DepartmentResource departmentResource = new DepartmentResource(); departmentResource.setAbbrName(abbrName); departmentResource.setBegDate(begDate); departmentResource.setEndDate(endDate); departmentResource.setName(name); departmentResource.setDepartmentTypeId(departmentType.getId()); departmentResource.setParentId(parent.getId()); departmentResource.setOrderId(orderId); departmentResource.setIdentifir(indetifir); Department actual = unit.convert(departmentResource); 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 expected = new Department(); expected.setAbbrName(abbrName); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setName(name); DepartmentResource departmentResource = new DepartmentResource(); departmentResource.setAbbrName(abbrName); departmentResource.setBegDate(begDate); departmentResource.setEndDate(endDate); departmentResource.setName(name); Department actual = unit.convert(departmentResource); assertEquals(expected, actual); }