### Question:
TransactionalMessagePublisher implements MessagePublisher<TypedMessage>, TransactionalResource { @Override public void begin() throws TransactionException { if (currentTransaction.get() != null) { throw new NestedTransactionException(currentTransaction.get()); } currentTransaction.set(new MessagingTransaction()); logger.trace("Beginning transaction: " + currentTransaction.get().transactionId()); } TransactionalMessagePublisher(final MessagePublisher<TypedMessage> messagePublisher); @Override void begin(); @Override void commit(); @Override void publish(final TypedMessage typedMessage); @Override void abort();  }### Answer:
@Test public void shouldBeginTransaction_withNoExistingTransaction() throws Exception { final TransactionalMessagePublisher transactionalMessagePublisher = new TransactionalMessagePublisher( mockMessagePublisher); Exception actualException = null; try { transactionalMessagePublisher.begin(); } catch (final Exception e) { actualException = e; } assertNull(actualException); }
@Test public void shouldNotBeginTransaction_withExistingTransaction() throws Exception { final TransactionalMessagePublisher transactionalMessagePublisher = new TransactionalMessagePublisher( mockMessagePublisher); transactionalMessagePublisher.begin(); NestedTransactionException actualException = null; try { transactionalMessagePublisher.begin(); } catch (final NestedTransactionException e) { actualException = e; } assertNotNull(actualException); }