CachedService implements Serializable { public static CachedService partial( List<RowMetaAndData> rowMetaAndData, DataServiceExecutor executor ) { return new CachedService( rowMetaAndData, Optional.of( calculateRank( executor ) ), Optional.of( calculateServiceRowRank( executor ) ) ); } private  CachedService( List<RowMetaAndData> rowMetaAndData, Optional<Integer> ranking,  Optional<Integer> ranking2 ); static CachedService complete( List<RowMetaAndData> rowMetaAndData ); static CachedService partial( List<RowMetaAndData> rowMetaAndData, DataServiceExecutor executor ); List<RowMetaAndData> getRowMetaAndData(); Optional<Integer> getRanking(); @Override String toString(); boolean isComplete(); boolean answersQuery( DataServiceExecutor executor );  }
@Test public void testPartial() throws Exception { CachedService rowLimit, limit, limitOffset, unlimited; when( sqlTransGenerator.getRowLimit() ).thenReturn( 10, 0 ); rowLimit = partial( dataServiceExecutor( BASE_QUERY ) ); limit = partial( dataServiceExecutor( BASE_QUERY + " LIMIT 20" ) ); limitOffset = partial( dataServiceExecutor( BASE_QUERY + " LIMIT 20 OFFSET 10" ) ); unlimited = partial( dataServiceExecutor( BASE_QUERY ) ); for ( CachedService loader : ImmutableList.of( rowLimit, limit, limitOffset ) ) { assertThat( loader.getRowMetaAndData(), equalTo( testData ) ); assertThat( loader.getRanking().get(), lessThan( Integer.MAX_VALUE ) ); } assertThat( unlimited.getRowMetaAndData(), equalTo( testData ) ); assertThat( unlimited.getRanking().get(), equalTo( Integer.MAX_VALUE ) ); assertThat( rowLimit.getRanking().get(), lessThan( limit.getRanking().get() ) ); assertThat( limit.getRanking().get(), lessThan( limitOffset.getRanking().get() ) ); assertThat( limitOffset.getRanking().get(), lessThan( unlimited.getRanking().get() ) ); }