TransactionLogger { public void logTransactionFromRelatedMessageId(String relatedMessageId, String messageId) { String transactionId = getTransactionStore().getTransactionId(relatedMessageId); logTransaction(transactionId, messageId); } TransactionLogger(); void logTransaction(String transactionId, String messageId); void logTransactionFromRelatedMessageId(String relatedMessageId, String messageId);  }
@Test public void logRelatedTransaction() { final TransactionStore transactionStore = mock(TransactionStore.class); TransactionLogger transactionLogger = new TransactionLogger() { @Override protected TransactionStore getTransactionStore() { return transactionStore; } }; when(transactionStore.getTransactionId(RELATED_MESSAGE_ID)).thenReturn(TRANSACTION_ID); when(transactionStore.insertIntoTransactionRepo(any(TransactionRepo.class))).thenReturn(true); transactionLogger.logTransactionFromRelatedMessageId(RELATED_MESSAGE_ID, MESSAGE_ID); verifyLog(transactionStore, MESSAGE_ID, TRANSACTION_ID); }
@Test public void logNoRelatedTransaction() { final TransactionStore transactionStore = mock(TransactionStore.class); TransactionLogger transactionLogger = new TransactionLogger() { @Override protected TransactionStore getTransactionStore() { return transactionStore; } }; when(transactionStore.getTransactionId(RELATED_MESSAGE_ID)).thenReturn(null); transactionLogger.logTransactionFromRelatedMessageId(RELATED_MESSAGE_ID, MESSAGE_ID); verifyNothingLogged(transactionStore); }