diff --git a/core/java/test/junit/net/i2p/data/DataHelperTest.java b/core/java/test/junit/net/i2p/data/DataHelperTest.java index 983a3cc9a7b8bcc586732097e77f79dfe05f94f5..b149b8fd71792a1a17e844e63a276956dcf1f5ab 100644 --- a/core/java/test/junit/net/i2p/data/DataHelperTest.java +++ b/core/java/test/junit/net/i2p/data/DataHelperTest.java @@ -2,6 +2,7 @@ package net.i2p.data; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.Calendar; import java.util.Date; import java.util.Random; @@ -126,4 +127,29 @@ public class DataHelperTest extends TestCase{ } } + + public void testSkip() throws Exception { + final int sz = 256; + TestInputStream tis = new TestInputStream(sz); + DataHelper.skip(tis, sz); + try { + DataHelper.skip(tis, 1); + fail(); + } catch (IOException ioe) {} + } + + private static class TestInputStream extends ByteArrayInputStream { + private final Random r = new Random(); + + public TestInputStream(int size) { + super(new byte[size]); + r.nextBytes(buf); + } + + /** skip a little at a time, or sometimes zero */ + @Override + public long skip(long n) { + return super.skip(Math.min(n, r.nextInt(4))); + } + } }