Search in sources :

Example 26 with Returns

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;
}
Also used : TableKeyMetaData(nl.topicus.jdbc.MetaDataStore.TableKeyMetaData) Returns(org.mockito.internal.stubbing.answers.Returns) CloudSpannerDatabaseMetaData(nl.topicus.jdbc.CloudSpannerDatabaseMetaData) CloudSpannerResultSet(nl.topicus.jdbc.resultset.CloudSpannerResultSet) ResultSet(java.sql.ResultSet) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) CloudSpannerTransaction(nl.topicus.jdbc.transaction.CloudSpannerTransaction) Logger(nl.topicus.jdbc.Logger)

Example 27 with Returns

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);
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) DatabaseClient(com.google.cloud.spanner.DatabaseClient)

Aggregations

Returns (org.mockito.internal.stubbing.answers.Returns)27 Test (org.junit.Test)12 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8 Invocation (org.mockito.invocation.Invocation)6 Before (org.junit.Before)5 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)5 Context (android.content.Context)4 CloudSpannerConnection (nl.topicus.jdbc.CloudSpannerConnection)4 CloudSpannerResultSet (nl.topicus.jdbc.resultset.CloudSpannerResultSet)4 MockSettingsImpl (org.mockito.internal.creation.MockSettingsImpl)4 Answer (org.mockito.stubbing.Answer)4 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)4 InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)3 SuppressLint (android.annotation.SuppressLint)2 AlertDialog (android.app.AlertDialog)2 ContentValues (android.content.ContentValues)2 PackageInfo (android.content.pm.PackageInfo)2 Cursor (android.database.Cursor)2 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)2 Handler (android.os.Handler)2