### Question:
LocalTransaction { public void begin() { beginInternal(defaultTransactionIsolationLevel, "begin"); } protected  LocalTransaction(
      DataSource dataSource,
      ThreadLocal<LocalTransactionContext> localTxContextHolder,
      JdbcLogger jdbcLogger); protected  LocalTransaction(
      DataSource dataSource,
      ThreadLocal<LocalTransactionContext> localTxContextHolder,
      JdbcLogger jdbcLogger,
      TransactionIsolationLevel defaultTransactionIsolationLevel); void begin(); void begin(TransactionIsolationLevel transactionIsolationLevel); void commit(); LocalTransactionContext suspend(); void resume(LocalTransactionContext context); void rollback(); void setSavepoint(String savepointName); boolean hasSavepoint(String savepointName); void releaseSavepoint(String savepointName); void rollback(String savepointName); @Override String toString(); boolean isActive(); void setRollbackOnly(); boolean isRollbackOnly();  }### Answer:
@Test public void testBegin() { transaction.begin(); assertTrue(transaction.isActive()); dataSource.getConnection(); assertFalse(connection.autoCommit); assertEquals(TransactionIsolationLevel.READ_COMMITTED.getLevel(), connection.isolationLevel); }
@Test public void testBegin_alreadyBegun() { transaction.begin(); try { transaction.begin(); fail(); } catch (TransactionAlreadyBegunException expected) { System.out.println(expected.getMessage()); } }
@Test public void testBeginAndGetConnection_failedToSetAutoCommit() { final SQLException exception = new SQLException(); MockConnection connection = new MockConnection() { @Override public void setAutoCommit(boolean autoCommit) throws SQLException { throw exception; } }; LocalTransactionDataSource dataSource = new LocalTransactionDataSource(new MockDataSource(connection)); LocalTransaction transaction = dataSource.getLocalTransaction(jdbcLogger); try { transaction.begin(); dataSource.getConnection(); fail(); } catch (JdbcException expected) { System.out.println(expected.getMessage()); assertEquals(exception, expected.getCause()); } }
@Test public void testBegin_failedToSetTransactionIsolation() { final SQLException exception = new SQLException(); MockConnection connection = new MockConnection() { @Override public void setTransactionIsolation(int level) throws SQLException { throw exception; } }; LocalTransactionDataSource dataSource = new LocalTransactionDataSource(new MockDataSource(connection)); LocalTransaction transaction = dataSource.getLocalTransaction(jdbcLogger); try { transaction.begin(TransactionIsolationLevel.READ_COMMITTED); dataSource.getConnection(); fail(); } catch (JdbcException expected) { System.out.println(expected.getMessage()); assertEquals(exception, expected.getCause()); } }