Esempio n. 1
0
  @Test
  public void shouldInitializePaginationOptionWithOffset0ForFirstPage() {
    Map<String, String> parameters = new HashMap<>();
    Paginator paginator = new Paginator(parameters, scheme, parser);

    when(scheme.nextPage(eq(parameters), any(Page.class))).thenReturn("testresponse");
    when(parser.parse("testresponse"))
        .thenReturn(new PaginatedResponse(null, new PaginatedResponseMeta(null, null, null, 0)));
    paginator.nextPage();

    ArgumentCaptor<Page> optionCaptor = ArgumentCaptor.forClass(Page.class);
    verify(scheme).nextPage(eq(parameters), optionCaptor.capture());
    Page paginationOption = optionCaptor.getValue();
    assertEquals(100, paginationOption.getLimit());
    assertEquals(0, paginationOption.getOffset());
  }
Esempio n. 2
0
  @Test
  public void shouldReturnNullIfNoPage() {
    Map<String, String> parameters = new HashMap<>();
    Paginator paginator = new Paginator(parameters, scheme, parser);
    PaginatedResponse paginatedResult =
        new PaginatedResponse(
            new JsonArray(),
            new PaginatedResponseMeta(new Page(100, 10), null, new Page(90, 10), 10));
    when(parser.parse(anyString())).thenReturn(paginatedResult);

    paginator.nextPage();
    PaginatedResponse lastPage = paginator.nextPage();

    ArgumentCaptor<Page> optionCaptor = ArgumentCaptor.forClass(Page.class);
    verify(scheme, times(1)).nextPage(eq(parameters), optionCaptor.capture());
    Page paginationOption = optionCaptor.getValue();
    assertEquals(100, paginationOption.getLimit());
    assertEquals(0, paginationOption.getOffset());

    assertNull(lastPage);
  }
Esempio n. 3
0
  @Test
  public void shouldFetchNextPage() {
    Map<String, String> parameters = new HashMap<>();
    Paginator paginator = new Paginator(parameters, scheme, parser);
    PaginatedResponse paginatedResult =
        new PaginatedResponse(
            new JsonArray(), new PaginatedResponseMeta(null, new Page(100, 100), null, 0));
    when(parser.parse(anyString())).thenReturn(paginatedResult);

    paginator.nextPage();
    paginator.nextPage();

    ArgumentCaptor<Page> optionCaptor = ArgumentCaptor.forClass(Page.class);
    verify(scheme, times(2)).nextPage(eq(parameters), optionCaptor.capture());
    List<Page> allValues = optionCaptor.getAllValues();
    assertEquals(2, allValues.size());
    assertEquals(100, allValues.get(0).getLimit());
    assertEquals(0, allValues.get(0).getOffset());

    assertEquals(100, allValues.get(1).getLimit());
    assertEquals(100, allValues.get(1).getOffset());
  }
Esempio n. 4
0
  @Test
  public void shouldOverrideDefaultLimitAndOffsetIfProvidedInParams() {

    Map<String, String> parameters =
        new HashMap<String, String>() {
          {
            put(Constants.OFFSET, "2000");
            put(Constants.LIMIT, "1000");
          }
        };
    Paginator paginator = new Paginator(parameters, scheme, parser);
    when(scheme.nextPage(eq(parameters), any(Page.class))).thenReturn("testresponse");
    when(parser.parse("testresponse"))
        .thenReturn(new PaginatedResponse(null, new PaginatedResponseMeta(null, null, null, 0)));
    paginator.nextPage();

    paginator.nextPage();
    ArgumentCaptor<Page> optionCaptor = ArgumentCaptor.forClass(Page.class);
    verify(scheme).nextPage(eq(parameters), optionCaptor.capture());

    assertEquals(2000, optionCaptor.getValue().getOffset());
    assertEquals(1000, optionCaptor.getValue().getLimit());
  }