### Question:
TransactionalDatabaseTemplate implements DatabaseTemplate, TransactionalResource { @Override public void begin() throws TransactionException { if (currentTransaction.get() != null) { throw new NestedTransactionException(currentTransaction.get()); } currentTransaction.set(new DatabaseTransaction()); logger.trace("Beginning transaction: " + currentTransaction.get().transactionId()); } TransactionalDatabaseTemplate(final DatabaseTemplate databaseTemplate); @Override void begin(); @Override void commit(); @Override T create(final T item, final PersistenceExceptionHandler<?>... persistenceExceptionHandlers); @Override T update(final T item, final PersistenceExceptionHandler<?>... persistenceExceptionHandlers); @Override void delete(final Item item, final PersistenceExceptionHandler<?>... persistenceExceptionHandlers); @Override T read(final ItemId itemId, final Class<T> itemClass); @Override Collection<T> fetch(final Query query, final Class<T> itemClass); @Override T fetchUnique(final Query query, final Class<T> itemClass); @Override GeneratedKeyHolder generateKeys(final SequenceKeyGenerator sequenceKeyGenerator); @Override void abort();  }### Answer:
@Test public void shouldBeginTransaction_withNoExistingTransaction() throws Exception { final TransactionalDatabaseTemplate transactionalDatabaseTemplate = new TransactionalDatabaseTemplate( mockDatabaseTemplate); Exception actualException = null; try { transactionalDatabaseTemplate.begin(); } catch (final Exception e) { actualException = e; } assertNull(actualException); }
@Test public void shouldNotBeginTransaction_withExistingTransaction() throws Exception { final TransactionalDatabaseTemplate transactionalDatabaseTemplate = new TransactionalDatabaseTemplate( mockDatabaseTemplate); transactionalDatabaseTemplate.begin(); NestedTransactionException actualException = null; try { transactionalDatabaseTemplate.begin(); } catch (final NestedTransactionException e) { actualException = e; } assertNotNull(actualException); }