@Test public void testSetOutOfBounds() throws Exception { Buffer b = Buffer.buffer(numSets); assertIndexOutOfBoundsException(() -> b.setByte(-1, (byte) 0)); assertIndexOutOfBoundsException(() -> b.setInt(-1, 0)); assertIndexOutOfBoundsException(() -> b.setLong(-1, 0)); assertIndexOutOfBoundsException(() -> b.setDouble(-1, 0)); assertIndexOutOfBoundsException(() -> b.setFloat(-1, 0)); assertIndexOutOfBoundsException(() -> b.setShort(-1, (short) 0)); assertIndexOutOfBoundsException(() -> b.setBuffer(-1, b)); assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, -1, 0)); assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, 0, -1)); assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1))); assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), -1, 0)); assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), 0, -1)); assertIndexOutOfBoundsException(() -> b.setString(-1, "")); assertIndexOutOfBoundsException(() -> b.setString(-1, "", "UTF-8")); }
assertIndexOutOfBoundsException(() -> b.getByte(bytesLen)); assertIndexOutOfBoundsException(() -> b.getByte(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getByte(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getByte(-1)); assertIndexOutOfBoundsException(() -> b.getByte(-100)); assertIndexOutOfBoundsException(() -> b.getInt(bytesLen)); assertIndexOutOfBoundsException(() -> b.getInt(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getInt(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getInt(-1)); assertIndexOutOfBoundsException(() -> b.getInt(-100)); assertIndexOutOfBoundsException(() -> b.getLong(bytesLen)); assertIndexOutOfBoundsException(() -> b.getLong(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getLong(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getLong(-1)); assertIndexOutOfBoundsException(() -> b.getLong(-100)); assertIndexOutOfBoundsException(() -> b.getFloat(bytesLen)); assertIndexOutOfBoundsException(() -> b.getFloat(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getFloat(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getFloat(-1)); assertIndexOutOfBoundsException(() -> b.getFloat(-100)); assertIndexOutOfBoundsException(() -> b.getDouble(bytesLen)); assertIndexOutOfBoundsException(() -> b.getDouble(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getDouble(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getDouble(-1)); assertIndexOutOfBoundsException(() -> b.getDouble(-100)); assertIndexOutOfBoundsException(() -> b.getShort(bytesLen)); assertIndexOutOfBoundsException(() -> b.getShort(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getShort(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getShort(-1));
@Test public void testSetOutOfBounds() throws Exception { Buffer b = Buffer.buffer(numSets); assertIndexOutOfBoundsException(() -> b.setByte(-1, (byte) 0)); assertIndexOutOfBoundsException(() -> b.setInt(-1, 0)); assertIndexOutOfBoundsException(() -> b.setLong(-1, 0)); assertIndexOutOfBoundsException(() -> b.setDouble(-1, 0)); assertIndexOutOfBoundsException(() -> b.setFloat(-1, 0)); assertIndexOutOfBoundsException(() -> b.setShort(-1, (short) 0)); assertIndexOutOfBoundsException(() -> b.setBuffer(-1, b)); assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, -1, 0)); assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, 0, -1)); assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1))); assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), -1, 0)); assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), 0, -1)); assertIndexOutOfBoundsException(() -> b.setString(-1, "")); assertIndexOutOfBoundsException(() -> b.setString(-1, "", "UTF-8")); }
assertIndexOutOfBoundsException(() -> b.getByte(bytesLen)); assertIndexOutOfBoundsException(() -> b.getByte(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getByte(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getByte(-1)); assertIndexOutOfBoundsException(() -> b.getByte(-100)); assertIndexOutOfBoundsException(() -> b.getInt(bytesLen)); assertIndexOutOfBoundsException(() -> b.getInt(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getInt(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getInt(-1)); assertIndexOutOfBoundsException(() -> b.getInt(-100)); assertIndexOutOfBoundsException(() -> b.getLong(bytesLen)); assertIndexOutOfBoundsException(() -> b.getLong(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getLong(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getLong(-1)); assertIndexOutOfBoundsException(() -> b.getLong(-100)); assertIndexOutOfBoundsException(() -> b.getFloat(bytesLen)); assertIndexOutOfBoundsException(() -> b.getFloat(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getFloat(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getFloat(-1)); assertIndexOutOfBoundsException(() -> b.getFloat(-100)); assertIndexOutOfBoundsException(() -> b.getDouble(bytesLen)); assertIndexOutOfBoundsException(() -> b.getDouble(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getDouble(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getDouble(-1)); assertIndexOutOfBoundsException(() -> b.getDouble(-100)); assertIndexOutOfBoundsException(() -> b.getShort(bytesLen)); assertIndexOutOfBoundsException(() -> b.getShort(bytesLen + 1)); assertIndexOutOfBoundsException(() -> b.getShort(bytesLen + 100)); assertIndexOutOfBoundsException(() -> b.getShort(-1));