From f67d676a880f68c406021639a4f5bdf6bd8c3a98 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Sat, 17 Nov 2018 10:15:37 +0800 Subject: [PATCH] #1238 Add Mock object for BackendConnectionTest. --- .../connection/BackendConnectionTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/sharding-proxy/src/test/java/io/shardingsphere/shardingproxy/backend/jdbc/connection/BackendConnectionTest.java b/sharding-proxy/src/test/java/io/shardingsphere/shardingproxy/backend/jdbc/connection/BackendConnectionTest.java index 9fc4cda6efb4d6..6683e04bb8719c 100644 --- a/sharding-proxy/src/test/java/io/shardingsphere/shardingproxy/backend/jdbc/connection/BackendConnectionTest.java +++ b/sharding-proxy/src/test/java/io/shardingsphere/shardingproxy/backend/jdbc/connection/BackendConnectionTest.java @@ -17,10 +17,43 @@ package io.shardingsphere.shardingproxy.backend.jdbc.connection; +import io.shardingsphere.core.constant.ConnectionMode; +import io.shardingsphere.shardingproxy.backend.jdbc.datasource.JDBCBackendDataSource; +import io.shardingsphere.shardingproxy.runtime.schema.LogicSchema; +import lombok.SneakyThrows; +import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import java.sql.Connection; +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) public class BackendConnectionTest { + @Mock + private LogicSchema logicSchema; + + private BackendConnection backendConnection = new BackendConnection(); + + @Before + @SuppressWarnings("unchecked") + @SneakyThrows + public void setup() { + List newConnection = mock(List.class); + JDBCBackendDataSource backendDataSource = mock(JDBCBackendDataSource.class); + when(backendDataSource.getConnections((ConnectionMode) any(), anyString(), anyInt())).thenReturn(newConnection); + when(logicSchema.getBackendDataSource()).thenReturn(backendDataSource); + } + @Test public void assertGetConnectionCacheIsEmpty() {