X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Ftest_code%2FNextableInputStreamTest.java;fp=src%2Fbe%2Fnikiroo%2Futils%2Ftest_code%2FNextableInputStreamTest.java;h=1b0064df249726c006d7f7d5c06ba793374d2a0f;hb=2e7584daaf5d2f06d326c21297a71d02dd275a35;hp=0000000000000000000000000000000000000000;hpb=ea152609fcf08aa02e85154e1f9a74a349241483;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/test_code/NextableInputStreamTest.java b/src/be/nikiroo/utils/test_code/NextableInputStreamTest.java new file mode 100644 index 0000000..1b0064d --- /dev/null +++ b/src/be/nikiroo/utils/test_code/NextableInputStreamTest.java @@ -0,0 +1,33 @@ +package be.nikiroo.utils.test_code; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import be.nikiroo.utils.IOUtils; +import be.nikiroo.utils.NextableInputStream; +import be.nikiroo.utils.test.TestCase; +import be.nikiroo.utils.test.TestLauncher; + +public class NextableInputStreamTest extends TestLauncher { + public NextableInputStreamTest(String[] args) { + super("NextableInputStream test", args); + + addTest(new TestCase("Simple byte array reading") { + @Override + public void test() throws Exception { + byte[] expected = new byte[] { 42, 12, 0, 127 }; + InputStream bin = new ByteArrayInputStream(expected); + NextableInputStream in = new NextableInputStream(bin); + byte[] actual = IOUtils.toByteArray(in); + + assertEquals( + "The resulting array has not the same number of items", + expected.length, actual.length); + for (int i = 0; i < expected.length; i++) { + assertEquals("Item " + i + " (0-based) is not the same", + expected[i], actual[i]); + } + } + }); + } +}