PaginatedApi { public <Q> Q execute(final Function<T, Q> function) { return this.execute(function, true); } PaginatedApi(final Class<T> api, final String url, final Supplier<ZonkyApiToken> token,
            final ResteasyClient client);  PaginatedApi(final Class<T> api, final String url, final Supplier<ZonkyApiToken> token,
            final ResteasyClient client, final RequestCounter counter); void setSortString(final String sortString); Q execute(final Function<T, Q> function); Q execute(final Function<T, Q> function, final boolean trackRequests); PaginatedResult<S> execute(final Function<T, List<S>> function, final Select select, final int pageNo,
            final int pageSize);  }
@Test void checkFilter() { final Function<T, BigDecimal> f = o -> BigDecimal.ONE; final Select sel = mock(Select.class); final RoboZonkyFilter filter = new RoboZonkyFilter(); final PaginatedApi<BigDecimal, T> p = spy(new PaginatedApi<>(null, null, null, null)); doReturn(BigDecimal.ONE).when(p) .execute(eq(f), eq(filter), anyBoolean()); assertThat(p.execute(f, sel, filter)).isEqualTo(BigDecimal.ONE); verify(sel).accept(filter); verify(p).execute(eq(f), any(RoboZonkyFilter.class), eq(true)); }
@Test void checkSimple() { final Function<T, S> f = o -> null; final PaginatedApi<S, T> p = spy(new PaginatedApi<>(null, null, null, null)); doReturn(null).when(p) .execute(eq(f), any(), anyBoolean()); p.execute(f); verify(p).execute(eq(f), isNotNull(), eq(true)); }
@Test void checkPagination() { final PaginatedApi<S, T> p = spy(new PaginatedApi<>(null, null, null, mock(ResteasyClient.class))); doReturn(null).when(p) .execute(any(), any(), any()); final Function<T, List<S>> f = o -> Collections.emptyList(); final Select sel = mock(Select.class); final int total = 1000; final RoboZonkyFilter filter = mock(RoboZonkyFilter.class); when(filter.getLastResponseHeader(eq("X-Total"))) .thenReturn(Optional.of("" + total)); final PaginatedResult<S> result = p.execute(f, sel, 1, 10, filter); assertThat(result.getTotalResultCount()).isEqualTo(total); verify(filter, never()).setRequestHeader(eq("X-Order"), any()); verify(filter).setRequestHeader(eq("X-Size"), eq("10")); verify(filter).setRequestHeader(eq("X-Page"), eq("1")); verify(p).execute(eq(f), eq(sel), eq(filter)); }