3ba7be8c738d2308215f33b59dbeff02a69a4606
1 package be
.nikiroo
.utils
.test_code
;
3 import java
.io
.ByteArrayInputStream
;
4 import java
.io
.InputStream
;
6 import be
.nikiroo
.utils
.IOUtils
;
7 import be
.nikiroo
.utils
.streams
.BufferedInputStream
;
8 import be
.nikiroo
.utils
.test
.TestCase
;
9 import be
.nikiroo
.utils
.test
.TestLauncher
;
11 class BufferedInputStreamTest
extends TestLauncher
{
12 public BufferedInputStreamTest(String
[] args
) {
13 super("BufferedInputStream test", args
);
15 addTest(new TestCase("Simple InputStream reading") {
17 public void test() throws Exception
{
18 byte[] expected
= new byte[] { 42, 12, 0, 127 };
19 BufferedInputStream in
= new BufferedInputStream(
20 new ByteArrayInputStream(expected
));
21 checkArrays(this, "FIRST", in
, expected
);
25 addTest(new TestCase("Simple byte array reading") {
27 public void test() throws Exception
{
28 byte[] expected
= new byte[] { 42, 12, 0, 127 };
29 BufferedInputStream in
= new BufferedInputStream(expected
);
30 checkArrays(this, "FIRST", in
, expected
);
35 static void checkArrays(TestCase test
, String prefix
, InputStream in
,
36 byte[] expected
) throws Exception
{
37 byte[] actual
= IOUtils
.toByteArray(in
);
38 test
.assertEquals("The " + prefix
39 + " resulting array has not the correct number of items",
40 expected
.length
, actual
.length
);
41 for (int i
= 0; i
< actual
.length
; i
++) {
42 test
.assertEquals(prefix
+ ": item " + i
43 + " (0-based) is not the same", expected
[i
], actual
[i
]);