@Test public void skip_shouldConsumeBytes() throws IOException { FixedLengthInputStream fixedLengthInputStream = new FixedLengthInputStream(inputStream("Hello World"), 5); guaranteedSkip(fixedLengthInputStream, 2); assertRemainingInputStreamEquals("llo", fixedLengthInputStream); }
@Test public void readingStream_shouldNotConsumeMoreThanLimitFromUnderlyingInputStream() throws Exception { InputStream inputStream = inputStream("Hello world"); FixedLengthInputStream fixedLengthInputStream = new FixedLengthInputStream(inputStream, 5); exhaustStream(fixedLengthInputStream); assertRemainingInputStreamEquals(" world", inputStream); }
@Test public void read_withOverSizedByteArray_shouldNotConsumeMoreThanLimitFromUnderlyingStream() throws Exception { InputStream inputStream = inputStream("Hello World"); FixedLengthInputStream fixedLengthInputStream = new FixedLengthInputStream(inputStream, 6); //noinspection ResultOfMethodCallIgnored fixedLengthInputStream.read(new byte[100]); assertRemainingInputStreamEquals("World", inputStream); }
@Test public void skipRemaining_shouldNotConsumeMoreThanLimitFromUnderlyingInputStream() throws IOException { InputStream inputStream = inputStream("Hello World"); FixedLengthInputStream fixedLengthInputStream = new FixedLengthInputStream(inputStream, 6); fixedLengthInputStream.skipRemaining(); assertRemainingInputStreamEquals("World", inputStream); }
@Test public void read_withOverSizedByteArrayInMiddleOfStream_shouldNotConsumeMoreThanLimitFromUnderlyingStream() throws Exception { InputStream inputStream = inputStream("Hello World"); FixedLengthInputStream fixedLengthInputStream = new FixedLengthInputStream(inputStream, 6); consumeBytes(fixedLengthInputStream, 5); //noinspection ResultOfMethodCallIgnored fixedLengthInputStream.read(new byte[10]); assertRemainingInputStreamEquals("World", inputStream); }