package nl.topicus.jdbc;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.sql.SQLException;

import org.mockito.Mockito;
import org.mockito.internal.stubbing.answers.Returns;

public class MockCloudSpannerConnection
{

	public static CloudSpannerConnection create(String url) throws SQLException
	{
		ConnectionProperties properties = ConnectionProperties.parse(url);
		CloudSpannerConnection connection = mock(CloudSpannerConnection.class);
		when(connection.getSimulateMajorVersion()).then(new Returns(null));
		when(connection.getSimulateMinorVersion()).then(new Returns(null));
		when(connection.getUrl()).thenAnswer(new Returns(url));
		when(connection.getProductName()).thenAnswer(new Returns(properties.productName));
		when(connection.getNodeCount()).thenAnswer(new Returns(1));
		return connection;
	}

	public static AbstractCloudSpannerConnection createAbstractConnection()
	{
		AbstractCloudSpannerConnection connection = Mockito.spy(AbstractCloudSpannerConnection.class);
		return connection;
	}

}

@@ -59,53 +59,157 @@
 ito.
-mock;%0D%0Aimport static org.mockito.Mockito.when
+CALLS_REAL_METHODS;%0D%0Aimport static org.mockito.Mockito.mock;%0D%0Aimport static org.mockito.Mockito.when;%0D%0Aimport static org.mockito.Mockito.withSettings
 ;%0D%0A%0D
@@ -246,37 +246,8 @@
 %0D%0A%0D%0A
-import org.mockito.Mockito;%0D%0A
 impo
@@ -1034,63 +1034,19 @@
 %0D%0A%09%09
-AbstractCloudSpannerConnection connection = Mockito.spy
+return mock
 (Abs
@@ -1078,39 +1078,89 @@
 on.class
-);
+,
 %0D%0A%09%09
-return connection
+%09%09withSettings().useConstructor().defaultAnswer(CALLS_REAL_METHODS))
 ;%0D%0A%09%7D%0D%0A%0D

use preferred method for creating spy object