gax-java
gax-java copied to clipboard
PagedResponses are extremely difficult to mock
Feature request: provide some kind of helper that can be used to mock a PagedListResponse.
As it stands it's next to impossible for end users to write unit tests that mock methods that are paginated. Ideally gax would provide a helper to construct an instance of PagedListResponse using an in memory list. Something along the lines of:
BigtableTableAdminStub mockStub = Mockito.mock(BigtableTableAdminStub.class, RETURNS_DEEP_STUBS);
Mockito.when(stub.listTablesPagedCallable().futureCall(expectedRequest, Mockito.any())
.thenReturn(
PaginationHelper.create(ListTablesPagedResponse.class)
.addPage(table1, table2)
.addPage(table3)
.build()
)
BigtableTableClient client = BigtableTableClient.create(mockStub);
assertThat(client.listTables(expectedRequest).iterateAll()).containsAll(table1, table2);
@sduskis do you want to reprioritize?
@andreamlin, the Yoshi team asks that only bugs get priority labels.
Closing. Please re-open if it's still a needed feature.