### Question:
SQLRevertExecutorFactory { @SneakyThrows public static SQLRevertExecutor newInstance(final SQLRevertExecutorContext context) { SQLStatement sqlStatement = context.getShardingStatement().getSQLStatement(); if (sqlStatement instanceof InsertStatement) { return new InsertSQLRevertExecutor(context); } else if (sqlStatement instanceof DeleteStatement) { return new DeleteSQLRevertExecutor(context, new DeleteSnapshotAccessor(context)); } else if (sqlStatement instanceof UpdateStatement) { return new UpdateSQLRevertExecutor(context, new UpdateSnapshotAccessor(context)); } else { throw new UnsupportedOperationException("unsupported SQL statement"); } }  @SneakyThrows static SQLRevertExecutor newInstance(final SQLRevertExecutorContext context);  }### Answer:
@Test public void assertNewSQLRevertExecutor() { when(executorContext.getShardingStatement()).thenReturn(shardingInsertOptimizedStatement); when(shardingInsertOptimizedStatement.getSQLStatement()).thenReturn(insertStatement); SQLRevertExecutor actual = SQLRevertExecutorFactory.newInstance(executorContext); assertThat(actual, instanceOf(InsertSQLRevertExecutor.class)); }
@Test public void assertNewDeleteSQLRevertExecutor() throws SQLException { when(shardingStatement.getSQLStatement()).thenReturn(deleteStatement); when(executorContext.getConnection()).thenReturn(connection); when(connection.prepareStatement(anyString())).thenReturn(preparedStatement); when(preparedStatement.executeQuery()).thenReturn(resultSet); when(resultSet.getMetaData()).thenReturn(resultSetMetaData); SQLRevertExecutor actual = SQLRevertExecutorFactory.newInstance(executorContext); assertThat(actual, instanceOf(DeleteSQLRevertExecutor.class)); }
@Test public void assertNewUpdateSQLRevertExecutor() throws SQLException { when(shardingStatement.getSQLStatement()).thenReturn(updateStatement); when(executorContext.getConnection()).thenReturn(connection); when(executorContext.getPrimaryKeyColumns()).thenReturn(primaryKeyColumns); when(executorContext.getParameters()).thenReturn(Arrays.<Object>asList(1, 2, 3)); when(connection.prepareStatement(anyString())).thenReturn(preparedStatement); when(preparedStatement.executeQuery()).thenReturn(resultSet); when(resultSet.getMetaData()).thenReturn(resultSetMetaData); SQLRevertExecutor actual = SQLRevertExecutorFactory.newInstance(executorContext); assertThat(actual, instanceOf(UpdateSQLRevertExecutor.class)); }
@Test(expected = UnsupportedOperationException.class) public void assertNewUnsupportedSQLStatement() { when(shardingStatement.getSQLStatement()).thenReturn(mock(DMLStatement.class)); SQLRevertExecutorFactory.newInstance(executorContext); }