### Question:
ReserveBuffer { public byte[] update(byte[] input, int offset, int inputLength) { int reserveToApply = Math.min(reserve.length, inputLength); int reserveToRelease = Math.max(reserveToApply - capacity(), 0); byte[] output = new byte[reserveToRelease + (inputLength - reserveToApply)]; read(output, 0, reserveToRelease); System.arraycopy(input, offset, output, reserveToRelease, inputLength - reserveToApply); write(input, offset + (inputLength - reserveToApply), reserveToApply); return output; } ReserveBuffer(int sizeInBytes); byte[] update(byte[] input, int offset, int inputLength); void read(byte[] buffer, int offset, int length); int capacity(); int getAvailable();  }### Answer:
@Test public void testIncremental() { ReserveBuffer buffer = new ReserveBuffer(16); byte[] input = new byte[1]; for (int i=0;i<16;i++) { input[0] = (byte)i; byte[] result = buffer.update(input, 0, 1); assertEquals(0, result.length); } byte[] largeInput = new byte[16]; Arrays.fill(largeInput, (byte)16); byte[] result = buffer.update(largeInput, 0, largeInput.length); assertEquals(16, result.length); for (int i=0;i<result.length;i++) { assertEquals(i, result[i]); } Arrays.fill(largeInput, (byte)17); result = buffer.update(largeInput, 0, largeInput.length); assertEquals(16, result.length); for (int i=0;i<result.length;i++) { assertEquals(16, result[i]); } }
@Test public void testChunks() { ReserveBuffer buffer = new ReserveBuffer(16); byte[] input = new byte[32]; for (int i=0;i<input.length;i++) { input[i] = (byte)i; } byte[] result = buffer.update(input, 0, input.length); assertEquals(16, result.length); for (int i=0;i<result.length;i++) { assertEquals(i, result[i]); } }