void () { int[] bufferSizesToCheck = generateBufferSizesToCheck(); //intentionally request randomly to check different ordering: ThreadLocalRandom rnd = ThreadLocalRandom.current(); for (int i = 0; i < bufferSizesToCheck.length * 2; i++) { int bufferSize = bufferSizesToCheck[rnd.nextInt(bufferSizesToCheck.length)]; ByteBuffer buffer = allocator.allocate(bufferSize); try { assertEquals( "Allocated buffer must be already positioned so that remaining=bufferSize", bufferSize, buffer.remaining() ); } finally { allocator.release(buffer); } } }