Skip to content

Commit

Permalink
apache#1238 Add Mock object for BackendConnectionTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
cherrylzhao authored and maxiaoguang64 committed Nov 25, 2018
1 parent 7967d80 commit f67d676
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection> 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() {

Expand Down

0 comments on commit f67d676

Please sign in to comment.