use of org.mockito.internal.stubbing.answers.Returns in project spanner-jdbc by olavloite.
the class CloudSpannerTestObjects method createConnection.
public static CloudSpannerConnection createConnection() throws SQLException {
CloudSpannerConnection connection = Mockito.mock(CloudSpannerConnection.class);
Mockito.doCallRealMethod().when(connection).setAutoCommit(Mockito.anyBoolean());
Mockito.when(connection.getAutoCommit()).thenCallRealMethod();
connection.setAutoCommit(false);
Mockito.when(connection.isAllowExtendedMode()).thenAnswer(new Returns(true));
Mockito.when(connection.createArrayOf(Mockito.anyString(), Mockito.any())).thenCallRealMethod();
CloudSpannerDatabaseMetaData metadata = createMetaData();
Mockito.when(connection.getMetaData()).thenReturn(metadata);
CloudSpannerTransaction transaction = Mockito.mock(CloudSpannerTransaction.class);
Mockito.when(transaction.executeQuery(Mockito.any())).thenReturn(Mockito.mock(com.google.cloud.spanner.ResultSet.class));
Mockito.when(connection.getTransaction()).thenReturn(transaction);
TableKeyMetaData tableFoo = Mockito.mock(TableKeyMetaData.class);
Mockito.when(tableFoo.getKeyColumns()).thenAnswer(new Returns(Arrays.asList("ID")));
Mockito.when(connection.getTable(Mockito.matches(Pattern.compile("FOO", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)))).thenAnswer(new Returns(tableFoo));
TableKeyMetaData tableBar = Mockito.mock(TableKeyMetaData.class);
Mockito.when(tableBar.getKeyColumns()).thenAnswer(new Returns(Arrays.asList("ID1", "ID2")));
Mockito.when(connection.getTable(Mockito.matches(Pattern.compile("BAR", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)))).thenAnswer(new Returns(tableBar));
Mockito.when(connection.getLogger()).thenAnswer(new Returns(new Logger()));
mockXAMethods(connection);
return connection;
}
use of org.mockito.internal.stubbing.answers.Returns in project spanner-jdbc by olavloite.
the class TransactionThreadTest method createTestSubject.
private TestSubject createTestSubject() {
MockTransactionRunner runner = new MockTransactionRunner();
DatabaseClient dbClient = mock(DatabaseClient.class);
when(dbClient.readWriteTransaction()).then(new Returns(runner));
return new TestSubject(new TransactionThread(dbClient), runner.mock);
}
Aggregations