+
+ addTest(new TestCase("UTF-8 text lines test") {
+ @Override
+ public void test() throws Exception {
+ String ln1 = "Ligne première";
+ String ln2 = "Ligne la deuxième du nom";
+ byte[] data = (ln1 + "\n" + ln2).getBytes("UTF-8");
+ NextableInputStream in = new NextableInputStream(
+ new ByteArrayInputStream(data),
+ new NextableInputStreamStep('\n'));
+
+ checkNext(this, false, "FIRST", in, ln1.getBytes("UTF-8"));
+ checkNext(this, true, "SECOND", in, ln2.getBytes("UTF-8"));
+ }
+ });
+ }
+
+ static void checkNext(TestCase test, boolean callNext, String prefix,
+ NextableInputStream in, byte[] expected) throws Exception {
+ if (callNext) {
+ test.assertEquals("Cannot get " + prefix + " entry", true,
+ in.next());
+ }
+ byte[] actual = IOUtils.toByteArray(in);
+ test.assertEquals("The " + prefix
+ + " 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]);
+ }