This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new e0dbe9f  Remove useless eq and thenReturn(null) for mock  (#11514)
e0dbe9f is described below

commit e0dbe9f967fac336499ae6a8886f4ece656cbef6
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jul 26 22:28:31 2021 +0800

    Remove useless eq and thenReturn(null) for mock  (#11514)
    
    * Remove useless eq with mock
    
    * Remove useless eq with mock
    
    * Remove useless eq with mock
    
    * Remove useless eq with mock
    
    * Remove useless eq with mock
    
    * Remove useless thenReturn(null)
---
 .../DecoratedEncryptColumnsMergedResultTest.java   |  3 +-
 ...ovidedShardingRuleConfigurationCheckerTest.java |  3 +-
 .../ShardingRuleConfigurationCheckerTest.java      |  3 +-
 .../GovernanceTransactionContextsTest.java         |  2 +-
 .../lock/ShardingSphereDistributeLockTest.java     |  7 +-
 .../zookeeper/CuratorZookeeperRepositoryTest.java  | 29 ++++----
 .../service/SchemaMetaDataPersistServiceTest.java  |  1 -
 .../AlterTableStatementSchemaRefresherTest.java    | 79 ++++----------------
 .../CreateTableStatementSchemaRefresherTest.java   | 57 ++++-----------
 .../impl/decorator/DecoratorMergedResultTest.java  |  1 -
 .../AlterTableStatementFederateRefresherTest.java  | 85 +++++-----------------
 .../CreateTableStatementFederateRefresherTest.java | 85 +++++++---------------
 .../DropTableStatementFederateRefresherTest.java   | 26 +++----
 .../jdbc/connection/BackendConnectionTest.java     | 12 +--
 .../frontend/command/CommandExecutorTaskTest.java  | 52 +++++--------
 .../component/PostgreSQLWalDumperTest.java         |  1 -
 .../wal/decode/TestDecodingPluginTest.java         |  5 +-
 17 files changed, 133 insertions(+), 318 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/impl/DecoratedEncryptColumnsMergedResultTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/impl/DecoratedEncryptColumnsMergedResultTest.java
index a5fa8b5..53b4731 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/impl/DecoratedEncryptColumnsMergedResultTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/impl/DecoratedEncryptColumnsMergedResultTest.java
@@ -33,7 +33,6 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -51,7 +50,7 @@ public final class DecoratedEncryptColumnsMergedResultTest {
         MergedResult mergedResult = mock(MergedResult.class);
         when(mergedResult.next()).thenReturn(true);
         when(mergedResult.wasNull()).thenReturn(false);
-        when(mergedResult.getValue(eq(new Integer(1)), 
eq(getClass()))).thenReturn("test");
+        when(mergedResult.getValue(1, getClass())).thenReturn("test");
         DecoratedEncryptColumnsMergedResult actual = new 
DecoratedEncryptColumnsMergedResult(mergedResult, testStatementContext, 
mock(EncryptRule.class));
         assertNotNull(actual);
         assertTrue(actual.nextValue());
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/AlgorithmProvidedShardingRuleConfigurationCheckerTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/AlgorithmProvidedShardingRuleConfigurationCheckerTest.java
index ab14b7a..ddacf40 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/AlgorithmProvidedShardingRuleConfigurationCheckerTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/AlgorithmProvidedShardingRuleConfigurationCheckerTest.java
@@ -40,6 +40,7 @@ public final class 
AlgorithmProvidedShardingRuleConfigurationCheckerTest {
         ShardingSphereServiceLoader.register(RuleConfigurationChecker.class);
     }
     
+    @SuppressWarnings({"rawtypes", "unchecked"})
     @Test
     public void assertCheckPass() {
         ShardingStrategyConfiguration strategyConfiguration = 
mock(ShardingStrategyConfiguration.class);
@@ -55,12 +56,12 @@ public final class 
AlgorithmProvidedShardingRuleConfigurationCheckerTest {
         checker.check("test", ruleConfig);
     }
     
+    @SuppressWarnings({"rawtypes", "unchecked"})
     @Test(expected = IllegalStateException.class)
     public void assertCheckNoPass() {
         AlgorithmProvidedShardingRuleConfiguration ruleConfig = 
mock(AlgorithmProvidedShardingRuleConfiguration.class);
         when(ruleConfig.getTables()).thenReturn(Collections.emptyList());
         when(ruleConfig.getAutoTables()).thenReturn(Collections.emptyList());
-        when(ruleConfig.getDefaultTableShardingStrategy()).thenReturn(null);
         RuleConfigurationChecker checker = 
OrderedSPIRegistry.getRegisteredServices(Collections.singleton(ruleConfig), 
RuleConfigurationChecker.class).get(ruleConfig);
         assertNotNull(checker);
         assertThat(checker, 
instanceOf(AlgorithmProvidedShardingRuleConfigurationChecker.class));
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/ShardingRuleConfigurationCheckerTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/ShardingRuleConfigurationCheckerTest.java
index 51d16d7..c9298e3 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/ShardingRuleConfigurationCheckerTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/ShardingRuleConfigurationCheckerTest.java
@@ -40,6 +40,7 @@ public final class ShardingRuleConfigurationCheckerTest {
         ShardingSphereServiceLoader.register(RuleConfigurationChecker.class);
     }
     
+    @SuppressWarnings({"rawtypes", "unchecked"})
     @Test
     public void assertCheckPass() {
         ShardingStrategyConfiguration strategyConfiguration = 
mock(ShardingStrategyConfiguration.class);
@@ -55,12 +56,12 @@ public final class ShardingRuleConfigurationCheckerTest {
         checker.check("test", ruleConfig);
     }
     
+    @SuppressWarnings({"rawtypes", "unchecked"})
     @Test(expected = IllegalStateException.class)
     public void assertCheckNoPass() {
         ShardingRuleConfiguration ruleConfig = 
mock(ShardingRuleConfiguration.class);
         when(ruleConfig.getTables()).thenReturn(Collections.emptyList());
         when(ruleConfig.getAutoTables()).thenReturn(Collections.emptyList());
-        when(ruleConfig.getDefaultTableShardingStrategy()).thenReturn(null);
         RuleConfigurationChecker checker = 
OrderedSPIRegistry.getRegisteredServices(Collections.singleton(ruleConfig), 
RuleConfigurationChecker.class).get(ruleConfig);
         assertNotNull(checker);
         assertThat(checker, 
instanceOf(ShardingRuleConfigurationChecker.class));
diff --git 
a/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/transaction/GovernanceTransactionContextsTest.java
 
b/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/transaction/GovernanceTransactionContextsTest.java
index 4a0fd3d..aae557b 100644
--- 
a/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/transaction/GovernanceTransactionContextsTest.java
+++ 
b/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/transaction/GovernanceTransactionContextsTest.java
@@ -73,7 +73,7 @@ public final class GovernanceTransactionContextsTest {
     public void assertRenew() throws Exception {
         when(event.getSchemaName()).thenReturn("name");
         when(transactionContexts.getEngines()).thenReturn(engineMap);
-        when(engineMap.remove(eq("name"))).thenReturn(engine);
+        when(engineMap.remove("name")).thenReturn(engine);
         GovernanceTransactionContexts actual = new 
GovernanceTransactionContexts(transactionContexts, 
XATransactionManagerType.ATOMIKOS.getType());
         actual.renew(event);
         verify(engine).close();
diff --git 
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/ShardingSphereDistributeLockTest.java
 
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/ShardingSphereDistributeLockTest.java
index 6dad09d..4bc78b4 100644
--- 
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/ShardingSphereDistributeLockTest.java
+++ 
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/ShardingSphereDistributeLockTest.java
@@ -27,7 +27,6 @@ import org.mockito.junit.MockitoJUnitRunner;
 
 import java.lang.reflect.Field;
 
-import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -49,14 +48,14 @@ public final class ShardingSphereDistributeLockTest {
     
     @Test
     public void assertTryLock() {
-        when(lockService.tryLock(eq("test"), 
eq(50L))).thenReturn(Boolean.TRUE);
+        when(lockService.tryLock("test", 50L)).thenReturn(Boolean.TRUE);
         lock.tryLock("test", 50L);
-        verify(lockService).tryLock(eq("test"), eq(50L));
+        verify(lockService).tryLock("test", 50L);
     }
     
     @Test
     public void assertReleaseLock() {
         lock.releaseLock("test");
-        verify(lockService).releaseLock(eq("test"));
+        verify(lockService).releaseLock("test");
     }
 }
diff --git 
a/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/governance/repository/zookeeper/CuratorZookeeperRepositoryTest.java
 
b/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/go
 [...]
index 0b86cf8..16bebaa 100644
--- 
a/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/governance/repository/zookeeper/CuratorZookeeperRepositoryTest.java
+++ 
b/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/governance/repository/zookeeper/CuratorZookeeperRepositoryTest.java
@@ -189,37 +189,35 @@ public final class CuratorZookeeperRepositoryTest {
     @Test
     @SneakyThrows
     public void assertPersist() {
-        when(existsBuilder.forPath(eq("/test"))).thenReturn(null);
-        when(protect.withMode(eq(CreateMode.PERSISTENT))).thenReturn(protect);
+        when(protect.withMode(CreateMode.PERSISTENT)).thenReturn(protect);
         REPOSITORY.persist("/test", "value1");
-        verify(protect).forPath(eq("/test"), 
eq("value1".getBytes(StandardCharsets.UTF_8)));
+        verify(protect).forPath("/test", 
"value1".getBytes(StandardCharsets.UTF_8));
     }
     
     @Test
     @SneakyThrows
     public void assertUpdate() {
-        when(existsBuilder.forPath(eq("/test"))).thenReturn(new Stat());
+        when(existsBuilder.forPath("/test")).thenReturn(new Stat());
         REPOSITORY.persist("/test", "value2");
-        verify(setDataBuilder).forPath(eq("/test"), 
eq("value2".getBytes(StandardCharsets.UTF_8)));
+        verify(setDataBuilder).forPath("/test", 
"value2".getBytes(StandardCharsets.UTF_8));
     }
     
     @Test
     @SneakyThrows
     public void assertPersistEphemeralNotExist() {
-        when(existsBuilder.forPath(eq("/test/ephemeral"))).thenReturn(null);
-        when(protect.withMode(eq(CreateMode.EPHEMERAL))).thenReturn(protect);
+        when(protect.withMode(CreateMode.EPHEMERAL)).thenReturn(protect);
         REPOSITORY.persistEphemeral("/test/ephemeral", "value3");
-        verify(protect).forPath(eq("/test/ephemeral"), 
eq("value3".getBytes(StandardCharsets.UTF_8)));
+        verify(protect).forPath("/test/ephemeral", 
"value3".getBytes(StandardCharsets.UTF_8));
     }
     
     @Test
     @SneakyThrows
     public void assertPersistEphemeralExist() {
-        when(existsBuilder.forPath(eq("/test/ephemeral"))).thenReturn(new 
Stat());
-        when(protect.withMode(eq(CreateMode.EPHEMERAL))).thenReturn(protect);
+        when(existsBuilder.forPath("/test/ephemeral")).thenReturn(new Stat());
+        when(protect.withMode(CreateMode.EPHEMERAL)).thenReturn(protect);
         REPOSITORY.persistEphemeral("/test/ephemeral", "value4");
-        verify(backgroundVersionable).forPath(eq("/test/ephemeral"));
-        verify(protect).forPath(eq("/test/ephemeral"), 
eq("value4".getBytes(StandardCharsets.UTF_8)));
+        verify(backgroundVersionable).forPath("/test/ephemeral");
+        verify(protect).forPath("/test/ephemeral", 
"value4".getBytes(StandardCharsets.UTF_8));
     }
     
     @Test
@@ -339,7 +337,6 @@ public final class CuratorZookeeperRepositoryTest {
     @Test
     @SneakyThrows
     public void assertDeleteNotExistKey() {
-        when(existsBuilder.forPath(eq("/test/children/1"))).thenReturn(null);
         REPOSITORY.delete("/test/children/1");
         verify(client, times(0)).delete();
     }
@@ -347,7 +344,7 @@ public final class CuratorZookeeperRepositoryTest {
     @Test
     @SneakyThrows
     public void assertDeleteExistKey() {
-        when(existsBuilder.forPath(eq("/test/children/1"))).thenReturn(new 
Stat());
+        when(existsBuilder.forPath("/test/children/1")).thenReturn(new Stat());
         
when(deleteBuilder.deletingChildrenIfNeeded()).thenReturn(backgroundVersionable);
         REPOSITORY.delete("/test/children/1");
         verify(backgroundVersionable).forPath("/test/children/1");
@@ -356,14 +353,14 @@ public final class CuratorZookeeperRepositoryTest {
     @Test
     @SneakyThrows
     public void assertTryLock() {
-        when(interProcessLock.acquire(eq(5L), 
eq(TimeUnit.SECONDS))).thenReturn(true);
+        when(interProcessLock.acquire(5L, TimeUnit.SECONDS)).thenReturn(true);
         assertThat(REPOSITORY.tryLock("/locks/glock", 5, TimeUnit.SECONDS), 
is(true));
     }
     
     @Test
     @SneakyThrows
     public void assertTryLockFailed() {
-        when(interProcessLock.acquire(eq(5L), 
eq(TimeUnit.SECONDS))).thenReturn(false);
+        when(interProcessLock.acquire(5L, TimeUnit.SECONDS)).thenReturn(false);
         assertThat(REPOSITORY.tryLock("/locks/glock", 5, TimeUnit.SECONDS), 
is(false));
     }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/persist/service/SchemaMetaDataPersistServiceTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/persist/service/SchemaMetaDataPersistServiceTest.java
index 11f531a..94a4ba8 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/persist/service/SchemaMetaDataPersistServiceTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/persist/service/SchemaMetaDataPersistServiceTest.java
@@ -75,7 +75,6 @@ public final class SchemaMetaDataPersistServiceTest {
         Optional<ShardingSphereSchema> empty = 
schemaMetaDataPersistService.load("test");
         assertThat(empty, is(Optional.empty()));
         ShardingSphereSchema schema = schemaOptional.get();
-        verify(repository).get(eq("/metadata/foo_db/schema"));
         assertThat(schema.getAllTableNames(), 
is(Collections.singleton("t_order")));
         assertThat(schema.get("t_order").getIndexes().keySet(), 
is(Collections.singleton("primary")));
         assertThat(schema.getAllColumnNames("t_order").size(), is(1));
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresherTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresherTest.java
index 54fadd1..88ffd92 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresherTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresherTest.java
@@ -25,7 +25,6 @@ import 
org.apache.shardingsphere.infra.database.type.dialect.SQLServerDatabaseTy
 import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
 import 
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import org.apache.shardingsphere.infra.rule.type.TableContainedRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
@@ -37,28 +36,28 @@ import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.ddl.SQL92AlterTableStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerAlterTableStatement;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
 
 import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+@RunWith(MockitoJUnitRunner.class)
 public final class AlterTableStatementSchemaRefresherTest {
     
-    private final SchemaBuilderMaterials materials = 
mock(SchemaBuilderMaterials.class);
+    @Mock
+    private SchemaBuilderMaterials materials;
     
     @Test
     public void refreshForMySQL() throws SQLException {
@@ -92,31 +91,26 @@ public final class AlterTableStatementSchemaRefresherTest {
     
     @Test
     public void refreshWithTableRuleForMySQL() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new MySQLDatabaseType());
         refreshWithTableRule(new MySQLAlterTableStatement());
     }
     
     @Test
     public void refreshWithTableRuleForOracle() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new OracleDatabaseType());
         refreshWithTableRule(new OracleAlterTableStatement());
     }
     
     @Test
     public void refreshWithTableRuleForPostgreSQL() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new 
PostgreSQLDatabaseType());
         refreshWithTableRule(new PostgreSQLAlterTableStatement());
     }
     
     @Test
     public void refreshWithTableRuleForSQL92() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new SQL92DatabaseType());
         refreshWithTableRule(new SQL92AlterTableStatement());
     }
     
     @Test
     public void refreshWithTableRuleForSQLServer() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new 
SQLServerDatabaseType());
         refreshWithTableRule(new SQLServerAlterTableStatement());
     }
     
@@ -128,23 +122,14 @@ public final class AlterTableStatementSchemaRefresherTest 
{
     
     @Test
     public void refreshWithRenameTableWithTableRuleForPostgreSQL() throws 
SQLException {
-        when(materials.getDatabaseType()).thenReturn(new 
PostgreSQLDatabaseType());
         refreshWithRenameTableWithTableRule(new 
PostgreSQLAlterTableStatement());
     }
-
+    
     private void refresh(final AlterTableStatement alterTableStatement) throws 
SQLException {
         alterTableStatement.setTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
-        Map<String, DataSource> dataSourceMap = mock(HashMap.class);
-        when(materials.getDataSourceMap()).thenReturn(dataSourceMap);
-        DataSource dataSource = mock(DataSource.class);
-        when(dataSourceMap.get(eq("ds"))).thenReturn(dataSource);
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        DatabaseMetaData metaData = mock(DatabaseMetaData.class);
-        when(connection.getMetaData()).thenReturn(metaData);
-        ResultSet resultSet = mock(ResultSet.class);
-        when(metaData.getTables(any(), any(), any(), 
any())).thenReturn(resultSet);
-        when(resultSet.next()).thenReturn(false);
+        DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
+        when(dataSource.getConnection().getMetaData().getTables(any(), any(), 
any(), any())).thenReturn(mock(ResultSet.class));
+        
when(materials.getDataSourceMap()).thenReturn(Collections.singletonMap("ds", 
dataSource));
         SchemaRefresher<AlterTableStatement> schemaRefresher = new 
AlterTableStatementSchemaRefresher();
         ShardingSphereSchema schema = 
ShardingSphereSchemaBuildUtil.buildSchema();
         schemaRefresher.refresh(schema, Collections.singletonList("ds"), 
alterTableStatement, materials);
@@ -153,21 +138,9 @@ public final class AlterTableStatementSchemaRefresherTest {
     
     private void refreshWithTableRule(final AlterTableStatement 
alterTableStatement) throws SQLException {
         alterTableStatement.setTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
-        Map<String, DataSource> dataSourceMap = mock(HashMap.class);
         TableContainedRule rule = mock(TableContainedRule.class);
-        Collection<ShardingSphereRule> rules = Collections.singletonList(rule);
-        when(materials.getRules()).thenReturn(rules);
         
when(rule.getTables()).thenReturn(Collections.singletonList("t_order"));
-        when(materials.getDataSourceMap()).thenReturn(dataSourceMap);
-        DataSource dataSource = mock(DataSource.class);
-        when(dataSourceMap.get(eq("ds"))).thenReturn(dataSource);
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        DatabaseMetaData metaData = mock(DatabaseMetaData.class);
-        when(connection.getMetaData()).thenReturn(metaData);
-        ResultSet resultSet = mock(ResultSet.class);
-        when(metaData.getTables(any(), any(), any(), 
any())).thenReturn(resultSet);
-        when(resultSet.next()).thenReturn(false);
+        when(materials.getRules()).thenReturn(Collections.singletonList(rule));
         SchemaRefresher<AlterTableStatement> schemaRefresher = new 
AlterTableStatementSchemaRefresher();
         ShardingSphereSchema schema = 
ShardingSphereSchemaBuildUtil.buildSchema();
         schemaRefresher.refresh(schema, Collections.singletonList("ds"), 
alterTableStatement, materials);
@@ -177,17 +150,9 @@ public final class AlterTableStatementSchemaRefresherTest {
     private void refreshWithRenameTable(final AlterTableStatement 
alterTableStatement) throws SQLException {
         alterTableStatement.setTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
         alterTableStatement.setRenameTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order_new"))));
-        Map<String, DataSource> dataSourceMap = mock(HashMap.class);
-        when(materials.getDataSourceMap()).thenReturn(dataSourceMap);
-        DataSource dataSource = mock(DataSource.class);
-        when(dataSourceMap.get(eq("ds"))).thenReturn(dataSource);
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        DatabaseMetaData metaData = mock(DatabaseMetaData.class);
-        when(connection.getMetaData()).thenReturn(metaData);
-        ResultSet resultSet = mock(ResultSet.class);
-        when(metaData.getTables(any(), any(), any(), 
any())).thenReturn(resultSet);
-        when(resultSet.next()).thenReturn(false);
+        DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
+        when(dataSource.getConnection().getMetaData().getTables(any(), any(), 
any(), any())).thenReturn(mock(ResultSet.class));
+        
when(materials.getDataSourceMap()).thenReturn(Collections.singletonMap("ds", 
dataSource));
         SchemaRefresher<AlterTableStatement> schemaRefresher = new 
AlterTableStatementSchemaRefresher();
         ShardingSphereSchema schema = 
ShardingSphereSchemaBuildUtil.buildSchema();
         schemaRefresher.refresh(schema, Collections.singletonList("ds"), 
alterTableStatement, materials);
@@ -198,21 +163,9 @@ public final class AlterTableStatementSchemaRefresherTest {
     private void refreshWithRenameTableWithTableRule(final AlterTableStatement 
alterTableStatement) throws SQLException {
         alterTableStatement.setTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
         alterTableStatement.setRenameTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order_new"))));
-        Map<String, DataSource> dataSourceMap = mock(HashMap.class);
         TableContainedRule rule = mock(TableContainedRule.class);
-        Collection<ShardingSphereRule> rules = Collections.singletonList(rule);
-        when(materials.getRules()).thenReturn(rules);
         when(rule.getTables()).thenReturn(Arrays.asList("t_order", 
"t_order_new"));
-        when(materials.getDataSourceMap()).thenReturn(dataSourceMap);
-        DataSource dataSource = mock(DataSource.class);
-        when(dataSourceMap.get(eq("ds"))).thenReturn(dataSource);
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        DatabaseMetaData metaData = mock(DatabaseMetaData.class);
-        when(connection.getMetaData()).thenReturn(metaData);
-        ResultSet resultSet = mock(ResultSet.class);
-        when(metaData.getTables(any(), any(), any(), 
any())).thenReturn(resultSet);
-        when(resultSet.next()).thenReturn(false);
+        when(materials.getRules()).thenReturn(Collections.singletonList(rule));
         SchemaRefresher<AlterTableStatement> schemaRefresher = new 
AlterTableStatementSchemaRefresher();
         ShardingSphereSchema schema = 
ShardingSphereSchemaBuildUtil.buildSchema();
         schemaRefresher.refresh(schema, Collections.singletonList("ds"), 
alterTableStatement, materials);
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresherTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresherTest.java
index 87c9f6b..357b432 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresherTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresherTest.java
@@ -25,7 +25,6 @@ import 
org.apache.shardingsphere.infra.database.type.dialect.SQLServerDatabaseTy
 import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
 import 
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import org.apache.shardingsphere.infra.rule.type.TableContainedRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
@@ -37,26 +36,26 @@ import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.ddl.SQL92CreateTableStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerCreateTableStatement;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
 
 import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
 
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+@RunWith(MockitoJUnitRunner.class)
 public final class CreateTableStatementSchemaRefresherTest {
     
-    private SchemaBuilderMaterials materials = 
mock(SchemaBuilderMaterials.class);
+    @Mock
+    private SchemaBuilderMaterials materials;
     
     @Test
     public void refreshForMySQL() throws SQLException {
@@ -99,53 +98,37 @@ public final class CreateTableStatementSchemaRefresherTest {
     public void refreshWithTableRuleForMySQL() throws SQLException {
         MySQLCreateTableStatement createTableStatement = new 
MySQLCreateTableStatement();
         createTableStatement.setContainsNotExistClause(false);
-        when(materials.getDatabaseType()).thenReturn(new MySQLDatabaseType());
         refreshWithTableRule(createTableStatement);
     }
     
     @Test
     public void refreshWithTableRuleForOracle() throws SQLException {
-        OracleCreateTableStatement createTableStatement = new 
OracleCreateTableStatement();
-        when(materials.getDatabaseType()).thenReturn(new OracleDatabaseType());
-        refreshWithTableRule(createTableStatement);
+        refreshWithTableRule(new OracleCreateTableStatement());
     }
     
     @Test
     public void refreshWithTableRuleForPostgreSQL() throws SQLException {
         PostgreSQLCreateTableStatement createTableStatement = new 
PostgreSQLCreateTableStatement();
         createTableStatement.setContainsNotExistClause(false);
-        when(materials.getDatabaseType()).thenReturn(new 
PostgreSQLDatabaseType());
         refreshWithTableRule(createTableStatement);
     }
     
     @Test
     public void refreshWithTableRuleForSQL92() throws SQLException {
-        SQL92CreateTableStatement createTableStatement = new 
SQL92CreateTableStatement();
-        when(materials.getDatabaseType()).thenReturn(new SQL92DatabaseType());
-        refreshWithTableRule(createTableStatement);
+        refreshWithTableRule(new SQL92CreateTableStatement());
     }
     
     @Test
     public void refreshWithTableRuleForSQLServer() throws SQLException {
-        SQLServerCreateTableStatement createTableStatement = new 
SQLServerCreateTableStatement();
-        when(materials.getDatabaseType()).thenReturn(new 
SQLServerDatabaseType());
-        refreshWithTableRule(createTableStatement);
+        refreshWithTableRule(new SQLServerCreateTableStatement());
     }
     
     // TODO add more tests for tables with table rule
     private void refresh(final CreateTableStatement createTableStatement) 
throws SQLException {
         createTableStatement.setTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order_0"))));
-        Map<String, DataSource> dataSourceMap = mock(HashMap.class);
-        when(materials.getDataSourceMap()).thenReturn(dataSourceMap);
-        DataSource dataSource = mock(DataSource.class);
-        when(dataSourceMap.get(eq("ds"))).thenReturn(dataSource);
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        DatabaseMetaData metaData = mock(DatabaseMetaData.class);
-        when(connection.getMetaData()).thenReturn(metaData);
-        ResultSet resultSet = mock(ResultSet.class);
-        when(metaData.getTables(any(), any(), any(), 
any())).thenReturn(resultSet);
-        when(resultSet.next()).thenReturn(false);
+        DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
+        when(dataSource.getConnection().getMetaData().getTables(any(), any(), 
any(), any())).thenReturn(mock(ResultSet.class));
+        
when(materials.getDataSourceMap()).thenReturn(Collections.singletonMap("ds", 
dataSource));
         ShardingSphereSchema schema = 
ShardingSphereSchemaBuildUtil.buildSchema();
         SchemaRefresher<CreateTableStatement> schemaRefresher = new 
CreateTableStatementSchemaRefresher();
         schemaRefresher.refresh(schema, Collections.singleton("ds"), 
createTableStatement, materials);
@@ -155,20 +138,8 @@ public final class CreateTableStatementSchemaRefresherTest 
{
     private void refreshWithTableRule(final CreateTableStatement 
createTableStatement) throws SQLException {
         createTableStatement.setTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order_0"))));
         TableContainedRule rule = mock(TableContainedRule.class);
-        Collection<ShardingSphereRule> rules = Collections.singletonList(rule);
-        when(materials.getRules()).thenReturn(rules);
+        when(materials.getRules()).thenReturn(Collections.singletonList(rule));
         
when(rule.getTables()).thenReturn(Collections.singletonList("t_order_0"));
-        Map<String, DataSource> dataSourceMap = mock(HashMap.class);
-        when(materials.getDataSourceMap()).thenReturn(dataSourceMap);
-        DataSource dataSource = mock(DataSource.class);
-        when(dataSourceMap.get(eq("ds"))).thenReturn(dataSource);
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        DatabaseMetaData metaData = mock(DatabaseMetaData.class);
-        when(connection.getMetaData()).thenReturn(metaData);
-        ResultSet resultSet = mock(ResultSet.class);
-        when(metaData.getTables(any(), any(), any(), 
any())).thenReturn(resultSet);
-        when(resultSet.next()).thenReturn(false);
         ShardingSphereSchema schema = 
ShardingSphereSchemaBuildUtil.buildSchema();
         SchemaRefresher<CreateTableStatement> schemaRefresher = new 
CreateTableStatementSchemaRefresher();
         schemaRefresher.refresh(schema, Collections.singleton("ds"), 
createTableStatement, materials);
diff --git 
a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/decorator/DecoratorMergedResultTest.java
 
b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/decorator/DecoratorMergedResultTest.java
index 1e1a17d..b457f46 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/decorator/DecoratorMergedResultTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/decorator/DecoratorMergedResultTest.java
@@ -63,7 +63,6 @@ public final class DecoratorMergedResultTest {
     
     @Test
     public void assertGetInputStreamWithColumnIndex() throws SQLException {
-        when(mergedResult.getInputStream(1, "ascii")).thenReturn(null);
         assertNull(decoratorMergedResult.getInputStream(1, "ascii"));
     }
     
diff --git 
a/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/metadata/refresher/AlterTableStatementFederateRefresherTest.java
 
b/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/metadata/refresher/AlterTableStatementFederateRefresherTest.java
index 6239bc5..9d93671 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/metadata/refresher/AlterTableStatementFederateRefresherTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/metadata/refresher/AlterTableStatementFederateRefresherTest.java
@@ -29,7 +29,6 @@ import 
org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
 import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
 import 
org.apache.shardingsphere.infra.optimize.core.metadata.FederateSchemaMetadata;
 import 
org.apache.shardingsphere.infra.optimize.core.metadata.refresher.type.AlterTableStatementFederateRefresher;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import org.apache.shardingsphere.infra.rule.type.TableContainedRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
@@ -41,60 +40,44 @@ import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.ddl.SQL92AlterTableStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerAlterTableStatement;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
 
 import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+@RunWith(MockitoJUnitRunner.class)
 public final class AlterTableStatementFederateRefresherTest {
-
-    private final SchemaBuilderMaterials materials = 
mock(SchemaBuilderMaterials.class);
-
+    
+    @Mock
+    private SchemaBuilderMaterials materials;
+    
     @Test
     public void refreshTableWithRule() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new MySQLDatabaseType());
         refreshTableWithRule(new MySQLAlterTableStatement());
-        when(materials.getDatabaseType()).thenReturn(new OracleDatabaseType());
         refreshTableWithRule(new OracleAlterTableStatement());
-        when(materials.getDatabaseType()).thenReturn(new 
PostgreSQLDatabaseType());
         refreshTableWithRule(new PostgreSQLAlterTableStatement());
-        when(materials.getDatabaseType()).thenReturn(new 
SQLServerDatabaseType());
         refreshTableWithRule(new SQLServerAlterTableStatement());
-        when(materials.getDatabaseType()).thenReturn(new SQL92DatabaseType());
         refreshTableWithRule(new SQL92AlterTableStatement());
     }
     
     private void refreshTableWithRule(final AlterTableStatement 
alterTableStatement) throws SQLException {
         alterTableStatement.setTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
-        Map<String, DataSource> dataSourceMap = mock(HashMap.class);
         TableContainedRule rule = mock(TableContainedRule.class);
-        Collection<ShardingSphereRule> rules = Collections.singletonList(rule);
-        when(materials.getRules()).thenReturn(rules);
         
when(rule.getTables()).thenReturn(Collections.singletonList("t_order"));
-        when(materials.getDataSourceMap()).thenReturn(dataSourceMap);
-        DataSource dataSource = mock(DataSource.class);
-        when(dataSourceMap.get(eq("ds"))).thenReturn(dataSource);
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        DatabaseMetaData metaData = mock(DatabaseMetaData.class);
-        when(connection.getMetaData()).thenReturn(metaData);
-        ResultSet resultSet = mock(ResultSet.class);
-        when(metaData.getTables(any(), any(), any(), 
any())).thenReturn(resultSet);
-        when(resultSet.next()).thenReturn(false);
+        when(materials.getRules()).thenReturn(Collections.singletonList(rule));
         FederateRefresher<AlterTableStatement> federateRefresher = new 
AlterTableStatementFederateRefresher();
         FederateSchemaMetadata schema = buildSchema();
         federateRefresher.refresh(schema, Collections.singletonList("ds"), 
alterTableStatement, materials);
@@ -118,17 +101,9 @@ public final class 
AlterTableStatementFederateRefresherTest {
     private void refreshTableWithoutRule(final AlterTableStatement 
alterTableStatement) throws SQLException {
         alterTableStatement.setTable(
                 new SimpleTableSegment(new TableNameSegment(1, 3, new 
IdentifierValue("t_order"))));
-        Map<String, DataSource> dataSourceMap = mock(HashMap.class);
-        when(materials.getDataSourceMap()).thenReturn(dataSourceMap);
-        DataSource dataSource = mock(DataSource.class);
-        when(dataSourceMap.get(eq("ds"))).thenReturn(dataSource);
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        DatabaseMetaData metaData = mock(DatabaseMetaData.class);
-        when(connection.getMetaData()).thenReturn(metaData);
-        ResultSet resultSet = mock(ResultSet.class);
-        when(metaData.getTables(any(), any(), any(), 
any())).thenReturn(resultSet);
-        when(resultSet.next()).thenReturn(false);
+        DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
+        when(dataSource.getConnection().getMetaData().getTables(any(), any(), 
any(), any())).thenReturn(mock(ResultSet.class));
+        
when(materials.getDataSourceMap()).thenReturn(Collections.singletonMap("ds", 
dataSource));
         FederateRefresher<AlterTableStatement> federateRefresher = new 
AlterTableStatementFederateRefresher();
         FederateSchemaMetadata schema = buildSchema();
         federateRefresher.refresh(schema, Collections.singletonList("ds"), 
alterTableStatement, materials);
@@ -137,36 +112,19 @@ public final class 
AlterTableStatementFederateRefresherTest {
     
     @Test
     public void renameTableWithRule() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new MySQLDatabaseType());
         renameTableWithRule(new MySQLAlterTableStatement());
-        when(materials.getDatabaseType()).thenReturn(new OracleDatabaseType());
         renameTableWithRule(new OracleAlterTableStatement());
-        when(materials.getDatabaseType()).thenReturn(new 
PostgreSQLDatabaseType());
         renameTableWithRule(new PostgreSQLAlterTableStatement());
-        when(materials.getDatabaseType()).thenReturn(new 
SQLServerDatabaseType());
         renameTableWithRule(new SQLServerAlterTableStatement());
-        when(materials.getDatabaseType()).thenReturn(new SQL92DatabaseType());
         renameTableWithRule(new SQL92AlterTableStatement());
     }
     
     private void renameTableWithRule(final AlterTableStatement 
alterTableStatement) throws SQLException {
         alterTableStatement.setTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
         alterTableStatement.setRenameTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order_new"))));
-        Map<String, DataSource> dataSourceMap = mock(HashMap.class);
         TableContainedRule rule = mock(TableContainedRule.class);
-        Collection<ShardingSphereRule> rules = Collections.singletonList(rule);
-        when(materials.getRules()).thenReturn(rules);
         when(rule.getTables()).thenReturn(Arrays.asList("t_order", 
"t_order_new"));
-        when(materials.getDataSourceMap()).thenReturn(dataSourceMap);
-        DataSource dataSource = mock(DataSource.class);
-        when(dataSourceMap.get(eq("ds"))).thenReturn(dataSource);
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        DatabaseMetaData metaData = mock(DatabaseMetaData.class);
-        when(connection.getMetaData()).thenReturn(metaData);
-        ResultSet resultSet = mock(ResultSet.class);
-        when(metaData.getTables(any(), any(), any(), 
any())).thenReturn(resultSet);
-        when(resultSet.next()).thenReturn(false);
+        when(materials.getRules()).thenReturn(Collections.singletonList(rule));
         FederateRefresher<AlterTableStatement> federateRefresher = new 
AlterTableStatementFederateRefresher();
         FederateSchemaMetadata schema = buildSchema();
         federateRefresher.refresh(schema, Collections.singletonList("ds"), 
alterTableStatement, materials);
@@ -191,17 +149,9 @@ public final class 
AlterTableStatementFederateRefresherTest {
     private void renameTableWithoutRule(final AlterTableStatement 
alterTableStatement) throws SQLException {
         alterTableStatement.setTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
         alterTableStatement.setRenameTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order_new"))));
-        Map<String, DataSource> dataSourceMap = mock(HashMap.class);
-        when(materials.getDataSourceMap()).thenReturn(dataSourceMap);
-        DataSource dataSource = mock(DataSource.class);
-        when(dataSourceMap.get(eq("ds"))).thenReturn(dataSource);
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        DatabaseMetaData metaData = mock(DatabaseMetaData.class);
-        when(connection.getMetaData()).thenReturn(metaData);
-        ResultSet resultSet = mock(ResultSet.class);
-        when(metaData.getTables(any(), any(), any(), 
any())).thenReturn(resultSet);
-        when(resultSet.next()).thenReturn(false);
+        DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
+        when(dataSource.getConnection().getMetaData().getTables(any(), any(), 
any(), any())).thenReturn(mock(ResultSet.class));
+        
when(materials.getDataSourceMap()).thenReturn(Collections.singletonMap("ds", 
dataSource));
         FederateRefresher<AlterTableStatement> federateRefresher = new 
AlterTableStatementFederateRefresher();
         FederateSchemaMetadata schema = buildSchema();
         federateRefresher.refresh(schema, Collections.singletonList("ds"), 
alterTableStatement, materials);
@@ -215,4 +165,3 @@ public final class AlterTableStatementFederateRefresherTest 
{
         return new FederateSchemaMetadata("t_order", metaData);
     }
 }
-
diff --git 
a/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/metadata/refresher/CreateTableStatementFederateRefresherTest.java
 
b/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/metadata/refresher/CreateTableStatementFederateRefresherTest.java
index dfd80d2..27cfc34 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/metadata/refresher/CreateTableStatementFederateRefresherTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/metadata/refresher/CreateTableStatementFederateRefresherTest.java
@@ -18,18 +18,12 @@
 package org.apache.shardingsphere.infra.optimize.core.metadata.refresher;
 
 import com.google.common.collect.ImmutableMap;
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.dialect.OracleDatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.SQL92DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.dialect.SQLServerDatabaseType;
 import 
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
 import org.apache.shardingsphere.infra.metadata.schema.model.ColumnMetaData;
 import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
 import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
 import 
org.apache.shardingsphere.infra.optimize.core.metadata.FederateSchemaMetadata;
 import 
org.apache.shardingsphere.infra.optimize.core.metadata.refresher.type.CreateTableStatementFederateRefresher;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import org.apache.shardingsphere.infra.rule.type.TableContainedRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
@@ -41,132 +35,103 @@ import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.ddl.SQL92CreateTableStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerCreateTableStatement;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
 
 import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+@RunWith(MockitoJUnitRunner.class)
 public final class CreateTableStatementFederateRefresherTest {
-
-    private final SchemaBuilderMaterials materials = 
mock(SchemaBuilderMaterials.class);
-
+    
+    @Mock
+    private SchemaBuilderMaterials materials;
+    
     @Test
     public void refreshForMySQL() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new MySQLDatabaseType());
         refreshTableWithRule(new MySQLCreateTableStatement());
     }
-
+    
     @Test
     public void refreshForOracle() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new OracleDatabaseType());
         refreshTableWithRule(new OracleCreateTableStatement());
     }
-
+    
     @Test
     public void refreshForPostgreSQL() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new 
PostgreSQLDatabaseType());
         refreshTableWithRule(new PostgreSQLCreateTableStatement());
     }
-
+    
     @Test
     public void refreshForSQL92() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new SQL92DatabaseType());
         refreshTableWithRule(new SQL92CreateTableStatement());
     }
-
+    
     @Test
     public void refreshForSQLServer() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new 
SQLServerDatabaseType());
         refreshTableWithRule(new SQLServerCreateTableStatement());
     }
-
+    
     @Test
     public void refreshWithoutRuleForMySQL() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new MySQLDatabaseType());
         refreshTableWithoutRule(new MySQLCreateTableStatement());
     }
-
+    
     @Test
     public void refreshWithoutRuleForOracle() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new OracleDatabaseType());
         refreshTableWithoutRule(new OracleCreateTableStatement());
     }
-
+    
     @Test
     public void refreshWithoutRuleForPostgreSQL() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new 
PostgreSQLDatabaseType());
         refreshTableWithoutRule(new PostgreSQLCreateTableStatement());
     }
-
+    
     @Test
     public void refreshWithoutRuleForSQL92() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new SQL92DatabaseType());
         refreshTableWithoutRule(new SQL92CreateTableStatement());
     }
-
+    
     @Test
     public void refreshWithoutRuleForSQLServer() throws SQLException {
-        when(materials.getDatabaseType()).thenReturn(new 
SQLServerDatabaseType());
         refreshTableWithoutRule(new SQLServerCreateTableStatement());
     }
-
+    
     private void refreshTableWithRule(final CreateTableStatement 
createTableStatement) throws SQLException {
         createTableStatement.setTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
-        Map<String, DataSource> dataSourceMap = mock(HashMap.class);
         TableContainedRule rule = mock(TableContainedRule.class);
-        Collection<ShardingSphereRule> rules = Collections.singletonList(rule);
-        when(materials.getRules()).thenReturn(rules);
         
when(rule.getTables()).thenReturn(Collections.singletonList("t_order"));
-        when(materials.getDataSourceMap()).thenReturn(dataSourceMap);
-        DataSource dataSource = mock(DataSource.class);
-        when(dataSourceMap.get(eq("ds"))).thenReturn(dataSource);
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        DatabaseMetaData metaData = mock(DatabaseMetaData.class);
-        when(connection.getMetaData()).thenReturn(metaData);
-        ResultSet resultSet = mock(ResultSet.class);
-        when(metaData.getTables(any(), any(), any(), 
any())).thenReturn(resultSet);
-        when(resultSet.next()).thenReturn(false);
+        when(materials.getRules()).thenReturn(Collections.singletonList(rule));
         FederateRefresher<CreateTableStatement> federateRefresher = new 
CreateTableStatementFederateRefresher();
         FederateSchemaMetadata schema = buildSchema();
         federateRefresher.refresh(schema, Collections.singletonList("ds"), 
createTableStatement, materials);
         assertTrue(schema.getTables().containsKey("t_order"));
         
assertFalse(schema.getTables().get("t_order").getColumnNames().contains("order_id"));
     }
-
+    
     private void refreshTableWithoutRule(final CreateTableStatement 
createTableStatement) throws SQLException {
         createTableStatement.setTable(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
-        Map<String, DataSource> dataSourceMap = mock(HashMap.class);
-        when(materials.getDataSourceMap()).thenReturn(dataSourceMap);
-        DataSource dataSource = mock(DataSource.class);
-        when(dataSourceMap.get(eq("t_order_item"))).thenReturn(dataSource);
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        DatabaseMetaData metaData = mock(DatabaseMetaData.class);
-        when(connection.getMetaData()).thenReturn(metaData);
-        ResultSet resultSet = mock(ResultSet.class);
-        when(metaData.getTables(any(), any(), any(), 
any())).thenReturn(resultSet);
-        when(resultSet.next()).thenReturn(false);
+        DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
+        when(dataSource.getConnection().getMetaData().getTables(any(), any(), 
any(), any())).thenReturn(mock(ResultSet.class));
+        
when(materials.getDataSourceMap()).thenReturn(Collections.singletonMap("ds", 
dataSource));
         FederateRefresher<CreateTableStatement> federateRefresher = new 
CreateTableStatementFederateRefresher();
         FederateSchemaMetadata schema = buildSchema();
         federateRefresher.refresh(schema, 
Collections.singletonList("t_order_item"), createTableStatement, materials);
         assertTrue(schema.getTables().containsKey("t_order"));
         
assertFalse(schema.getTables().get("t_order").getColumnNames().contains("order_id"));
     }
-
+    
     private FederateSchemaMetadata buildSchema() {
         Map<String, TableMetaData> metaData = ImmutableMap.of("t_order", new 
TableMetaData("t_order", Collections.singletonList(new 
ColumnMetaData("order_id", 1, false, false, false)),
                 Collections.singletonList(new IndexMetaData("index"))));
diff --git 
a/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/metadata/refresher/DropTableStatementFederateRefresherTest.java
 
b/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/metadata/refresher/DropTableStatementFederateRefresherTest.java
index 619c79c..32e2630 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/metadata/refresher/DropTableStatementFederateRefresherTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/metadata/refresher/DropTableStatementFederateRefresherTest.java
@@ -43,32 +43,32 @@ import static org.junit.Assert.assertFalse;
 import static org.mockito.Mockito.mock;
 
 public final class DropTableStatementFederateRefresherTest {
-
+    
     @Test
     public void refreshForMySQL() throws SQLException {
         refresh(new MySQLDropTableStatement());
     }
-
+    
     @Test
     public void refreshForOracle() throws SQLException {
         refresh(new OracleDropTableStatement());
     }
-
+    
     @Test
     public void refreshForPostgreSQL() throws SQLException {
         refresh(new PostgreSQLDropTableStatement());
     }
-
+    
     @Test
     public void refreshForSQL92() throws SQLException {
         refresh(new SQL92DropTableStatement());
     }
-
+    
     @Test
     public void refreshForSQLServer() throws SQLException {
         refresh(new SQLServerDropTableStatement());
     }
-
+    
     private void refresh(final DropTableStatement dropTableStatement) throws 
SQLException {
         FederateSchemaMetadata schema = buildSchema();
         FederateRefresher<DropTableStatement> schemaRefresher = new 
DropTableStatementFederateRefresher();
@@ -76,39 +76,39 @@ public final class DropTableStatementFederateRefresherTest {
         schemaRefresher.refresh(schema, Collections.emptyList(), 
dropTableStatement, mock(SchemaBuilderMaterials.class));
         assertFalse(schema.getTables().containsKey("t_order"));
     }
-
+    
     @Test
     public void refreshWithUnConfiguredForMySQL() throws SQLException {
         refreshWithUnConfigured(new MySQLDropTableStatement());
     }
-
+    
     @Test
     public void refreshWithUnConfiguredForOracle() throws SQLException {
         refreshWithUnConfigured(new OracleDropTableStatement());
     }
-
+    
     @Test
     public void refreshWithUnConfiguredForPostgreSQL() throws SQLException {
         refreshWithUnConfigured(new PostgreSQLDropTableStatement());
     }
-
+    
     @Test
     public void refreshWithUnConfiguredForSQL92() throws SQLException {
         refreshWithUnConfigured(new SQL92DropTableStatement());
     }
-
+    
     @Test
     public void refreshWithUnConfiguredForSQLServer() throws SQLException {
         refreshWithUnConfigured(new SQLServerDropTableStatement());
     }
-
+    
     private void refreshWithUnConfigured(final DropTableStatement 
dropTableStatement) throws SQLException {
         FederateSchemaMetadata schema = buildSchema();
         FederateRefresher<DropTableStatement> schemaRefresher = new 
DropTableStatementFederateRefresher();
         dropTableStatement.getTables().add(new SimpleTableSegment(new 
TableNameSegment(1, 3, new IdentifierValue("t_order_item"))));
         schemaRefresher.refresh(schema, 
Collections.singletonList("t_order_item"), dropTableStatement, 
mock(SchemaBuilderMaterials.class));
     }
-
+    
     private FederateSchemaMetadata buildSchema() {
         Map<String, TableMetaData> metaData = ImmutableMap.of("t_order", new 
TableMetaData("t_order", Collections.singletonList(new 
ColumnMetaData("order_id", 1, false, false, false)),
                 Collections.singletonList(new IndexMetaData("index"))));
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java
index aad7953..78aa8f9 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java
@@ -321,22 +321,22 @@ public final class BackendConnectionTest {
     @Test
     public void assertGetConnectionsWithoutTransactions() throws SQLException {
         backendConnection.getTransactionStatus().setInTransaction(false);
-        List<Connection> connectionList = 
MockConnectionUtil.mockNewConnections(1);
-        when(backendDataSource.getConnections(anyString(), anyString(), eq(1), 
any())).thenReturn(connectionList);
+        List<Connection> connections = 
MockConnectionUtil.mockNewConnections(1);
+        when(backendDataSource.getConnections(anyString(), anyString(), eq(1), 
any())).thenReturn(connections);
         List<Connection> fetchedConnections = 
backendConnection.getConnections("ds1", 1, null);
         assertThat(fetchedConnections.size(), is(1));
-        assertTrue(fetchedConnections.contains(connectionList.get(0)));
-        assertConnectionsCached("ds1", connectionList);
+        assertTrue(fetchedConnections.contains(connections.get(0)));
+        assertConnectionsCached("ds1", connections);
     }
     
     @SuppressWarnings("unchecked")
     @SneakyThrows(ReflectiveOperationException.class)
-    private void assertConnectionsCached(final String dataSourceName, final 
Collection<Connection> collectionList) {
+    private void assertConnectionsCached(final String dataSourceName, final 
Collection<Connection> connections) {
         Field field = 
backendConnection.getClass().getDeclaredField("cachedConnections");
         field.setAccessible(true);
         Multimap<String, Connection> cachedConnections = (Multimap<String, 
Connection>) field.get(backendConnection);
         assertTrue(cachedConnections.containsKey(dataSourceName));
-        assertArrayEquals(cachedConnections.get(dataSourceName).toArray(), 
collectionList.toArray());
+        assertArrayEquals(cachedConnections.get(dataSourceName).toArray(), 
connections.toArray());
     }
     
     @SuppressWarnings("unchecked")
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java
index 826e00e..b7d7b82 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.proxy.frontend.command;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
-import org.apache.shardingsphere.db.protocol.codec.DatabasePacketCodecEngine;
 import org.apache.shardingsphere.db.protocol.packet.CommandPacket;
 import org.apache.shardingsphere.db.protocol.packet.CommandPacketType;
 import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
@@ -44,7 +43,6 @@ import java.util.Optional;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.atLeast;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -52,13 +50,10 @@ import static org.mockito.Mockito.when;
 @RunWith(MockitoJUnitRunner.class)
 public final class CommandExecutorTaskTest {
     
-    @Mock
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private DatabaseProtocolFrontendEngine engine;
     
     @Mock
-    private DatabasePacketCodecEngine codecEngine;
-    
-    @Mock
     private PacketPayload payload;
     
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -71,9 +66,6 @@ public final class CommandExecutorTaskTest {
     private ConnectionStatus connectionStatus;
     
     @Mock
-    private CommandExecuteEngine executeEngine;
-    
-    @Mock
     private ByteBuf message;
     
     @Mock
@@ -102,13 +94,11 @@ public final class CommandExecutorTaskTest {
     @Test
     public void assertRunNeedFlushByFalse() throws SQLException {
         
when(queryCommandExecutor.execute()).thenReturn(Collections.emptyList());
-        when(executeEngine.getCommandPacket(eq(payload), 
eq(commandPacketType), eq(backendConnection))).thenReturn(commandPacket);
-        when(executeEngine.getCommandExecutor(eq(commandPacketType), 
eq(commandPacket), eq(backendConnection))).thenReturn(queryCommandExecutor);
-        
when(executeEngine.getCommandPacketType(eq(payload))).thenReturn(commandPacketType);
-        when(engine.getCommandExecuteEngine()).thenReturn(executeEngine);
+        when(engine.getCommandExecuteEngine().getCommandPacket(payload, 
commandPacketType, backendConnection)).thenReturn(commandPacket);
+        
when(engine.getCommandExecuteEngine().getCommandExecutor(commandPacketType, 
commandPacket, backendConnection)).thenReturn(queryCommandExecutor);
+        
when(engine.getCommandExecuteEngine().getCommandPacketType(payload)).thenReturn(commandPacketType);
         
when(backendConnection.getConnectionStatus()).thenReturn(connectionStatus);
-        when(codecEngine.createPacketPayload(eq(message))).thenReturn(payload);
-        when(engine.getCodecEngine()).thenReturn(codecEngine);
+        
when(engine.getCodecEngine().createPacketPayload(message)).thenReturn(payload);
         
when(backendConnection.closeConnections(false)).thenReturn(Collections.emptyList());
         
when(backendConnection.closeFederateExecutor()).thenReturn(Collections.emptyList());
         CommandExecutorTask actual = new CommandExecutorTask(engine, 
backendConnection, handlerContext, message);
@@ -122,14 +112,12 @@ public final class CommandExecutorTaskTest {
     @Test
     public void assertRunNeedFlushByTrue() throws SQLException {
         
when(queryCommandExecutor.execute()).thenReturn(Collections.singletonList(databasePacket));
-        when(executeEngine.getCommandPacket(eq(payload), 
eq(commandPacketType), eq(backendConnection))).thenReturn(commandPacket);
-        when(executeEngine.getCommandExecutor(eq(commandPacketType), 
eq(commandPacket), eq(backendConnection))).thenReturn(queryCommandExecutor);
-        
when(executeEngine.getCommandPacketType(eq(payload))).thenReturn(commandPacketType);
-        when(executeEngine.writeQueryData(any(ChannelHandlerContext.class), 
any(BackendConnection.class), any(QueryCommandExecutor.class), 
anyInt())).thenReturn(true);
-        when(engine.getCommandExecuteEngine()).thenReturn(executeEngine);
+        when(engine.getCommandExecuteEngine().getCommandPacket(payload, 
commandPacketType, backendConnection)).thenReturn(commandPacket);
+        
when(engine.getCommandExecuteEngine().getCommandExecutor(commandPacketType, 
commandPacket, backendConnection)).thenReturn(queryCommandExecutor);
+        
when(engine.getCommandExecuteEngine().getCommandPacketType(payload)).thenReturn(commandPacketType);
+        
when(engine.getCommandExecuteEngine().writeQueryData(any(ChannelHandlerContext.class),
 any(BackendConnection.class), any(QueryCommandExecutor.class), 
anyInt())).thenReturn(true);
         
when(backendConnection.getConnectionStatus()).thenReturn(connectionStatus);
-        when(codecEngine.createPacketPayload(eq(message))).thenReturn(payload);
-        when(engine.getCodecEngine()).thenReturn(codecEngine);
+        
when(engine.getCodecEngine().createPacketPayload(message)).thenReturn(payload);
         
when(backendConnection.closeConnections(false)).thenReturn(Collections.emptyList());
         
when(backendConnection.closeFederateExecutor()).thenReturn(Collections.emptyList());
         CommandExecutorTask actual = new CommandExecutorTask(engine, 
backendConnection, handlerContext, message);
@@ -138,7 +126,7 @@ public final class CommandExecutorTaskTest {
         verify(connectionStatus).switchToUsing();
         verify(handlerContext).write(databasePacket);
         verify(handlerContext).flush();
-        verify(executeEngine).writeQueryData(handlerContext, 
backendConnection, queryCommandExecutor, 1);
+        
verify(engine.getCommandExecuteEngine()).writeQueryData(handlerContext, 
backendConnection, queryCommandExecutor, 1);
         verify(queryCommandExecutor).close();
         verify(backendConnection).closeDatabaseCommunicationEngines(true);
     }
@@ -148,13 +136,11 @@ public final class CommandExecutorTaskTest {
         when(frontendContext.isFlushForPerCommandPacket()).thenReturn(true);
         when(engine.getFrontendContext()).thenReturn(frontendContext);
         
when(commandExecutor.execute()).thenReturn(Collections.singletonList(databasePacket));
-        when(executeEngine.getCommandPacket(eq(payload), 
eq(commandPacketType), eq(backendConnection))).thenReturn(commandPacket);
-        when(executeEngine.getCommandExecutor(eq(commandPacketType), 
eq(commandPacket), eq(backendConnection))).thenReturn(commandExecutor);
-        
when(executeEngine.getCommandPacketType(eq(payload))).thenReturn(commandPacketType);
-        when(engine.getCommandExecuteEngine()).thenReturn(executeEngine);
+        when(engine.getCommandExecuteEngine().getCommandPacket(payload, 
commandPacketType, backendConnection)).thenReturn(commandPacket);
+        
when(engine.getCommandExecuteEngine().getCommandExecutor(commandPacketType, 
commandPacket, backendConnection)).thenReturn(commandExecutor);
+        
when(engine.getCommandExecuteEngine().getCommandPacketType(payload)).thenReturn(commandPacketType);
         
when(backendConnection.getConnectionStatus()).thenReturn(connectionStatus);
-        when(codecEngine.createPacketPayload(eq(message))).thenReturn(payload);
-        when(engine.getCodecEngine()).thenReturn(codecEngine);
+        
when(engine.getCodecEngine().createPacketPayload(message)).thenReturn(payload);
         
when(backendConnection.closeConnections(false)).thenReturn(Collections.emptyList());
         
when(backendConnection.closeFederateExecutor()).thenReturn(Collections.emptyList());
         CommandExecutorTask actual = new CommandExecutorTask(engine, 
backendConnection, handlerContext, message);
@@ -171,11 +157,9 @@ public final class CommandExecutorTaskTest {
     public void assertRunWithError() {
         RuntimeException mockException = new RuntimeException("mock");
         when(backendConnection.getConnectionStatus()).thenThrow(mockException);
-        when(codecEngine.createPacketPayload(message)).thenReturn(payload);
-        when(engine.getCodecEngine()).thenReturn(codecEngine);
-        when(executeEngine.getErrorPacket(mockException, 
backendConnection)).thenReturn(databasePacket);
-        
when(executeEngine.getOtherPacket(backendConnection)).thenReturn(Optional.of(databasePacket));
-        when(engine.getCommandExecuteEngine()).thenReturn(executeEngine);
+        
when(engine.getCodecEngine().createPacketPayload(message)).thenReturn(payload);
+        when(engine.getCommandExecuteEngine().getErrorPacket(mockException, 
backendConnection)).thenReturn(databasePacket);
+        
when(engine.getCommandExecuteEngine().getOtherPacket(backendConnection)).thenReturn(Optional.of(databasePacket));
         
when(backendConnection.closeConnections(false)).thenReturn(Collections.emptyList());
         
when(backendConnection.closeFederateExecutor()).thenReturn(Collections.emptyList());
         CommandExecutorTask actual = new CommandExecutorTask(engine, 
backendConnection, handlerContext, message);
diff --git 
a/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/test/java/org/apache/shardingsphere/scaling/postgresql/component/PostgreSQLWalDumperTest.java
 
b/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/test/java/org/apache/shardingsphere/scaling/postgresql/component/PostgreSQLWalDumperTest.java
index 6a605e5..8991315 100644
--- 
a/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/test/java/org/apache/shardingsphere/scaling/postgresql/component/PostgreSQLWalDumperTest.java
+++ 
b/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/test/java/org/apache/shardingsphere/scaling/postgresql/component/PostgreSQLWalDumperTest.java
@@ -85,7 +85,6 @@ public final class PostgreSQLWalDumperTest {
             ReflectionUtil.setFieldValue(walDumper, "logicalReplication", 
logicalReplication);
             
when(logicalReplication.createPgConnection(jdbcDataSourceConfig)).thenReturn(pgConnection);
             
when(pgConnection.unwrap(PgConnection.class)).thenReturn(pgConnection);
-            when(pgConnection.getTimestampUtils()).thenReturn(null);
             when(logicalReplication.createReplicationStream(pgConnection, 
PostgreSQLPositionInitializer.SLOT_NAME, 
position.getLogSequenceNumber())).thenReturn(pgReplicationStream);
             ByteBuffer data = ByteBuffer.wrap("table public.test: DELETE: 
data[integer]:1".getBytes());
             
when(pgReplicationStream.readPending()).thenReturn(null).thenReturn(data).thenThrow(new
 SQLException(""));
diff --git 
a/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/test/java/org/apache/shardingsphere/scaling/postgresql/wal/decode/TestDecodingPluginTest.java
 
b/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/test/java/org/apache/shardingsphere/scaling/postgresql/wal/decode/TestDecodingPluginTest.java
index 8179639..f98f8c7 100644
--- 
a/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/test/java/org/apache/shardingsphere/scaling/postgresql/wal/decode/TestDecodingPluginTest.java
+++ 
b/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/test/java/org/apache/shardingsphere/scaling/postgresql/wal/decode/TestDecodingPluginTest.java
@@ -34,13 +34,12 @@ import java.sql.SQLException;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 public final class TestDecodingPluginTest {
     
-    private LogSequenceNumber logSequenceNumber = 
LogSequenceNumber.valueOf("0/14EFDB8");
+    private final LogSequenceNumber logSequenceNumber = 
LogSequenceNumber.valueOf("0/14EFDB8");
     
     @Test
     public void assertDecodeWriteRowEvent() {
@@ -95,7 +94,7 @@ public final class TestDecodingPluginTest {
     @SneakyThrows(SQLException.class)
     public void assertDecodeTime() {
         TimestampUtils timestampUtils = mock(TimestampUtils.class);
-        when(timestampUtils.toTime(eq(null), eq("1 2 3'"))).thenThrow(new 
SQLException(""));
+        when(timestampUtils.toTime(null, "1 2 3'")).thenThrow(new 
SQLException(""));
         ByteBuffer data = ByteBuffer.wrap("table public.test: INSERT: 
data[time without time zone]:'1 2 3'''".getBytes());
         new TestDecodingPlugin(timestampUtils).decode(data, logSequenceNumber);
     }

Reply via email to