WorldpayOrderManualCheckedAction extends WorldpayAbstractOrderAction<OrderProcessModel> { @Override public final String execute(final OrderProcessModel process) { ServicesUtil.validateParameterNotNull(process, "Process cannot be null"); final OrderModel order = process.getOrder(); ServicesUtil.validateParameterNotNull(order, "Order in process cannot be null"); if (order.getFraudulent() != null) { final OrderHistoryEntryModel historyLog = createHistoryLog( "Order Manually checked by CSA - Fraud = " + order.getFraudulent(), order); modelService.save(historyLog); if (order.getFraudulent()) { setOrderStatus(order, OrderStatus.SUSPENDED); removeSavedPaymentInfo(order); return NOK; } setOrderStatus(order, FRAUD_CHECKED); return OK; } return UNDEFINED; }  @Override Set<String> getTransitions(); @Override final String execute(final OrderProcessModel process);  }
@Test public void executeShouldReturnOK() { when(orderModelMock.getFraudulent()).thenReturn(false); final String result = testObj.execute(orderProcessModelMock); verify(modelServiceMock).save(orderHistoryEntryModelMock); verify(orderModelMock, never()).setStatus(SUSPENDED); verify(orderModelMock).setStatus(FRAUD_CHECKED); verify(modelServiceMock).save(orderModelMock); assertEquals(OK, result); }
@Test public void executeShouldReturnNOK() { when(orderModelMock.getFraudulent()).thenReturn(true); when(orderModelMock.getPaymentInfo().getOriginal()).thenReturn(originalPaymentInfo); final String result = testObj.execute(orderProcessModelMock); verify(modelServiceMock).save(orderHistoryEntryModelMock); verify(orderModelMock).setStatus(SUSPENDED); verify(modelServiceMock).save(orderModelMock); assertEquals(NOK, result); }
@Test public void executeShouldReturnUNDEFINED() { when(orderModelMock.getFraudulent()).thenReturn(null); final String result = testObj.execute(orderProcessModelMock); verify(modelServiceMock, never()).save(any(OrderHistoryEntryModel.class)); verify(orderModelMock, never()).setStatus(any(OrderStatus.class)); assertEquals(UNDEFINED, result); }
@Test public void executeDeletePaymentInfoWhenCheckFraudAndPaymentSaved() { when(orderModelMock.getFraudulent()).thenReturn(true); when(orderModelMock.getPaymentInfo().getOriginal()).thenReturn(originalPaymentInfo); when(originalPaymentInfo.isSaved()).thenReturn(true); final String result = testObj.execute(orderProcessModelMock); verify(modelServiceMock).remove(originalPaymentInfo); assertEquals(NOK, result); }