WorldpayEntryCodeStrategyImpl implements EntryCodeStrategy { @Override public String generateCode(final PaymentTransactionModel paymentTransaction) { final String transactionCode = paymentTransaction.getCode(); final List<PaymentTransactionEntryModel> entries = paymentTransaction.getEntries(); if (entries == null) { return transactionCode + "-1"; } else { return transactionCode + "-" + (entries.size() + 1); } }  @Override String generateCode(final PaymentTransactionModel paymentTransaction);  }
@Test public void generateNewEntryCodeShouldReturnCodeEndingInEntriesSizePlusOne() throws Exception { when(paymentTransactionModelMock.getEntries()).thenReturn(Collections.singletonList(transactionEntry1Mock)); when(paymentTransactionModelMock.getCode()).thenReturn(PAYMENT_TRANSACTION_CODE); final String result = testObj.generateCode(paymentTransactionModelMock); assertEquals(PAYMENT_TRANSACTION_CODE + "-2", result); }
@Test public void generateNewEntryCodeShouldReturnCodeEndingIn1WhenEntriesIsNull() throws Exception { when(paymentTransactionModelMock.getEntries()).thenReturn(null); when(paymentTransactionModelMock.getCode()).thenReturn(PAYMENT_TRANSACTION_CODE); final String result = testObj.generateCode(paymentTransactionModelMock); assertEquals(PAYMENT_TRANSACTION_CODE + "-1", result); }