junit test for new DataHelper.skip()

This commit is contained in:
zzz
2013-11-10 20:42:24 +00:00
parent d2a1025b3f
commit 1b5309be05

View File

@ -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)));
}
}
}