gax-java icon indicating copy to clipboard operation
gax-java copied to clipboard

PagedResponses are extremely difficult to mock

Open igorbernstein2 opened this issue 7 years ago • 2 comments

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);

igorbernstein2 avatar Oct 05 '18 00:10 igorbernstein2

@sduskis do you want to reprioritize?

andreamlin avatar Jan 02 '19 22:01 andreamlin

@andreamlin, the Yoshi team asks that only bugs get priority labels.

sduskis avatar Apr 11 '19 15:04 sduskis

Closing. Please re-open if it's still a needed feature.

meltsufin avatar Sep 28 '22 18:09 meltsufin