### Question:
SQLTransactionExecutionHook implements SQLExecutionHook { @Override public void start(final RouteUnit routeUnit, final DataSourceMetaData dataSourceMetaData, final boolean isTrunkThread, final Map<String, Object> shardingExecuteDataMap) { if (!shardingExecuteDataMap.containsKey(Constant.SAGA_TRANSACTION_KEY)) { return; } shardingSQLTransaction = (ShardingSQLTransaction) shardingExecuteDataMap.get(Constant.SAGA_TRANSACTION_KEY); if (!shardingSQLTransaction.getCurrentLogicSQLTransaction().isWritableTransaction()) { return; } sqlTransaction = new SQLTransaction(routeUnit.getDataSourceName(), routeUnit.getSqlUnit().getSql(), splitParameters(routeUnit.getSqlUnit()), ExecuteStatus.EXECUTING); sqlTransaction.setRevertSQLResult(doSQLRevert(shardingSQLTransaction.getCurrentLogicSQLTransaction(), routeUnit).orNull()); shardingSQLTransaction.addSQLTransaction(sqlTransaction); }  @Override void start(final RouteUnit routeUnit, final DataSourceMetaData dataSourceMetaData, final boolean isTrunkThread, final Map<String, Object> shardingExecuteDataMap); @Override void finishSuccess(); @Override void finishFailure(final Exception cause);  }### Answer:
@Test public void assertStartWithinTransaction() throws SQLException { when(logicSQLTransaction.isWritableTransaction()).thenReturn(true); shardingExecuteDataMap.put(SAGA_TRANSACTION_KEY, shardingSQLTransaction); cachedConnections.put("ds", MockTestUtil.mockConnection()); when(shardingSQLTransaction.getCachedConnections()).thenReturn(cachedConnections); SQLStatement sqlStatement = MockTestUtil.mockDeleteStatement("t_order"); ShardingOptimizedStatement optimizedStatement = new ShardingTransparentOptimizedStatement(sqlStatement); when(logicSQLTransaction.getSqlRouteResult()).thenReturn(MockTestUtil.mockSQLRouteResult(optimizedStatement, "ds", "t_order", "t_order_0")); RouteUnit routeUnit = MockTestUtil.mockRouteUnit("ds", "delete from t_order_0 where c1=? and c2=? and c3=?", Arrays.<Object>asList(1, 2, 3)); sqlExecutionHook.start(routeUnit, dataSourceMetaData, true, shardingExecuteDataMap); verify(shardingSQLTransaction).addSQLTransaction(any(SQLTransaction.class)); }
@Test public void assertStartWithoutTransaction() { sqlExecutionHook.start(mock(RouteUnit.class), dataSourceMetaData, true, shardingExecuteDataMap); verify(shardingSQLTransaction, never()).addSQLTransaction(any(SQLTransaction.class)); }
@Test public void assertStartIsNotDMLLogicSQL() { sqlExecutionHook.start(mock(RouteUnit.class), dataSourceMetaData, true, shardingExecuteDataMap); verify(shardingSQLTransaction, never()).addSQLTransaction(any(SQLTransaction.class)); }