WorldpayCreateReturnRequestAction extends AbstractComponentWidgetAdapterAware implements CockpitAction<OrderModel, OrderModel> { @Override public boolean canPerform(final ActionContext<OrderModel> actionContext) { OrderModel order = actionContext.getData(); return order != null && isReturnable(order) && isRefundable(order); }  @Override boolean canPerform(final ActionContext<OrderModel> actionContext); @Override String getConfirmationMessage(ActionContext<OrderModel> actionContext); @Override boolean needsConfirmation(ActionContext<OrderModel> actionContext); @Override ActionResult<OrderModel> perform(ActionContext<OrderModel> actionContext);  }
@Test public void canPerformShouldReturnTrueWhenOrderIsReturnableAndRefundable() { final boolean result = testObj.canPerform(actionContextMock); assertTrue(result); }
@Test public void canPerformShouldReturnTrueWhenOrderIsReturnableAndRefundableAndConsignmentIsPickupComplete() { when(consignmentModelMock.getStatus()).thenReturn(ConsignmentStatus.PICKUP_COMPLETE); final boolean result = testObj.canPerform(actionContextMock); assertTrue(result); }
@Test public void canPerformShouldReturnFalseWhenOrderIsNull() { when(actionContextMock.getData()).thenReturn(null); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }
@Test public void canPerformShouldReturnFalseWhenOrderEntriesIsNull() { when(orderModelMock.getEntries()).thenReturn(null); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }
@Test public void canPerformShouldReturnFalseWhenOrderConsignmentsIsEmpty() { when(orderModelMock.getConsignments()).thenReturn(null); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }
@Test public void canPerformShouldReturnFalseWhenAllReturnableEntriesIsEmpty() { when(returnServiceMock.getAllReturnableEntries(orderModelMock)).thenReturn(null); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }
@Test public void canPerformShouldReturnFalseWhenPaymentTransactionsIsEmpty() { when(orderModelMock.getPaymentTransactions()).thenReturn(null); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }
@Test public void canPerformShouldReturnTrueWhenPaymentTransactionsIsForAnAPMThatSupportsAutomaticRefunds() { when(orderModelMock.getPaymentTransactions()).thenReturn(singletonList(paymentTransactionModelMock)); when(paymentTransactionModelMock.getInfo()).thenReturn(worldpayAPMPaymentInfoModelMock); when(worldpayAPMPaymentInfoModelMock.getApmConfiguration()).thenReturn(apmConfigurationMock); when(apmConfigurationMock.getAutomaticRefunds()).thenReturn(true); final boolean result = testObj.canPerform(actionContextMock); assertTrue(result); }
@Test public void canPerformShouldReturnFalseWhenPaymentTransactionsIsForAnAPMThatDoesNotSupportsAutomaticRefunds() { when(orderModelMock.getPaymentTransactions()).thenReturn(singletonList(paymentTransactionModelMock)); when(paymentTransactionModelMock.getInfo()).thenReturn(worldpayAPMPaymentInfoModelMock); when(worldpayAPMPaymentInfoModelMock.getApmConfiguration()).thenReturn(apmConfigurationMock); when(apmConfigurationMock.getAutomaticRefunds()).thenReturn(false); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }
@Test public void canPerformShouldReturnFalseWhenPaymentTransactionsIsForAnAPMThatDoesSupportsAutomaticRefundsButHasNotBeenSettled() { when(orderModelMock.getPaymentTransactions()).thenReturn(singletonList(paymentTransactionModelMock)); when(paymentTransactionModelMock.getInfo()).thenReturn(worldpayAPMPaymentInfoModelMock); when(worldpayAPMPaymentInfoModelMock.getApmConfiguration()).thenReturn(apmConfigurationMock); when(apmConfigurationMock.getAutomaticRefunds()).thenReturn(true); when(worldpayPaymentTransactionServiceMock.filterPaymentTransactionEntriesOfType(paymentTransactionModelMock, SETTLED)).thenReturn(null); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }
@Test public void canPerformShouldReturnFalseWhenPaymentTransactionsIsForACreditCardAndNoCaptureExists() { when(worldpayPaymentTransactionServiceMock.filterPaymentTransactionEntriesOfType(paymentTransactionModelMock, CAPTURE)).thenReturn(null); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }
@Test public void canPerformShouldReturnFalseWhenPaymentTransactionsIsForACreditCardAndCaptureIsPending() { when(worldpayPaymentTransactionServiceMock.isPaymentTransactionPending(paymentTransactionModelMock, CAPTURE)).thenReturn(true); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }