new: NextableInputStream, step 1
[fanfix.git] / src / be / nikiroo / utils / test_code / NextableInputStreamTest.java
CommitLineData
2e7584da
NR
1package be.nikiroo.utils.test_code;
2
3import java.io.ByteArrayInputStream;
4import java.io.InputStream;
5
6import be.nikiroo.utils.IOUtils;
7import be.nikiroo.utils.NextableInputStream;
8import be.nikiroo.utils.test.TestCase;
9import be.nikiroo.utils.test.TestLauncher;
10
11public class NextableInputStreamTest extends TestLauncher {
12 public NextableInputStreamTest(String[] args) {
13 super("NextableInputStream test", args);
14
15 addTest(new TestCase("Simple byte array reading") {
16 @Override
17 public void test() throws Exception {
18 byte[] expected = new byte[] { 42, 12, 0, 127 };
19 InputStream bin = new ByteArrayInputStream(expected);
20 NextableInputStream in = new NextableInputStream(bin);
21 byte[] actual = IOUtils.toByteArray(in);
22
23 assertEquals(
24 "The resulting array has not the same number of items",
25 expected.length, actual.length);
26 for (int i = 0; i < expected.length; i++) {
27 assertEquals("Item " + i + " (0-based) is not the same",
28 expected[i], actual[i]);
29 }
30 }
31 });
32 }
33}