You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/07/29 05:32:17 UTC

[shardingsphere] branch master updated: Use read Collection to instead of mock (#11567)

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

wuweijie 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 5cfb766  Use read Collection to instead of mock (#11567)
5cfb766 is described below

commit 5cfb7660e64e1b85c2792c5cab479fc2587a6d28
Author: Liang Zhang <te...@163.com>
AuthorDate: Thu Jul 29 13:31:45 2021 +0800

    Use read Collection to instead of mock (#11567)
---
 .../driver/jdbc/adapter/WrapperAdapterTest.java           |  6 +-----
 .../command/PostgreSQLCommandExecutorFactoryTest.java     | 15 +++++++++------
 .../transaction/ShardingTransactionManagerEngineTest.java |  7 +++----
 3 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/WrapperAdapterTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/WrapperAdapterTest.java
index b0cf10b..ecaefdd 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/WrapperAdapterTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/WrapperAdapterTest.java
@@ -35,8 +35,6 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 public final class WrapperAdapterTest {
     
@@ -69,10 +67,8 @@ public final class WrapperAdapterTest {
     
     @Test
     public void assertRecordMethodInvocationSuccess() {
-        List<?> list = mock(List.class);
-        when(list.isEmpty()).thenReturn(true);
         shardingSphereDataSource.recordMethodInvocation(List.class, "isEmpty", new Class[]{}, new Object[]{});
-        shardingSphereDataSource.replayMethodsInvocation(list);
+        shardingSphereDataSource.replayMethodsInvocation(Collections.emptyList());
     }
     
     @Test(expected = NoSuchMethodException.class)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactoryTest.java
index f79eaaa..5d233a8 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactoryTest.java
@@ -48,12 +48,13 @@ import java.sql.SQLException;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
-import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -75,14 +76,16 @@ public final class PostgreSQLCommandExecutorFactoryTest {
     @Test
     public void assertPendingCommandExecutors() throws SQLException {
         PostgreSQLConnectionContext connectionContext = mock(PostgreSQLConnectionContext.class);
-        Collection<CommandExecutor> pendingCommandExecutors = mock(Collection.class);
+        Collection<CommandExecutor> pendingCommandExecutors = new LinkedList<>();
         when(connectionContext.getPendingExecutors()).thenReturn(pendingCommandExecutors);
         PostgreSQLCommandExecutorFactory.newInstance(PostgreSQLCommandPacketType.CLOSE_COMMAND, mock(PostgreSQLComClosePacket.class), backendConnection, connectionContext);
         PostgreSQLCommandExecutorFactory.newInstance(PostgreSQLCommandPacketType.BIND_COMMAND, mock(PostgreSQLComBindPacket.class), backendConnection, connectionContext);
         PostgreSQLCommandExecutorFactory.newInstance(PostgreSQLCommandPacketType.DESCRIBE_COMMAND, null, backendConnection, connectionContext);
-        verify(pendingCommandExecutors).add(any(PostgreSQLComCloseExecutor.class));
-        verify(pendingCommandExecutors).add(any(PostgreSQLComBindExecutor.class));
-        verify(pendingCommandExecutors).add(any(PostgreSQLComDescribeExecutor.class));
+        assertThat(pendingCommandExecutors.size(), is(3));
+        Iterator<CommandExecutor> commandExecutorIterator = pendingCommandExecutors.iterator();
+        assertThat(commandExecutorIterator.next(), instanceOf(PostgreSQLComCloseExecutor.class));
+        assertThat(commandExecutorIterator.next(), instanceOf(PostgreSQLComBindExecutor.class));
+        assertThat(commandExecutorIterator.next(), instanceOf(PostgreSQLComDescribeExecutor.class));
     }
     
     @Test
diff --git a/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/ShardingTransactionManagerEngineTest.java b/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/ShardingTransactionManagerEngineTest.java
index beaa8c9..76560f5 100644
--- a/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/ShardingTransactionManagerEngineTest.java
+++ b/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/ShardingTransactionManagerEngineTest.java
@@ -18,12 +18,12 @@
 package org.apache.shardingsphere.transaction;
 
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
-import org.apache.shardingsphere.transaction.core.XATransactionManagerType;
 import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.apache.shardingsphere.transaction.core.XATransactionManagerType;
 import org.apache.shardingsphere.transaction.core.fixture.ShardingTransactionManagerFixture;
 import org.junit.Test;
 
-import java.util.Map;
+import java.util.Collections;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.junit.Assert.assertThat;
@@ -39,13 +39,12 @@ public final class ShardingTransactionManagerEngineTest {
         assertThat(shardingTransactionManagerEngine.getTransactionManager(TransactionType.XA), instanceOf(ShardingTransactionManagerFixture.class));
     }
     
-    @SuppressWarnings("unchecked")
     @Test
     public void assertRegisterTransactionResource() {
         Runnable caller = mock(Runnable.class);
         ShardingTransactionManagerFixture shardingTransactionManager = (ShardingTransactionManagerFixture) shardingTransactionManagerEngine.getTransactionManager(TransactionType.XA);
         shardingTransactionManager.setCaller(caller);
-        shardingTransactionManagerEngine.init(DatabaseTypeRegistry.getActualDatabaseType("H2"), mock(Map.class), XATransactionManagerType.ATOMIKOS.getType());
+        shardingTransactionManagerEngine.init(DatabaseTypeRegistry.getActualDatabaseType("H2"), Collections.emptyMap(), XATransactionManagerType.ATOMIKOS.getType());
         verify(caller).run();
     }
 }