### Question:
RenewableBatchIdSequence implements IdSequence, Resource { @Override public long nextId() { assert !closed; long id; while ( currentBatch == null || (id = currentBatch.nextId()) == VALUE_REPRESENTING_NULL ) { currentBatch = source.nextIdBatch( batchSize ).iterator(); } return id; } RenewableBatchIdSequence( IdSequence source, int batchSize, LongConsumer excessIdConsumer ); @Override synchronized void close(); @Override long nextId(); @Override IdRange nextIdBatch( int size );  }### Answer:
@Test public void shouldRequestIdBatchFromSourceOnFirstCall() { assertEquals( 0, idSource.calls ); assertEquals( 0, ids.nextId() ); assertEquals( 1, idSource.calls ); for ( int i = 1; i < BATCH_SIZE; i++ ) { assertEquals( i, ids.nextId() ); assertEquals( 1, idSource.calls ); } }
@Test public void shouldRequestIdBatchFromSourceOnDepletingCurrent() { assertEquals( 0, idSource.calls ); for ( int i = 0; i < BATCH_SIZE; i++ ) { assertEquals( i, ids.nextId() ); } assertEquals( 1, idSource.calls ); long firstIdOfNextBatch = ids.nextId(); assertEquals( BATCH_SIZE, firstIdOfNextBatch ); assertEquals( 2, idSource.calls ); }