void () { final ByteBuffer buffer = ByteBuffer.allocate(200); final int limitInitial = 128; final byte[] bytes = AttributesStorageOnTheTopOfBlobStorageTestBase.generateBytes(ThreadLocalRandom.current(), buffer.capacity()); for (int offset = 0; offset < limitInitial; offset++) { for (int oldGap = 0; oldGap < limitInitial - offset; oldGap++) { for (int newGap = 0; newGap < 128; newGap++) { final int positionBefore = offset; buffer .clear() .put(bytes) .position(positionBefore).limit(limitInitial); final ByteBuffer newBuffer = AttributesStorageOverBlobStorage.resizeGap(buffer, offset, oldGap, newGap); assertEquals( "Position must be unchanged", positionBefore, newBuffer.position() ); assertEquals( "Limit must adjust for the gaps difference (" + (newGap - oldGap) + ")", limitInitial + (newGap - oldGap), newBuffer.limit() ); final byte[] firstSlice = new byte[offset]; newBuffer.get(0, firstSlice); assertArrayEquals( "Bytes before the gap [0.." + offset + ") must remain unchanged", firstSlice, Arrays.copyOf(bytes, offset) ); final byte[] lastSlice = new byte[limitInitial - offset - oldGap]; newBuffer.get(offset + newGap, lastSlice); assertArrayEquals( "Bytes after the gap (" + (offset + newGap) + ".." + limitInitial + ") must remain unchanged", lastSlice, Arrays.copyOfRange(bytes, offset + oldGap, limitInitial) ); } } } }