Skip to content

Commit e44aaad

Browse files
Fixing unnecessary mock errors which appear only on IDE runs (#2965)
1 parent be5e9dc commit e44aaad

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

v2/sourcedb-to-spanner/src/test/java/com/google/cloud/teleport/v2/source/reader/io/jdbc/iowrapper/JdbcIoWrapperTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.Assert.assertTrue;
2222
import static org.mockito.ArgumentMatchers.any;
2323
import static org.mockito.Mockito.doNothing;
24+
import static org.mockito.Mockito.lenient;
2425
import static org.mockito.Mockito.times;
2526
import static org.mockito.Mockito.verify;
2627
import static org.mockito.Mockito.when;
@@ -204,7 +205,8 @@ public void testJdbcIoWrapperNoPrimaryKeyExistsOnTable()
204205
.setIsUnique(true)
205206
.setOrdinalPosition(2)
206207
.build())));
207-
when(mockDialectAdapter.discoverTableSchema(any(), (SourceSchemaReference) any(), any()))
208+
lenient()
209+
.when(mockDialectAdapter.discoverTableSchema(any(), (SourceSchemaReference) any(), any()))
208210
.thenReturn(ImmutableMap.of("testTable", ImmutableMap.of(testCol, testColType)));
209211

210212
assertThrows(
@@ -298,7 +300,8 @@ public void testJdbcIoWrapperDifferentTables() throws RetriableSchemaDiscoveryEx
298300
SourceColumnType testColType = new SourceColumnType("INTEGER", new Long[] {}, null);
299301
when(mockDialectAdapter.discoverTables(any(), (SourceSchemaReference) any()))
300302
.thenReturn(ImmutableList.of("testTable"));
301-
when(mockDialectAdapter.discoverTableIndexes(any(), (SourceSchemaReference) any(), any()))
303+
lenient()
304+
.when(mockDialectAdapter.discoverTableIndexes(any(), (SourceSchemaReference) any(), any()))
302305
.thenReturn(
303306
ImmutableMap.of(
304307
"testTable",
@@ -312,7 +315,8 @@ public void testJdbcIoWrapperDifferentTables() throws RetriableSchemaDiscoveryEx
312315
.setIsUnique(true)
313316
.setOrdinalPosition(1)
314317
.build())));
315-
when(mockDialectAdapter.discoverTableSchema(any(), (SourceSchemaReference) any(), any()))
318+
lenient()
319+
.when(mockDialectAdapter.discoverTableSchema(any(), (SourceSchemaReference) any(), any()))
316320
.thenReturn(ImmutableMap.of("testTable", ImmutableMap.of(testCol, testColType)));
317321
JdbcIoWrapper jdbcIoWrapper =
318322
JdbcIoWrapper.of(

v2/sourcedb-to-spanner/src/test/java/com/google/cloud/teleport/v2/source/reader/io/jdbc/uniformsplitter/range/BoundaryExtractorFactoryTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,8 @@ public void testFromTimestampsEmptyTable() throws SQLException {
268268
PartitionColumn.builder().setColumnName("col1").setColumnClass(Timestamp.class).build();
269269
BoundaryExtractor<Timestamp> extractor = BoundaryExtractorFactory.create(Timestamp.class);
270270
when(mockResultSet.next()).thenReturn(true);
271-
when(mockResultSet.getBigDecimal(1)).thenReturn(null);
272-
// BigInt Unsigned Max in MySQL
273-
when(mockResultSet.getBigDecimal(2)).thenReturn(null);
271+
when(mockResultSet.getTimestamp(eq(1), any())).thenReturn(null);
272+
when(mockResultSet.getTimestamp(eq(2), any())).thenReturn(null);
274273
Boundary<Timestamp> boundary = extractor.getBoundary(partitionColumn, mockResultSet, null);
275274

276275
assertThat(boundary.start()).isNull();

v2/sourcedb-to-spanner/src/test/java/com/google/cloud/teleport/v2/source/reader/io/schema/SchemaDiscoveryImplTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public class SchemaDiscoveryImplTest {
5454
public void testSchemaDiscoveryImpl() throws RetriableSchemaDiscoveryException {
5555
final int testRetryCount = 2;
5656
final int expectedCallsCount = testRetryCount + 1;
57-
when(mockDataSource.jdbc()).thenReturn(mockJdbcDataSource);
5857
when(mockRetriableSchemaDiscovery.discoverTableSchema(
5958
mockDataSource, mockSourceSchemaReference, ImmutableList.of()))
6059
.thenThrow(new RetriableSchemaDiscoveryException(new SQLTransientConnectionException()))
@@ -82,7 +81,6 @@ public void testSchemaDiscoveryImplThrowsRetriesExhausted()
8281

8382
when(mockFluentBackoff.backoff()).thenReturn(mockBackoff);
8483
when(mockBackoff.nextBackOffMillis()).thenThrow(new RuntimeException("test"));
85-
when(mockDataSource.jdbc()).thenReturn(mockJdbcDataSource);
8684
when(mockRetriableSchemaDiscovery.discoverTableSchema(
8785
mockDataSource, mockSourceSchemaReference, ImmutableList.of()))
8886
.thenThrow(new RetriableSchemaDiscoveryException(new SQLTransientConnectionException()));
@@ -103,7 +101,6 @@ public void testSchemaDiscoveryImplHandlesIOException()
103101

104102
final int testRetryCount = 2;
105103
final int expectedCallsCount = testRetryCount + 1;
106-
when(mockDataSource.jdbc()).thenReturn(mockJdbcDataSource);
107104
when(mockRetriableSchemaDiscovery.discoverTableSchema(
108105
mockDataSource, mockSourceSchemaReference, ImmutableList.of()))
109106
.thenThrow(new RetriableSchemaDiscoveryException(new SQLTransientConnectionException()));
@@ -128,7 +125,6 @@ public void testTableDiscoveryImpl() throws RetriableSchemaDiscoveryException {
128125
final int testRetryCount = 2;
129126
final int expectedCallsCount = testRetryCount + 1;
130127
final ImmutableList<String> testTables = ImmutableList.of("testTable1", "testTable2");
131-
when(mockDataSource.jdbc()).thenReturn(mockJdbcDataSource);
132128
when(mockRetriableSchemaDiscovery.discoverTables(mockDataSource, mockSourceSchemaReference))
133129
.thenThrow(new RetriableSchemaDiscoveryException(new SQLTransientConnectionException()))
134130
.thenThrow(new RetriableSchemaDiscoveryException(new SQLTransientConnectionException()))
@@ -162,7 +158,7 @@ public void testIndexDiscoveryImpl() throws RetriableSchemaDiscoveryException {
162158
.setOrdinalPosition(1)
163159
.setIndexType(IndexType.NUMERIC)
164160
.build()));
165-
when(mockDataSource.jdbc()).thenReturn(mockJdbcDataSource);
161+
166162
when(mockRetriableSchemaDiscovery.discoverTableIndexes(
167163
mockDataSource, mockSourceSchemaReference, ImmutableList.of("testTable1")))
168164
.thenThrow(new RetriableSchemaDiscoveryException(new SQLTransientConnectionException()))

0 commit comments

Comments
 (0)