WorldpayTransactionInfoService extends DefaultTransactionInfoService { @Override public boolean isSuccessful(final PaymentTransactionEntryModel entry) { if (isEntryPending(entry)) { return false; } final String transactionStatus = extractTransactionStatusFromEntry(entry); return transactionStatus.equalsIgnoreCase(TransactionStatus.ACCEPTED.name()); }  @Override boolean isSuccessful(final PaymentTransactionEntryModel entry);  }
@Test public void isSuccessfulShouldReturnTrueWhenEntryIsAuthorisedAndAcceptedAndNotPending() throws Exception { when(paymentTransactionEntryModelMock.getType()).thenReturn(PaymentTransactionType.AUTHORIZATION); when(paymentTransactionEntryModelMock.getPending()).thenReturn(false); when(paymentTransactionEntryModelMock.getTransactionStatus()).thenReturn(TransactionStatus.ACCEPTED.name()); final boolean result = testObj.isSuccessful(paymentTransactionEntryModelMock); assertTrue(result); }
@Test public void isSuccessfulShouldReturnFalseWhenEntryIsNotAuthorisedAndPending() throws Exception { when(paymentTransactionEntryModelMock.getType()).thenReturn(PaymentTransactionType.CAPTURE); when(paymentTransactionEntryModelMock.getPending()).thenReturn(true); when(paymentTransactionEntryModelMock.getTransactionStatus()).thenReturn(TransactionStatus.ACCEPTED.name()); final boolean result = testObj.isSuccessful(paymentTransactionEntryModelMock); assertFalse(result); }
@Test public void isSuccessfulShouldReturnFalseWhenEntryIsNotAccepted() throws Exception { when(paymentTransactionEntryModelMock.getType()).thenReturn(PaymentTransactionType.AUTHORIZATION); when(paymentTransactionEntryModelMock.getPending()).thenReturn(false); when(paymentTransactionEntryModelMock.getTransactionStatus()).thenReturn(TransactionStatus.REJECTED.name()); final boolean result = testObj.isSuccessful(paymentTransactionEntryModelMock); assertFalse(result); }
@Test public void isSuccessfulShouldReturnFalseWhenTransactionStatusIsNull() { when(paymentTransactionEntryModelMock.getType()).thenReturn(PaymentTransactionType.AUTHORIZATION); when(paymentTransactionEntryModelMock.getPending()).thenReturn(false); when(paymentTransactionEntryModelMock.getTransactionStatus()).thenReturn(null); final boolean result = testObj.isSuccessful(paymentTransactionEntryModelMock); assertFalse(result); }