Commit | Line | Data |
---|---|---|
2e7584da NR |
1 | package be.nikiroo.utils.test_code; |
2 | ||
3 | import java.io.ByteArrayInputStream; | |
4 | import java.io.InputStream; | |
5 | ||
6 | import be.nikiroo.utils.IOUtils; | |
7 | import be.nikiroo.utils.NextableInputStream; | |
8 | import be.nikiroo.utils.test.TestCase; | |
9 | import be.nikiroo.utils.test.TestLauncher; | |
10 | ||
11 | public 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 | } |