DefaultWorldpayCancelWholeOrderDueToCancelNotificationStrategy implements WorldpayCancelWholeOrderDueToCancelNotificationStrategy { @Override public void cancelOrder(final OrderProcessModel orderProcessModel) { final OrderModel orderModel = orderProcessModel.getOrder(); LOG.debug("The order {} is being cancelled.", orderModel::getCode); Optional.ofNullable(worldpayPaymentTransactionService.getPaymentTransactionFromCode(orderModel.getWorldpayOrderCode())) .ifPresentOrElse( paymentTransactionModel -> { createAndSaveCancelTransactionEntry(paymentTransactionModel); orderModel.setStatus(OrderStatus.CANCELLED); }, () -> orderModel.setStatus(OrderStatus.PROCESSING_ERROR) ); modelService.save(orderModel); } DefaultWorldpayCancelWholeOrderDueToCancelNotificationStrategy(final WorldpayPaymentTransactionService worldpayPaymentTransactionService,
                                                                          final ModelService modelService); @Override void cancelOrder(final OrderProcessModel orderProcessModel);  }
@Test public void cancelOrder_ShouldSetTheOrderStatusToCancelled() { when(worldpayPaymentTransactionServiceMock.getPaymentTransactionFromCode(WORLDPAY_ORDER_CODE)).thenReturn(paymentTransactionModelMock); testObj.cancelOrder(orderProcessModelMock); verify(orderModelMock).setStatus(OrderStatus.CANCELLED); verify(paymentTransactionEntryMock).setPaymentTransaction(paymentTransactionModelMock); verify(modelServiceMock).save(paymentTransactionEntryMock); verify(modelServiceMock).save(orderModelMock); }
@Test public void cancelOrder_ShouldSetTheOrderStatusToProcessingError_WhenNoPaymentTransactionFound() { when(orderModelMock.getPaymentTransactions()).thenReturn(Collections.emptyList()); testObj.cancelOrder(orderProcessModelMock); verify(orderModelMock).setStatus(OrderStatus.PROCESSING_ERROR); verify(paymentTransactionEntryMock, never()).setPaymentTransaction(paymentTransactionModelMock); verify(modelServiceMock).save(orderModelMock); }