This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new f760f75b350 Added unit test based on a scanner issue
f760f75b350 is described below
commit f760f75b350fe51ec1bf614381f55e42ec69a476
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Aug 5 16:31:47 2022 +0200
Added unit test based on a scanner issue
---
.../java/org/apache/camel/util/ScannerTest.java | 84 ++++++++++++++++++++++
1 file changed, 84 insertions(+)
diff --git
a/core/camel-util/src/test/java/org/apache/camel/util/ScannerTest.java
b/core/camel-util/src/test/java/org/apache/camel/util/ScannerTest.java
new file mode 100644
index 00000000000..5b9af65dd82
--- /dev/null
+++ b/core/camel-util/src/test/java/org/apache/camel/util/ScannerTest.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.nio.charset.StandardCharsets;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+public class ScannerTest {
+
+ @Test
+ public void testScannerString() throws Exception {
+ String d = "data1\ndata2\ndata3\n";
+
+ Scanner s = new Scanner(d, "\n");
+
+ Assertions.assertTrue(s.hasNext());
+ Assertions.assertEquals("data1", s.next());
+ Assertions.assertTrue(s.hasNext());
+ Assertions.assertEquals("data2", s.next());
+ Assertions.assertTrue(s.hasNext());
+ Assertions.assertEquals("data3", s.next());
+ Assertions.assertFalse(s.hasNext());
+ }
+
+ @Test
+ public void testScannerInputStream() throws Exception {
+ String d = "data1\ndata2\ndata3\n";
+ InputStream is = new
ByteArrayInputStream(d.getBytes(StandardCharsets.UTF_8));
+
+ Scanner s = new Scanner(is, "UTF-8", "\n");
+
+ Assertions.assertTrue(s.hasNext());
+ Assertions.assertEquals("data1", s.next());
+ Assertions.assertTrue(s.hasNext());
+ Assertions.assertEquals("data2", s.next());
+ Assertions.assertTrue(s.hasNext());
+ Assertions.assertEquals("data3", s.next());
+ Assertions.assertFalse(s.hasNext());
+ }
+
+ @Test
+ @Disabled("TODO: scanner with open piped connections")
+ public void testPipedInputStream() throws Exception {
+ PipedOutputStream pos = new PipedOutputStream();
+ InputStream is = new PipedInputStream(pos);
+
+ pos.write("data1\n".getBytes());
+ pos.write("data2\n".getBytes());
+ pos.write("data3\n".getBytes());
+ pos.flush();
+
+ Scanner s = new Scanner(is, "UTF-8", "\n");
+
+ Assertions.assertTrue(s.hasNext());
+ Assertions.assertEquals("data1", s.next());
+ Assertions.assertTrue(s.hasNext());
+ Assertions.assertEquals("data2", s.next());
+ Assertions.assertTrue(s.hasNext());
+ Assertions.assertEquals("data3", s.next());
+ Assertions.assertFalse(s.hasNext());
+ }
+
+}