WorldpayOrderCancelDenialStrategy extends AbstractCancelDenialStrategy implements OrderCancelDenialStrategy { @Override public OrderCancelDenialReason getCancelDenialReason(final OrderCancelConfigModel orderCancelConfigModel, final OrderModel orderModel, final PrincipalModel principalModel, boolean partialCancel, boolean partialEntryCancel) { final List<PaymentTransactionModel> paymentTransactions = orderModel.getPaymentTransactions(); if (paymentTransactions != null) { return findReason(orderModel, paymentTransactions); } return null; }  @Override OrderCancelDenialReason getCancelDenialReason(final OrderCancelConfigModel orderCancelConfigModel, final OrderModel orderModel,
                                                         final PrincipalModel principalModel, boolean partialCancel, boolean partialEntryCancel);  }
@Test public void shouldReturnNullWhenCaptureTransactionEntryIsPending() { when(authTransactionEntryMock.getPending()).thenReturn(false); when(capturedTransactionEntryMock.getPending()).thenReturn(true); final OrderCancelDenialReason result = testObj.getCancelDenialReason(orderCancelConfigModelMock, orderModelMock, principalModelMock, false, false); verify(orderModelMock).getPaymentTransactions(); verify(paymentTransaction1Mock).getEntries(); assertNull(result); }
@Test public void shouldReturnNullWhenPaymentTransactionsAreNull() { when(orderModelMock.getPaymentTransactions()).thenReturn(null); final OrderCancelDenialReason result = testObj.getCancelDenialReason(orderCancelConfigModelMock, orderModelMock, principalModelMock, false, false); assertNull(result); }
@Test public void shouldReturnDenialReasonWhenCaptureTransactionEntryIsNotPending() { when(authTransactionEntryMock.getPending()).thenReturn(false); when(capturedTransactionEntryMock.getPending()).thenReturn(false); final OrderCancelDenialReason result = testObj.getCancelDenialReason(orderCancelConfigModelMock, orderModelMock, principalModelMock, false, false); verify(orderModelMock).getPaymentTransactions(); verify(paymentTransaction1Mock).getEntries(); assertNotNull(result); assertEquals(denialReasonMock, result); }
@Test public void shouldReturnDenialReasonWhenOneCaptureTransactionEntryIsNotPending() { when(orderModelMock.getPaymentTransactions()).thenReturn(Arrays.asList(paymentTransaction1Mock, paymentTransaction1Mock)); when(authTransactionEntryMock.getPending()).thenReturn(false); when(capturedTransactionEntryMock.getPending()).thenReturn(true).thenReturn(false); final OrderCancelDenialReason result = testObj.getCancelDenialReason(orderCancelConfigModelMock, orderModelMock, principalModelMock, false, false); verify(orderModelMock).getPaymentTransactions(); verify(paymentTransaction1Mock, times(2)).getEntries(); assertNotNull(result); assertEquals(denialReasonMock, result); }