@@ -36,18 +36,40 @@ public class BitsTest {
3636 };
3737
3838 @ Test
39- public void testReadFully () throws IOException {
39+ public void testReadFullyWithBufferLargerThanExpected () throws IOException {
4040 final byte [] buffer = new byte [8192 ];
4141 Bits .readFully (new ByteArrayInputStream (BYTES ), buffer , BYTES .length );
4242 assertArrayEquals (BYTES , Arrays .copyOfRange (buffer , 0 , BYTES .length ));
4343 }
4444
45+ @ Test
46+ public void testReadFullyWithOffset () throws IOException {
47+ final int offset = 10 ;
48+ final byte [] buffer = new byte [8192 ];
49+ Bits .readFully (new ByteArrayInputStream (BYTES ), buffer , offset , BYTES .length );
50+ assertArrayEquals (BYTES , Arrays .copyOfRange (buffer , offset , BYTES .length + offset ));
51+ }
52+
53+ @ Test
54+ public void testReadFullyWithBufferEqualsToExpected () throws IOException {
55+ final int offset = 10 ;
56+ final byte [] buffer = new byte [offset + BYTES .length ];
57+ Bits .readFully (new ByteArrayInputStream (BYTES ), buffer , offset , BYTES .length );
58+ assertArrayEquals (BYTES , Arrays .copyOfRange (buffer , offset , BYTES .length + offset ));
59+ }
4560
46- @ Test (expected = IllegalArgumentException .class )
61+ @ Test (expected = IllegalArgumentException .class )
4762 public void testReadFullyUsingNotEnoughBigBuffer () throws IOException {
4863 Bits .readFully (new ByteArrayInputStream (BYTES ), new byte [2 ], BYTES .length );
4964 }
5065
66+ @ Test (expected = IllegalArgumentException .class )
67+ public void testReadFullyUsingNotEnoughBigBufferWithOffset () throws IOException {
68+ final int offset = 10 ;
69+ final byte [] buffer = new byte [BYTES .length ];
70+ Bits .readFully (new ByteArrayInputStream (BYTES ), buffer , offset , BYTES .length );
71+ }
72+
5173 @ Test
5274 public void testReadInt () {
5375 assertEquals (41 , Bits .readInt (BYTES ));
@@ -68,7 +90,6 @@ public void testReadIntInBigEndianNotation() {
6890 assertEquals (-12 , Bits .readIntBE (new byte []{-1 , -1 , -1 , -12 }, 0 ));
6991 }
7092
71-
7293 @ Test
7394 public void testReadLong () {
7495 assertEquals (Long .MAX_VALUE , Bits .readLong (BYTES , 24 ));
@@ -79,5 +100,4 @@ public void testReadLongWithNotEnoughData() {
79100 Bits .readLong (Arrays .copyOfRange (BYTES , 24 , 30 ), 0 );
80101 }
81102
82-
83103}
0 commit comments