Beispiel #1
0
  @Test
  public void testSimpleCases() throws Exception {
    Range _r = new Range(0, 10);
    assertEquals(0, _r.getStart());
    assertEquals(9, _r.getEnd());
    assertEquals(10, _r.getBatchSize());
    assertEquals(10, _r.getSize());
    assertEquals(Integer.MAX_VALUE, _r.getTotal());
    assertTrue(_r.hasNext());
    assertFalse(_r.hasPrevious());
    assertEquals("1 to 10 of " + Integer.MAX_VALUE, _r.toString());

    _r = new Range(10, 10);
    assertEquals(10, _r.getStart());
    assertEquals(19, _r.getEnd());
    assertEquals(10, _r.getBatchSize());
    assertEquals(10, _r.getSize());
    assertEquals(Integer.MAX_VALUE, _r.getTotal());
    assertTrue(_r.hasNext());
    assertTrue(_r.hasPrevious());
    assertEquals("11 to 20 of " + Integer.MAX_VALUE, _r.toString());

    _r = new Range(0, 10, 34);
    assertEquals(0, _r.getStart());
    assertEquals(9, _r.getEnd());
    assertEquals(10, _r.getBatchSize());
    assertEquals(10, _r.getSize());
    assertEquals(34, _r.getTotal());
    assertTrue(_r.hasNext());
    assertFalse(_r.hasPrevious());
    assertEquals("1 to 10 of 34", _r.toString());

    _r = new Range(10, 10, 34);
    assertEquals(10, _r.getStart());
    assertEquals(19, _r.getEnd());
    assertEquals(10, _r.getBatchSize());
    assertEquals(10, _r.getSize());
    assertEquals(34, _r.getTotal());
    assertTrue(_r.hasNext());
    assertTrue(_r.hasPrevious());
    assertEquals("11 to 20 of 34", _r.toString());

    _r = new Range(10, 10, 16);
    assertEquals(10, _r.getStart());
    assertEquals(16, _r.getEnd());
    assertEquals(10, _r.getBatchSize());
    assertEquals(6, _r.getSize());
    assertEquals(16, _r.getTotal());
    assertFalse(_r.hasNext());
    assertTrue(_r.hasPrevious());
    assertEquals("11 to 16 of 16", _r.toString());
  }
Beispiel #2
0
  @Test
  public void testAlwaysMakesAValidRange() throws Exception {
    Range _r = new Range(-20, -6);
    assertEquals(0, _r.getStart());
    assertEquals(0, _r.getEnd());
    assertEquals(1, _r.getBatchSize());
    assertEquals(0, _r.getSize());
    assertTrue(_r.hasNext());
    assertFalse(_r.hasPrevious());
    assertEquals(_r, _r.previous());

    _r = new Range(-3, -3, -3);
    assertEquals(0, _r.getStart());
    assertEquals(0, _r.getEnd());
    assertEquals(1, _r.getBatchSize());
    assertEquals(0, _r.getSize());
    assertFalse(_r.hasNext());
    assertFalse(_r.hasPrevious());
    assertEquals(_r, _r.next());
    assertEquals(_r, _r.previous());
  }