Merge commit '77d3a60869e7a780c6ae069e51530e1eacece5e2'
[fanfix.git] / src / be / nikiroo / utils / test_code / BufferedInputStreamTest.java
index e2fc80bf38275b666fdf8f892eece519e1d80537..c715585f7da7afb93633c937672342f5b6ec3fc7 100644 (file)
@@ -3,12 +3,12 @@ package be.nikiroo.utils.test_code;
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 
-import be.nikiroo.utils.BufferedInputStream;
 import be.nikiroo.utils.IOUtils;
+import be.nikiroo.utils.streams.BufferedInputStream;
 import be.nikiroo.utils.test.TestCase;
 import be.nikiroo.utils.test.TestLauncher;
 
-public class BufferedInputStreamTest extends TestLauncher {
+class BufferedInputStreamTest extends TestLauncher {
        public BufferedInputStreamTest(String[] args) {
                super("BufferedInputStream test", args);
 
@@ -30,6 +30,75 @@ public class BufferedInputStreamTest extends TestLauncher {
                                checkArrays(this, "FIRST", in, expected);
                        }
                });
+
+               addTest(new TestCase("Byte array is(byte[])") {
+                       @Override
+                       public void test() throws Exception {
+                               byte[] expected = new byte[] { 42, 12, 0, 127 };
+                               BufferedInputStream in = new BufferedInputStream(expected);
+                               assertEquals(
+                                               "The array should be considered identical to its source",
+                                               true, in.is(expected));
+                               assertEquals(
+                                               "The array should be considered different to that one",
+                                               false, in.is(new byte[] { 42, 12, 0, 121 }));
+                               in.close();
+                       }
+               });
+
+               addTest(new TestCase("InputStream is(byte[])") {
+                       @Override
+                       public void test() throws Exception {
+                               byte[] expected = new byte[] { 42, 12, 0, 127 };
+                               BufferedInputStream in = new BufferedInputStream(
+                                               new ByteArrayInputStream(expected));
+                               assertEquals(
+                                               "The array should be considered identical to its source",
+                                               true, in.is(expected));
+                               assertEquals(
+                                               "The array should be considered different to that one",
+                                               false, in.is(new byte[] { 42, 12, 0, 121 }));
+                               in.close();
+                       }
+               });
+
+               addTest(new TestCase("Byte array is(String)") {
+                       @Override
+                       public void test() throws Exception {
+                               String expected = "Testy";
+                               BufferedInputStream in = new BufferedInputStream(
+                                               expected.getBytes("UTF-8"));
+                               assertEquals(
+                                               "The array should be considered identical to its source",
+                                               true, in.is(expected));
+                               assertEquals(
+                                               "The array should be considered different to that one",
+                                               false, in.is("Autre"));
+                               assertEquals(
+                                               "The array should be considered different to that one",
+                                               false, in.is("Test"));
+                               in.close();
+                       }
+               });
+
+               addTest(new TestCase("InputStream is(String)") {
+                       @Override
+                       public void test() throws Exception {
+                               String expected = "Testy";
+                               BufferedInputStream in = new BufferedInputStream(
+                                               new ByteArrayInputStream(expected.getBytes("UTF-8")));
+                               assertEquals(
+                                               "The array should be considered identical to its source",
+                                               true, in.is(expected));
+                               assertEquals(
+                                               "The array should be considered different to that one",
+                                               false, in.is("Autre"));
+                               assertEquals(
+                                               "The array should be considered different to that one",
+                                               false, in.is("Testy."));
+                               in.close();
+                       }
+               });
        }
 
        static void checkArrays(TestCase test, String prefix, InputStream in,
@@ -39,8 +108,8 @@ public class BufferedInputStreamTest extends TestLauncher {
                                + " resulting array has not the correct number of items",
                                expected.length, actual.length);
                for (int i = 0; i < actual.length; i++) {
-                       test.assertEquals("Item " + i + " (0-based) is not the same",
-                                       expected[i], actual[i]);
+                       test.assertEquals(prefix + ": item " + i
+                                       + " (0-based) is not the same", expected[i], actual[i]);
                }
        }
 }