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