### Question:
IpcBuffer { public IpcBuffer setByte(int index, byte value) { Segment segment = segmentContaining(index); segment.buffer.put(segment.relativize(index), value); return this; } IpcBuffer(ByteBufferSequence buffers); int position(); IpcBuffer position(int newPosition); byte getByte(int index); short getShort(int index); char getChar(int index); int getInt(int index); long getLong(int index); IpcBuffer setByte(int index, byte value); IpcBuffer setShort(int index, short value); IpcBuffer setChar(int index, char value); IpcBuffer setInt(int index, int value); IpcBuffer setLong(int index, long value); byte readByte(); short readShort(); char readChar(); int readInt(); long readLong(); IpcBuffer writeByte(byte value); IpcBuffer writeShort(short value); IpcBuffer writeChar(char value); IpcBuffer writeInt(int value); IpcBuffer writeLong(long value);  }### Answer:
@Test public void tries_to_minimize_the_number_of_times_that_a_backing_buffer_is_looked_up() { AllocatedByteBufferSequence sequence = spy(new AllocatedByteBufferSequence(10)); IpcBuffer buffer = new IpcBuffer(sequence); buffer.setByte(5, (byte) 0); buffer.setByte(15, (byte) 0); buffer.setByte(5, (byte) 0); buffer.setByte(15, (byte) 0); verify(sequence, times(1)).get(0); verify(sequence, times(1)).get(1); }
@Test public void cannot_write_to_negative_positions() { buffer = new IpcBuffer(new AllocatedByteBufferSequence(10)); thrown.expect(IndexOutOfBoundsException.class); buffer.setByte(-1, (byte) 0); }