OrderConverter extends AbstractConverter<Order, OrderResource> { @Override public OrderResource convert(final Order source, final OrderResource target) { if (source.getOrderType() != null) { target.setOrderTypeId(source.getOrderType().getId()); } if (source.getEmployee() != null) { target.setEmployeeId(source.getEmployee().getId()); } if (source.getAsset() != null) { target.setAssetId(source.getAsset().getId()); } if (source.getPartner() != null) { target.setPartnerId(source.getPartner().getId()); } if (source.getOpType() != null) { target.setOperationTypeId(source.getOpType().getId()); } if (source.getDepartment() != null) { target.setDepartmentId(source.getDepartment().getId()); } if (source.getReason() != null) { target.setReasonId(source.getReason().getId()); } if (source.getParent() != null) { target.setParentId(source.getParent().getId()); } if (source.getTimePeriod() != null) { target.setTimePeriodId(source.getTimePeriod().getId()); } target.setReasonText(source.getReasonText()); target.setDocSeries(source.getDocSeries()); target.setDocNum(source.getDocNum()); target.setDocDate(source.getDocDate()); target.setDocIssued(source.getDocIssued()); target.setEvDate(source.getEvDate()); target.setDescription(source.getDescription()); target.setTitle(source.getTitle()); target.setId(source.getId()); return target; }  @Override OrderResource convert(final Order source, final OrderResource target); @Override OrderResource convert(final Order source);  }
@Test public void testConvert() throws Exception { Long orderTypeId = 1L; OrderType orderType = new OrderType(); orderType.setId(orderTypeId); Long employeeId = 2L; Employee employee = new Employee(); employee.setId(employeeId); Long assetId = 3L; Asset asset = new Asset(); asset.setId(assetId); Long partnerId = 4L; Partner partner = new Partner(); partner.setId(partnerId); Long operationTypeId = 5L; OperationType opType = new OperationType(); opType.setId(operationTypeId); Long departmentId = 6L; Department department = new Department(); department.setId(departmentId); Long reasonId = 7L; Reason reason = new Reason(); reason.setId(reasonId); Long parentId = 8L; Order parent = new Order(); parent.setId(parentId); String reasonText = "reasonText"; String docSeries = "docSeries"; String docNum = "docnum"; Date docDate = new Date(); String docIssued = "docIssued"; Date evDate = new Date(); Order source = new Order(); source.setOrderType(orderType); source.setEmployee(employee); source.setAsset(asset); source.setPartner(partner); source.setOpType(opType); source.setDepartment(department); source.setReason(reason); source.setParent(parent); source.setReasonText(reasonText); source.setDocSeries(docSeries); source.setDocNum(docNum); source.setDocDate(docDate); source.setDocIssued(docIssued); source.setEvDate(evDate); OrderResource expected = new OrderResource(); expected.setOrderTypeId(orderTypeId); expected.setEmployeeId(employeeId); expected.setAssetId(assetId); expected.setPartnerId(partnerId); expected.setOperationTypeId(operationTypeId); expected.setDepartmentId(departmentId); expected.setReasonId(reasonId); expected.setParentId(parentId); expected.setReasonText(reasonText); expected.setDocSeries(docSeries); expected.setDocNum(docNum); expected.setDocDate(docDate); expected.setDocIssued(docIssued); expected.setEvDate(evDate); OrderResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String reasonText = "reasonText"; String docSeries = "docSeries"; String docNum = "docnum"; Date docDate = new Date(); String docIssued = "docIssued"; Date evDate = new Date(); Order source = new Order(); source.setReasonText(reasonText); source.setDocSeries(docSeries); source.setDocNum(docNum); source.setDocDate(docDate); source.setDocIssued(docIssued); source.setEvDate(evDate); OrderResource expected = new OrderResource(); expected.setReasonText(reasonText); expected.setDocSeries(docSeries); expected.setDocNum(docNum); expected.setDocDate(docDate); expected.setDocIssued(docIssued); expected.setEvDate(evDate); OrderResource actual = unit.convert(source); assertEquals(expected, actual); }