Changeset 1b5309b


Ignore:
Timestamp:
Nov 10, 2013 8:42:24 PM (7 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
35fb332
Parents:
d2a1025b
Message:

junit test for new DataHelper?.skip()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/test/junit/net/i2p/data/DataHelperTest.java

    rd2a1025b r1b5309b  
    33import java.io.ByteArrayInputStream;
    44import java.io.ByteArrayOutputStream;
     5import java.io.IOException;
    56import java.util.Calendar;
    67import java.util.Date;
     
    127128        }
    128129    }
     130
     131    public void testSkip() throws Exception {
     132        final int sz = 256;
     133        TestInputStream tis = new TestInputStream(sz);
     134        DataHelper.skip(tis, sz);
     135        try {
     136            DataHelper.skip(tis, 1);
     137            fail();
     138        } catch (IOException ioe) {}
     139    }
     140
     141    private static class TestInputStream extends ByteArrayInputStream {
     142        private final Random r = new Random();
     143
     144        public TestInputStream(int size) {
     145            super(new byte[size]);
     146            r.nextBytes(buf);
     147        }
     148
     149        /** skip a little at a time, or sometimes zero */
     150        @Override
     151        public long skip(long n) {
     152            return super.skip(Math.min(n, r.nextInt(4)));
     153        }
     154    }
    129155}
Note: See TracChangeset for help on using the changeset viewer.