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

panjuan 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 893c7fa1491 Remove Mockito Silent from unit tests (#19709)
893c7fa1491 is described below

commit 893c7fa14914da04418ae7515b0ce4c6034271a5
Author: 吴伟杰 <[email protected]>
AuthorDate: Sat Jul 30 16:21:09 2022 +0800

    Remove Mockito Silent from unit tests (#19709)
---
 .../distsql/checker/ShardingRuleStatementCheckerTest.java    |  2 +-
 .../update/AlterShardingTableRuleStatementUpdaterTest.java   |  2 +-
 .../update/CreateShardingTableRuleStatementUpdaterTest.java  |  2 +-
 .../driver/jdbc/core/connection/ConnectionManagerTest.java   | 12 ++++++++----
 .../spring/boot/datasource/DataSourceMapSetterTest.java      |  4 ++--
 .../coordinator/ClusterContextManagerCoordinatorTest.java    |  3 +--
 .../jdbc/connection/JDBCBackendConnectionTest.java           | 12 +++---------
 .../handler/distsql/rql/DataSourceQueryResultSetTest.java    |  2 +-
 .../distsql/rql/UnusedDataSourceQueryResultSetTest.java      |  2 +-
 .../apache/shardingsphere/test/mock/MockedDataSource.java    |  7 -------
 10 files changed, 19 insertions(+), 29 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java
index bc69e025c62..5cfebe12bb3 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java
@@ -58,7 +58,7 @@ import java.util.Properties;
 
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.Silent.class)
+@RunWith(MockitoJUnitRunner.class)
 public final class ShardingRuleStatementCheckerTest {
     
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java
index 3f8998a08fe..86fa72cba62 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java
@@ -54,7 +54,7 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.Silent.class)
+@RunWith(MockitoJUnitRunner.class)
 public final class AlterShardingTableRuleStatementUpdaterTest {
     
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
index 8e13ef19c3e..4846183c728 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
@@ -59,7 +59,7 @@ import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.Silent.class)
+@RunWith(MockitoJUnitRunner.class)
 public final class CreateShardingTableRuleStatementUpdaterTest {
     
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
index 63358105244..04a8d4d0d18 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
@@ -98,10 +98,14 @@ public final class ConnectionManagerTest {
         return result;
     }
     
-    private Map<String, DataSource> mockTrafficDataSourceMap() {
-        Map<String, DataSource> result = new LinkedHashMap<>();
-        result.put("127.0.0.1@3307", new 
MockedDataSource("jdbc:mysql://127.0.0.1:3307/logic_db?serverTimezone=UTC&useSSL=false",
 "root", "123456"));
-        return result;
+    private Map<String, DataSource> mockTrafficDataSourceMap() throws 
SQLException {
+        MockedDataSource result = new MockedDataSource(mock(Connection.class, 
RETURNS_DEEP_STUBS));
+        
result.setUrl("jdbc:mysql://127.0.0.1:3307/logic_db?serverTimezone=UTC&useSSL=false");
+        result.setUsername("root");
+        result.setPassword("123456");
+        
when(result.getConnection().getMetaData().getURL()).thenReturn(result.getUrl());
+        
when(result.getConnection().getMetaData().getUserName()).thenReturn(result.getUsername());
+        return Collections.singletonMap("127.0.0.1@3307", result);
     }
     
     private MetaDataPersistService mockMetaDataPersistService() {
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetterTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetterTest.java
index 659b249dd3b..3f8466a623d 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetterTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetterTest.java
@@ -49,7 +49,7 @@ public final class DataSourceMapSetterTest {
         standardEnvironment.merge(mockEnvironment);
         Map<String, DataSource> dataSourceMap = 
DataSourceMapSetter.getDataSourceMap(standardEnvironment);
         assertThat(dataSourceMap.size(), is(2));
-        
assertThat(dataSourceMap.get("ds0").getConnection().getMetaData().getUserName(),
 is("sa"));
-        
assertThat(dataSourceMap.get("ds1").getConnection().getMetaData().getUserName(),
 is("sa"));
+        
assertThat(dataSourceMap.get("ds0").getConnection().getMetaData().getURL(), 
is("jdbc:mock://127.0.0.1/ds_0"));
+        
assertThat(dataSourceMap.get("ds1").getConnection().getMetaData().getURL(), 
is("jdbc:mock://127.0.0.1/ds_1"));
     }
 }
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
index 4b554c731c2..0e8ea72725a 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
@@ -118,7 +118,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.Silent.class)
+@RunWith(MockitoJUnitRunner.class)
 public final class ClusterContextManagerCoordinatorTest {
     
     private ClusterContextManagerCoordinator coordinator;
@@ -193,7 +193,6 @@ public final class ClusterContextManagerCoordinatorTest {
     
     @Test
     public void assertRenewForSchemaAdded() {
-        
when(contextManager.getMetaDataContexts().getMetaData().getDatabase("db").getSchema("foo_schema")).thenReturn(null);
         coordinator.renew(new SchemaAddedEvent("db", "foo_schema"));
         
verify(contextManager.getMetaDataContexts().getMetaData().getDatabase("db")).putSchema(argThat(argument
 -> argument.equals("foo_schema")), any(ShardingSphereSchema.class));
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java
index b66ca0cbacf..8e704d7c1f8 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java
@@ -34,13 +34,11 @@ import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDB
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.statement.JDBCBackendStatement;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.backend.exception.BackendConnectionException;
+import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import 
org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus;
-import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler;
 import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer;
-import 
org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine;
 import org.apache.shardingsphere.transaction.core.TransactionType;
-import org.apache.shardingsphere.transaction.rule.TransactionRule;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -77,7 +75,7 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.Silent.class)
+@RunWith(MockitoJUnitRunner.class)
 public final class JDBCBackendConnectionTest extends ProxyContextRestorer {
     
     private static final String SCHEMA_PATTERN = "schema_%s";
@@ -123,11 +121,7 @@ public final class JDBCBackendConnectionTest extends 
ProxyContextRestorer {
     }
     
     private ShardingSphereRuleMetaData mockGlobalRuleMetaData() {
-        ShardingSphereRuleMetaData result = 
mock(ShardingSphereRuleMetaData.class);
-        TransactionRule transactionRule = mock(TransactionRule.class);
-        when(transactionRule.getResource()).thenReturn(new 
ShardingSphereTransactionManagerEngine());
-        
when(result.getSingleRule(TransactionRule.class)).thenReturn(transactionRule);
-        return result;
+        return mock(ShardingSphereRuleMetaData.class);
     }
     
     private void setBackendDataSource() throws ReflectiveOperationException {
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/DataSourceQueryResultSetTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/DataSourceQueryResultSetTest.java
index d8a1c3c2bc0..1f0f519a53a 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/DataSourceQueryResultSetTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/DataSourceQueryResultSetTest.java
@@ -38,7 +38,7 @@ import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.Silent.class)
+@RunWith(MockitoJUnitRunner.class)
 public final class DataSourceQueryResultSetTest {
     
     @Mock
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/UnusedDataSourceQueryResultSetTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/UnusedDataSourceQueryResultSetTest.java
index 208f717d1f8..d5bfed2d1b7 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/UnusedDataSourceQueryResultSetTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/UnusedDataSourceQueryResultSetTest.java
@@ -49,7 +49,7 @@ import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.Silent.class)
+@RunWith(MockitoJUnitRunner.class)
 public final class UnusedDataSourceQueryResultSetTest {
     
     @Mock
diff --git 
a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/mock/MockedDataSource.java
 
b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/mock/MockedDataSource.java
index 9347514d085..7bc27e3f2be 100644
--- 
a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/mock/MockedDataSource.java
+++ 
b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/mock/MockedDataSource.java
@@ -66,12 +66,6 @@ public final class MockedDataSource implements DataSource, 
AutoCloseable {
     @Setter(AccessLevel.NONE)
     private boolean closed;
     
-    public MockedDataSource(final String url, final String username, final 
String password) {
-        this.url = url;
-        this.username = username;
-        this.password = password;
-    }
-    
     public MockedDataSource(final Connection connection) {
         this.connection = connection;
     }
@@ -84,7 +78,6 @@ public final class MockedDataSource implements DataSource, 
AutoCloseable {
         }
         Connection result = mock(Connection.class, RETURNS_DEEP_STUBS);
         when(result.getMetaData().getURL()).thenReturn(url);
-        when(result.getMetaData().getUserName()).thenReturn(username);
         when(result.createStatement(anyInt(), anyInt(), 
anyInt()).getConnection()).thenReturn(result);
         return result;
     }

Reply via email to