### Question:
ByteArrayInputStreamWithPos extends InputStream { public void setPosition(int pos) { Preconditions.checkArgument(pos >= 0 && pos <= count, "Position out of bounds."); this.position = pos; } ByteArrayInputStreamWithPos();  ByteArrayInputStreamWithPos(byte[] buffer);  ByteArrayInputStreamWithPos(byte[] buffer, int offset, int length); @Override int read(); @Override int read(byte[] b, int off, int len); @Override long skip(long toSkip); @Override boolean markSupported(); @Override void mark(int readAheadLimit); @Override void reset(); @Override int available(); @Override void close(); int getPosition(); void setPosition(int pos); void setBuffer(byte[] buffer, int offset, int length);  }### Answer:
@Test public void testSetPosition() throws Exception { Assert.assertEquals(data.length, stream.available()); Assert.assertEquals('0', stream.read()); stream.setPosition(1); Assert.assertEquals(data.length - 1, stream.available()); Assert.assertEquals('1', stream.read()); stream.setPosition(3); Assert.assertEquals(data.length - 3, stream.available()); Assert.assertEquals('3', stream.read()); stream.setPosition(data.length); Assert.assertEquals(0, stream.available()); Assert.assertEquals(-1, stream.read()); }
@Test public void testSetTooLargePosition() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Position out of bounds."); stream.setPosition(data.length + 1); }
@Test public void testSetNegativePosition() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Position out of bounds."); stream.setPosition(-1); }