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

chengzhang 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 5a2c32c8249 Remove useless mock(AuthorityRule.class) on test cases 
(#31810)
5a2c32c8249 is described below

commit 5a2c32c824979f32c74332a4df8c6514c2bd7ee5
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Jun 21 20:36:17 2024 +0800

    Remove useless mock(AuthorityRule.class) on test cases (#31810)
    
    * Refactor OKDriverStateTest
    
    * Remove useless mock(AuthorityRule.class) on test cases
---
 .../shardingsphere/driver/jdbc/adapter/ConnectionAdapterTest.java   | 6 ++----
 .../driver/jdbc/core/connection/ShardingSphereConnectionTest.java   | 4 +---
 .../driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java | 6 ++----
 .../apache/shardingsphere/driver/state/DriverStateContextTest.java  | 5 +----
 .../apache/shardingsphere/driver/state/ok/OKDriverStateTest.java    | 6 ++----
 5 files changed, 8 insertions(+), 19 deletions(-)

diff --git 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ConnectionAdapterTest.java
 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ConnectionAdapterTest.java
index 36af79292a6..2b80d4b212b 100644
--- 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ConnectionAdapterTest.java
+++ 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ConnectionAdapterTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.driver.jdbc.adapter;
 
-import org.apache.shardingsphere.authority.rule.AuthorityRule;
 import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
 import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
 import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
@@ -28,7 +27,7 @@ import org.junit.jupiter.api.Test;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.util.Arrays;
+import java.util.Collections;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -97,8 +96,7 @@ class ConnectionAdapterTest {
     
     private Connection createConnectionAdaptor() {
         ContextManager contextManager = mock(ContextManager.class, 
RETURNS_DEEP_STUBS);
-        
when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(
-                new RuleMetaData(Arrays.asList(mock(TransactionRule.class, 
RETURNS_DEEP_STUBS), mock(AuthorityRule.class))));
+        
when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new
 RuleMetaData(Collections.singleton(mock(TransactionRule.class, 
RETURNS_DEEP_STUBS))));
         return new ShardingSphereConnection(DefaultDatabase.LOGIC_NAME, 
contextManager);
     }
 }
diff --git 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
index e23c7870cf5..6adf01dbdbf 100644
--- 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
+++ 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
@@ -18,7 +18,6 @@
 package org.apache.shardingsphere.driver.jdbc.core.connection;
 
 import lombok.SneakyThrows;
-import org.apache.shardingsphere.authority.rule.AuthorityRule;
 import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
@@ -37,7 +36,6 @@ import org.mockito.internal.configuration.plugins.Plugins;
 import javax.sql.DataSource;
 import java.sql.Connection;
 import java.sql.SQLException;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.Properties;
 
@@ -206,7 +204,7 @@ class ShardingSphereConnectionTest {
         StorageUnit storageUnit = mock(StorageUnit.class);
         when(storageUnit.getDataSource()).thenReturn(dataSource);
         
when(result.getStorageUnits(DefaultDatabase.LOGIC_NAME)).thenReturn(Collections.singletonMap("ds",
 storageUnit));
-        
when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new
 RuleMetaData(Arrays.asList(mockTransactionRule(), mock(AuthorityRule.class))));
+        
when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new
 RuleMetaData(Collections.singleton(mockTransactionRule())));
         return result;
     }
     
diff --git 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java
 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java
index dfdc934f280..3ca5d91ed07 100644
--- 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java
+++ 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.driver.jdbc.unsupported;
 
-import org.apache.shardingsphere.authority.rule.AuthorityRule;
 import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
 import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
 import 
org.apache.shardingsphere.infra.exception.generic.UnsupportedSQLOperationException;
@@ -29,7 +28,7 @@ import org.junit.jupiter.api.Test;
 
 import java.sql.ResultSet;
 import java.sql.SQLFeatureNotSupportedException;
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.Properties;
 
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -44,8 +43,7 @@ class UnsupportedOperationConnectionTest {
     @BeforeEach
     void setUp() {
         ContextManager contextManager = mock(ContextManager.class, 
RETURNS_DEEP_STUBS);
-        
when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(
-                new RuleMetaData(Arrays.asList(mock(AuthorityRule.class), 
mock(TransactionRule.class, RETURNS_DEEP_STUBS))));
+        
when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new
 RuleMetaData(Collections.singleton(mock(TransactionRule.class, 
RETURNS_DEEP_STUBS))));
         shardingSphereConnection = new 
ShardingSphereConnection(DefaultDatabase.LOGIC_NAME, contextManager);
     }
     
diff --git 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java
 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java
index bdaff49bdf0..e17a4b25546 100644
--- 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java
+++ 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.driver.state;
 
-import org.apache.shardingsphere.authority.rule.AuthorityRule;
 import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
@@ -41,7 +40,6 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 
 import java.sql.Connection;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Properties;
@@ -61,8 +59,7 @@ class DriverStateContextTest {
     void setUp() {
         Map<String, ShardingSphereDatabase> databases = mockDatabases();
         TransactionRule transactionRule = mock(TransactionRule.class);
-        AuthorityRule authorityRule = mock(AuthorityRule.class);
-        RuleMetaData globalRuleMetaData = new 
RuleMetaData(Arrays.asList(transactionRule, authorityRule));
+        RuleMetaData globalRuleMetaData = new 
RuleMetaData(Collections.singleton(transactionRule));
         MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(
                 mock(MetaDataPersistService.class), new 
ShardingSphereMetaData(databases, mock(ResourceMetaData.class), 
globalRuleMetaData, new ConfigurationProperties(new Properties())));
         
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
diff --git 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/ok/OKDriverStateTest.java
 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/ok/OKDriverStateTest.java
index 80332b31029..c218c34a80e 100644
--- 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/ok/OKDriverStateTest.java
+++ 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/ok/OKDriverStateTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.driver.state.ok;
 
-import org.apache.shardingsphere.authority.rule.AuthorityRule;
 import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
 import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
 import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
@@ -26,7 +25,7 @@ import 
org.apache.shardingsphere.transaction.rule.TransactionRule;
 import org.junit.jupiter.api.Test;
 
 import java.sql.Connection;
-import java.util.Arrays;
+import java.util.Collections;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -39,8 +38,7 @@ class OKDriverStateTest {
     @Test
     void assertGetConnection() {
         ContextManager contextManager = mock(ContextManager.class, 
RETURNS_DEEP_STUBS);
-        
when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(
-                new RuleMetaData(Arrays.asList(mock(TransactionRule.class, 
RETURNS_DEEP_STUBS), mock(AuthorityRule.class))));
+        
when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new
 RuleMetaData(Collections.singleton(mock(TransactionRule.class, 
RETURNS_DEEP_STUBS))));
         Connection actual = new 
OKDriverState().getConnection(DefaultDatabase.LOGIC_NAME, contextManager);
         assertThat(actual, instanceOf(ShardingSphereConnection.class));
     }

Reply via email to