ResponsePagingUtils { public static int calculatePreviousStartIndex( int startIndex, int count ) { int previousStartIndex = startIndex - count; if ( previousStartIndex < 0 && startIndex > 0 ) return 0; if ( previousStartIndex >= 0 ) { return previousStartIndex; } return -1; } private  ResponsePagingUtils(); static int calculateNextStartIndex( int startIndex, int count, int hits ); static int calculatePreviousStartIndex( int startIndex, int count );  }
@Test public void testCalculatePreviosStartIndex_FirstPage() { int nextStartIndex = ResponsePagingUtils.calculatePreviousStartIndex( 10, 20 ); assertThat( nextStartIndex, is( 0 ) ); }
@Test public void testCalculatePreviosStartIndex_FirstPageStartIndexLessThanCount() { int nextStartIndex = ResponsePagingUtils.calculatePreviousStartIndex( 5, 10 ); assertThat( nextStartIndex, is( 0 ) ); }
@Test public void testCalculatePreviosStartIndex_StartIndexGreaterThanCount() { int nextStartIndex = ResponsePagingUtils.calculatePreviousStartIndex( 30, 10 ); assertThat( nextStartIndex, is( 20 ) ); }
@Test public void testCalculatePreviosStartIndex_StartIndexAtBegin() { int nextStartIndex = ResponsePagingUtils.calculatePreviousStartIndex( 0, 10 ); assertThat( nextStartIndex, is( -1 ) ); }