You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/06/16 16:10:31 UTC

[camel] branch main updated (29e918f1cb8 -> 83aa9070710)

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from 29e918f1cb8 Revert "should servlet and rest throw exceptions when duplicate and ambiguous paths occur (#10400)"
     new 10b0f9161b8 (chores) camel-util: use Java native methods for padding/filling chars
     new 8e93fe10200 (chores) camel-util: added missing test annotation
     new 5ff4ef88b67 (chores) camel-core: remove duplicated test case
     new 83aa9070710 (chores) camel-util: remove unused exceptions

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/camel/util/StringHelperTest.java    | 354 ---------------------
 .../java/org/apache/camel/util/StringHelper.java   |  10 +-
 .../org/apache/camel/util/StringHelperTest.java    | 354 ++++++++++++++++++++-
 3 files changed, 342 insertions(+), 376 deletions(-)
 delete mode 100644 core/camel-core/src/test/java/org/apache/camel/util/StringHelperTest.java


[camel] 03/04: (chores) camel-core: remove duplicated test case

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 5ff4ef88b67dc801764c68d90af2fc76577143f2
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Jun 16 13:17:41 2023 +0200

    (chores) camel-core: remove duplicated test case
---
 .../org/apache/camel/util/StringHelperTest.java    | 354 ---------------------
 .../org/apache/camel/util/StringHelperTest.java    | 325 +++++++++++++++++++
 2 files changed, 325 insertions(+), 354 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/util/StringHelperTest.java b/core/camel-core/src/test/java/org/apache/camel/util/StringHelperTest.java
deleted file mode 100644
index a0770e7009a..00000000000
--- a/core/camel-core/src/test/java/org/apache/camel/util/StringHelperTest.java
+++ /dev/null
@@ -1,354 +0,0 @@
-/*
- * 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.util.List;
-import java.util.Locale;
-
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-/**
- * Unit test for StringHelper
- */
-public class StringHelperTest {
-
-    @Test
-    public void testSimpleSanitized() {
-        String out = StringHelper.sanitize("hello");
-        assertEquals(-1, out.indexOf(':'), "Should not contain : ");
-        assertEquals(-1, out.indexOf('.'), "Should not contain . ");
-    }
-
-    @Test
-    public void testNotFileFriendlySimpleSanitized() {
-        String out = StringHelper.sanitize("c:\\helloworld");
-        assertEquals(-1, out.indexOf(':'), "Should not contain : ");
-        assertEquals(-1, out.indexOf('.'), "Should not contain . ");
-    }
-
-    @Test
-    public void testSimpleCRLF() {
-        String out = StringHelper.removeCRLF("hello");
-        assertEquals("hello", out);
-        boolean b6 = !out.contains("\r");
-        assertTrue(b6, "Should not contain : ");
-        boolean b5 = !out.contains("\n");
-        assertTrue(b5, "Should not contain : ");
-
-        out = StringHelper.removeCRLF("hello\r\n");
-        assertEquals("hello", out);
-        boolean b4 = !out.contains("\r");
-        assertTrue(b4, "Should not contain : ");
-        boolean b3 = !out.contains("\n");
-        assertTrue(b3, "Should not contain : ");
-
-        out = StringHelper.removeCRLF("\r\nhe\r\nllo\n");
-        assertEquals("hello", out);
-        boolean b2 = !out.contains("\r");
-        assertTrue(b2, "Should not contain : ");
-        boolean b1 = !out.contains("\n");
-        assertTrue(b1, "Should not contain : ");
-
-        out = StringHelper.removeCRLF("hello" + System.lineSeparator());
-        assertEquals("hello", out);
-        boolean b = !out.contains(System.lineSeparator());
-        assertTrue(b, "Should not contain : ");
-    }
-
-    @Test
-    public void testCountChar() {
-        assertEquals(0, StringHelper.countChar("Hello World", 'x'));
-        assertEquals(1, StringHelper.countChar("Hello World", 'e'));
-        assertEquals(3, StringHelper.countChar("Hello World", 'l'));
-        assertEquals(1, StringHelper.countChar("Hello World", ' '));
-        assertEquals(0, StringHelper.countChar("", ' '));
-        assertEquals(0, StringHelper.countChar(null, ' '));
-    }
-
-    @Test
-    public void testRemoveQuotes() throws Exception {
-        assertEquals("Hello World", StringHelper.removeQuotes("Hello World"));
-        assertEquals("", StringHelper.removeQuotes(""));
-        assertNull(StringHelper.removeQuotes(null));
-        assertEquals(" ", StringHelper.removeQuotes(" "));
-        assertEquals("foo", StringHelper.removeQuotes("'foo'"));
-        assertEquals("foo", StringHelper.removeQuotes("'foo"));
-        assertEquals("foo", StringHelper.removeQuotes("foo'"));
-        assertEquals("foo", StringHelper.removeQuotes("\"foo\""));
-        assertEquals("foo", StringHelper.removeQuotes("\"foo"));
-        assertEquals("foo", StringHelper.removeQuotes("foo\""));
-        assertEquals("foo", StringHelper.removeQuotes("'foo\""));
-    }
-
-    @Test
-    public void testRemoveLeadingAndEndingQuotes() throws Exception {
-        assertNull(StringHelper.removeLeadingAndEndingQuotes(null));
-        assertEquals("", StringHelper.removeLeadingAndEndingQuotes(""));
-        assertEquals(" ", StringHelper.removeLeadingAndEndingQuotes(" "));
-        assertEquals("Hello World", StringHelper.removeLeadingAndEndingQuotes("Hello World"));
-        assertEquals("Hello World", StringHelper.removeLeadingAndEndingQuotes("'Hello World'"));
-        assertEquals("Hello World", StringHelper.removeLeadingAndEndingQuotes("\"Hello World\""));
-        assertEquals("Hello 'Camel'", StringHelper.removeLeadingAndEndingQuotes("Hello 'Camel'"));
-    }
-
-    @Test
-    public void testHasUpper() throws Exception {
-        assertFalse(StringHelper.hasUpperCase(null));
-        assertFalse(StringHelper.hasUpperCase(""));
-        assertFalse(StringHelper.hasUpperCase(" "));
-        assertFalse(StringHelper.hasUpperCase("com.foo"));
-        assertFalse(StringHelper.hasUpperCase("com.foo.123"));
-
-        assertTrue(StringHelper.hasUpperCase("com.foo.MyClass"));
-        assertTrue(StringHelper.hasUpperCase("com.foo.My"));
-
-        // Note, this is not a FQN
-        assertTrue(StringHelper.hasUpperCase("com.foo.subA"));
-    }
-
-    @Test
-    public void testIsClassName() throws Exception {
-        assertFalse(StringHelper.isClassName(null));
-        assertFalse(StringHelper.isClassName(""));
-        assertFalse(StringHelper.isClassName(" "));
-        assertFalse(StringHelper.isClassName("com.foo"));
-        assertFalse(StringHelper.isClassName("com.foo.123"));
-
-        assertTrue(StringHelper.isClassName("com.foo.MyClass"));
-        assertTrue(StringHelper.isClassName("com.foo.My"));
-
-        // Note, this is not a FQN
-        assertFalse(StringHelper.isClassName("com.foo.subA"));
-    }
-
-    @Test
-    public void testHasStartToken() throws Exception {
-        assertFalse(StringHelper.hasStartToken(null, null));
-        assertFalse(StringHelper.hasStartToken(null, "simple"));
-        assertFalse(StringHelper.hasStartToken("", null));
-        assertFalse(StringHelper.hasStartToken("", "simple"));
-        assertFalse(StringHelper.hasStartToken("Hello World", null));
-        assertFalse(StringHelper.hasStartToken("Hello World", "simple"));
-
-        assertFalse(StringHelper.hasStartToken("${body}", null));
-        assertTrue(StringHelper.hasStartToken("${body}", "simple"));
-        assertTrue(StringHelper.hasStartToken("$simple{body}", "simple"));
-
-        assertFalse(StringHelper.hasStartToken("${body}", null));
-        assertFalse(StringHelper.hasStartToken("${body}", "foo"));
-        // $foo{ is valid because its foo language
-        assertTrue(StringHelper.hasStartToken("$foo{body}", "foo"));
-    }
-
-    @Test
-    public void testIsQuoted() throws Exception {
-        assertFalse(StringHelper.isQuoted(null));
-        assertFalse(StringHelper.isQuoted(""));
-        assertFalse(StringHelper.isQuoted(" "));
-        assertFalse(StringHelper.isQuoted("abc"));
-        assertFalse(StringHelper.isQuoted("abc'"));
-        assertFalse(StringHelper.isQuoted("\"abc'"));
-        assertFalse(StringHelper.isQuoted("abc\""));
-        assertFalse(StringHelper.isQuoted("'abc\""));
-        assertFalse(StringHelper.isQuoted("\"abc'"));
-        assertFalse(StringHelper.isQuoted("abc'def'"));
-        assertFalse(StringHelper.isQuoted("abc'def'ghi"));
-        assertFalse(StringHelper.isQuoted("'def'ghi"));
-
-        assertTrue(StringHelper.isQuoted("'abc'"));
-        assertTrue(StringHelper.isQuoted("\"abc\""));
-    }
-
-    @Test
-    public void testRemoveInitialCharacters() throws Exception {
-        assertEquals("foo", StringHelper.removeStartingCharacters("foo", '/'));
-        assertEquals("foo", StringHelper.removeStartingCharacters("/foo", '/'));
-        assertEquals("foo", StringHelper.removeStartingCharacters("//foo", '/'));
-    }
-
-    @Test
-    public void testBefore() {
-        assertEquals("Hello ", StringHelper.before("Hello World", "World"));
-        assertEquals("Hello ", StringHelper.before("Hello World Again", "World"));
-        assertNull(StringHelper.before("Hello Again", "Foo"));
-
-        assertTrue(StringHelper.before("mykey:ignore", ":", "mykey"::equals).orElse(false));
-        assertFalse(StringHelper.before("ignore:ignore", ":", "mykey"::equals).orElse(false));
-
-        assertEquals("", StringHelper.before("Hello World", "Test", ""));
-        assertNull(StringHelper.before("Hello World", "Test", (String) null));
-
-        assertEquals("a:b", StringHelper.beforeLast("a:b:c", ":"));
-        assertEquals("", StringHelper.beforeLast("a:b:c", "_", ""));
-    }
-
-    @Test
-    public void testAfter() {
-        assertEquals(" World", StringHelper.after("Hello World", "Hello"));
-        assertEquals(" World Again", StringHelper.after("Hello World Again", "Hello"));
-        assertNull(StringHelper.after("Hello Again", "Foo"));
-
-        assertTrue(StringHelper.after("ignore:mykey", ":", "mykey"::equals).orElse(false));
-        assertFalse(StringHelper.after("ignore:ignore", ":", "mykey"::equals).orElse(false));
-
-        assertEquals("", StringHelper.after("Hello World", "Test", ""));
-        assertNull(StringHelper.after("Hello World", "Test", (String) null));
-
-        assertEquals("c", StringHelper.afterLast("a:b:c", ":"));
-        assertEquals("", StringHelper.afterLast("a:b:c", "_", ""));
-    }
-
-    @Test
-    public void testBetween() {
-        assertEquals("foo bar", StringHelper.between("Hello 'foo bar' how are you", "'", "'"));
-        assertEquals("foo bar", StringHelper.between("Hello ${foo bar} how are you", "${", "}"));
-        assertNull(StringHelper.between("Hello ${foo bar} how are you", "'", "'"));
-
-        assertTrue(StringHelper.between("begin:mykey:end", "begin:", ":end", "mykey"::equals).orElse(false));
-        assertFalse(StringHelper.between("begin:ignore:end", "begin:", ":end", "mykey"::equals).orElse(false));
-    }
-
-    @Test
-    public void testBetweenOuterPair() {
-        assertEquals("bar(baz)123", StringHelper.betweenOuterPair("foo(bar(baz)123)", '(', ')'));
-        assertNull(StringHelper.betweenOuterPair("foo(bar(baz)123))", '(', ')'));
-        assertNull(StringHelper.betweenOuterPair("foo(bar(baz123", '(', ')'));
-        assertNull(StringHelper.betweenOuterPair("foo)bar)baz123", '(', ')'));
-        assertEquals("bar", StringHelper.betweenOuterPair("foo(bar)baz123", '(', ')'));
-        assertEquals("'bar', 'baz()123', 123", StringHelper.betweenOuterPair("foo('bar', 'baz()123', 123)", '(', ')'));
-
-        assertTrue(StringHelper.betweenOuterPair("foo(bar)baz123", '(', ')', "bar"::equals).orElse(false));
-        assertFalse(StringHelper.betweenOuterPair("foo[bar)baz123", '(', ')', "bar"::equals).orElse(false));
-    }
-
-    @Test
-    public void testIsJavaIdentifier() {
-        assertTrue(StringHelper.isJavaIdentifier("foo"));
-        assertFalse(StringHelper.isJavaIdentifier("foo.bar"));
-        assertFalse(StringHelper.isJavaIdentifier(""));
-        assertFalse(StringHelper.isJavaIdentifier(null));
-    }
-
-    @Test
-    public void testNormalizeClassName() {
-        assertEquals("my.package-info", StringHelper.normalizeClassName("my.package-info"), "Should get the right class name");
-        assertEquals("Integer[]", StringHelper.normalizeClassName("Integer[] \r"), "Should get the right class name");
-        assertEquals("Hello_World", StringHelper.normalizeClassName("Hello_World"), "Should get the right class name");
-        assertEquals("", StringHelper.normalizeClassName("////"), "Should get the right class name");
-    }
-
-    @Test
-    public void testChangedLines() {
-        String oldText = "Hello\nWorld\nHow are you";
-        String newText = "Hello\nWorld\nHow are you";
-
-        List<Integer> changed = StringHelper.changedLines(oldText, newText);
-        assertEquals(0, changed.size());
-
-        oldText = "Hello\nWorld\nHow are you";
-        newText = "Hello\nWorld\nHow are you today";
-
-        changed = StringHelper.changedLines(oldText, newText);
-        assertEquals(1, changed.size());
-        assertEquals(2, changed.get(0).intValue());
-
-        oldText = "Hello\nWorld\nHow are you";
-        newText = "Hello\nCamel\nHow are you today";
-
-        changed = StringHelper.changedLines(oldText, newText);
-        assertEquals(2, changed.size());
-        assertEquals(1, changed.get(0).intValue());
-        assertEquals(2, changed.get(1).intValue());
-
-        oldText = "Hello\nWorld\nHow are you";
-        newText = "Hello\nWorld\nHow are you today\nand tomorrow";
-
-        changed = StringHelper.changedLines(oldText, newText);
-        assertEquals(2, changed.size());
-        assertEquals(2, changed.get(0).intValue());
-        assertEquals(3, changed.get(1).intValue());
-    }
-
-    @Test
-    public void testTrimToNull() {
-        assertEquals("abc", StringHelper.trimToNull("abc"));
-        assertEquals("abc", StringHelper.trimToNull(" abc"));
-        assertEquals("abc", StringHelper.trimToNull(" abc "));
-        assertNull(StringHelper.trimToNull(" "));
-        assertNull(StringHelper.trimToNull("\t"));
-        assertNull(StringHelper.trimToNull(" \t "));
-        assertNull(StringHelper.trimToNull(""));
-    }
-
-    @Test
-    public void testHumanReadableBytes() {
-        assertEquals("0 B", StringHelper.humanReadableBytes(Locale.ENGLISH, 0));
-        assertEquals("32 B", StringHelper.humanReadableBytes(Locale.ENGLISH, 32));
-        assertEquals("1.0 KB", StringHelper.humanReadableBytes(Locale.ENGLISH, 1024));
-        assertEquals("1.7 KB", StringHelper.humanReadableBytes(Locale.ENGLISH, 1730));
-        assertEquals("108.0 KB", StringHelper.humanReadableBytes(Locale.ENGLISH, 110592));
-        assertEquals("6.8 MB", StringHelper.humanReadableBytes(Locale.ENGLISH, 7077888));
-        assertEquals("432.0 MB", StringHelper.humanReadableBytes(Locale.ENGLISH, 452984832));
-        assertEquals("27.0 GB", StringHelper.humanReadableBytes(Locale.ENGLISH, 28991029248L));
-        assertEquals("1.7 TB", StringHelper.humanReadableBytes(Locale.ENGLISH, 1855425871872L));
-    }
-
-    @Test
-    public void testHumanReadableBytesNullLocale() {
-        assertEquals("1.3 KB", StringHelper.humanReadableBytes(null, 1280));
-    }
-
-    @Test
-    public void testHumanReadableBytesDefaultLocale() {
-        assertNotNull(StringHelper.humanReadableBytes(110592));
-    }
-
-    @Test
-    public void testCapitalizeDash() {
-        assertNull(StringHelper.dashToCamelCase(null));
-        assertEquals("", StringHelper.dashToCamelCase(""));
-        assertEquals("hello", StringHelper.dashToCamelCase("hello"));
-        assertEquals("helloGreat", StringHelper.dashToCamelCase("helloGreat"));
-        assertEquals("helloGreat", StringHelper.dashToCamelCase("hello-great"));
-        assertEquals("helloGreatWorld", StringHelper.dashToCamelCase("hello-great-world"));
-    }
-
-    public void testStartsWithIgnoreCase() {
-        assertTrue(StringHelper.startsWithIgnoreCase(null, null));
-        assertFalse(StringHelper.startsWithIgnoreCase("foo", null));
-        assertFalse(StringHelper.startsWithIgnoreCase(null, "bar"));
-        assertFalse(StringHelper.startsWithIgnoreCase("HelloWorld", "bar"));
-        assertTrue(StringHelper.startsWithIgnoreCase("HelloWorld", "Hello"));
-        assertTrue(StringHelper.startsWithIgnoreCase("HelloWorld", "hello"));
-        assertFalse(StringHelper.startsWithIgnoreCase("HelloWorld", "Helo"));
-        assertFalse(StringHelper.startsWithIgnoreCase("HelloWorld", "HelloWorld"));
-        assertTrue(StringHelper.startsWithIgnoreCase("HelloWorld", "helloWORLD"));
-        assertTrue(StringHelper.startsWithIgnoreCase("HelloWorld", "HELLO"));
-        assertTrue(StringHelper.startsWithIgnoreCase("helloworld", "helloWORLD"));
-        assertTrue(StringHelper.startsWithIgnoreCase("HELLOWORLD", "HELLO"));
-    }
-
-    @Test
-    public void testSplitAsStream() {
-        List<String> items = StringHelper.splitAsStream("a,b,c", ",").toList();
-        assertTrue(items.contains("a"));
-        assertTrue(items.contains("b"));
-        assertTrue(items.contains("c"));
-    }
-}
diff --git a/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java b/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
index 2a8a458ee7b..ac78aa0795e 100644
--- a/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
+++ b/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.util;
 
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
@@ -134,6 +135,16 @@ public class StringHelperTest {
         assertEquals("'", removeLeadingAndEndingQuotes("'"));
     }
 
+    @Test
+    public void testRemoveLeadingAndEndingQuotesWithSpaces() throws Exception {
+        assertNull(StringHelper.removeLeadingAndEndingQuotes(null));
+        assertEquals(" ", StringHelper.removeLeadingAndEndingQuotes(" "));
+        assertEquals("Hello World", StringHelper.removeLeadingAndEndingQuotes("Hello World"));
+        assertEquals("Hello World", StringHelper.removeLeadingAndEndingQuotes("'Hello World'"));
+        assertEquals("Hello World", StringHelper.removeLeadingAndEndingQuotes("\"Hello World\""));
+        assertEquals("Hello 'Camel'", StringHelper.removeLeadingAndEndingQuotes("Hello 'Camel'"));
+    }
+
     @Test
     public void testSplitOnCharacterAsList() throws Exception {
         List<String> list = splitOnCharacterAsList("foo", ',', 1);
@@ -234,4 +245,318 @@ public class StringHelperTest {
         assertEquals("----", StringHelper.fillChars('-', 4));
         assertEquals("..........", StringHelper.fillChars('.', 10));
     }
+
+    @Test
+    public void testSimpleSanitized() {
+        String out = StringHelper.sanitize("hello");
+        assertEquals(-1, out.indexOf(':'), "Should not contain : ");
+        assertEquals(-1, out.indexOf('.'), "Should not contain . ");
+    }
+
+    @Test
+    public void testNotFileFriendlySimpleSanitized() {
+        String out = StringHelper.sanitize("c:\\helloworld");
+        assertEquals(-1, out.indexOf(':'), "Should not contain : ");
+        assertEquals(-1, out.indexOf('.'), "Should not contain . ");
+    }
+
+    @Test
+    public void testSimpleCRLF() {
+        String out = StringHelper.removeCRLF("hello");
+        assertEquals("hello", out);
+        boolean b6 = !out.contains("\r");
+        assertTrue(b6, "Should not contain : ");
+        boolean b5 = !out.contains("\n");
+        assertTrue(b5, "Should not contain : ");
+
+        out = StringHelper.removeCRLF("hello\r\n");
+        assertEquals("hello", out);
+        boolean b4 = !out.contains("\r");
+        assertTrue(b4, "Should not contain : ");
+        boolean b3 = !out.contains("\n");
+        assertTrue(b3, "Should not contain : ");
+
+        out = StringHelper.removeCRLF("\r\nhe\r\nllo\n");
+        assertEquals("hello", out);
+        boolean b2 = !out.contains("\r");
+        assertTrue(b2, "Should not contain : ");
+        boolean b1 = !out.contains("\n");
+        assertTrue(b1, "Should not contain : ");
+
+        out = StringHelper.removeCRLF("hello" + System.lineSeparator());
+        assertEquals("hello", out);
+        boolean b = !out.contains(System.lineSeparator());
+        assertTrue(b, "Should not contain : ");
+    }
+
+    @Test
+    public void testCountChar() {
+        assertEquals(0, StringHelper.countChar("Hello World", 'x'));
+        assertEquals(1, StringHelper.countChar("Hello World", 'e'));
+        assertEquals(3, StringHelper.countChar("Hello World", 'l'));
+        assertEquals(1, StringHelper.countChar("Hello World", ' '));
+        assertEquals(0, StringHelper.countChar("", ' '));
+        assertEquals(0, StringHelper.countChar(null, ' '));
+    }
+
+    @Test
+    public void testRemoveQuotes() throws Exception {
+        assertEquals("Hello World", StringHelper.removeQuotes("Hello World"));
+        assertEquals("", StringHelper.removeQuotes(""));
+        assertNull(StringHelper.removeQuotes(null));
+        assertEquals(" ", StringHelper.removeQuotes(" "));
+        assertEquals("foo", StringHelper.removeQuotes("'foo'"));
+        assertEquals("foo", StringHelper.removeQuotes("'foo"));
+        assertEquals("foo", StringHelper.removeQuotes("foo'"));
+        assertEquals("foo", StringHelper.removeQuotes("\"foo\""));
+        assertEquals("foo", StringHelper.removeQuotes("\"foo"));
+        assertEquals("foo", StringHelper.removeQuotes("foo\""));
+        assertEquals("foo", StringHelper.removeQuotes("'foo\""));
+    }
+
+    @Test
+    public void testHasUpper() throws Exception {
+        assertFalse(StringHelper.hasUpperCase(null));
+        assertFalse(StringHelper.hasUpperCase(""));
+        assertFalse(StringHelper.hasUpperCase(" "));
+        assertFalse(StringHelper.hasUpperCase("com.foo"));
+        assertFalse(StringHelper.hasUpperCase("com.foo.123"));
+
+        assertTrue(StringHelper.hasUpperCase("com.foo.MyClass"));
+        assertTrue(StringHelper.hasUpperCase("com.foo.My"));
+
+        // Note, this is not a FQN
+        assertTrue(StringHelper.hasUpperCase("com.foo.subA"));
+    }
+
+    @Test
+    public void testIsClassName() throws Exception {
+        assertFalse(StringHelper.isClassName(null));
+        assertFalse(StringHelper.isClassName(""));
+        assertFalse(StringHelper.isClassName(" "));
+        assertFalse(StringHelper.isClassName("com.foo"));
+        assertFalse(StringHelper.isClassName("com.foo.123"));
+
+        assertTrue(StringHelper.isClassName("com.foo.MyClass"));
+        assertTrue(StringHelper.isClassName("com.foo.My"));
+
+        // Note, this is not a FQN
+        assertFalse(StringHelper.isClassName("com.foo.subA"));
+    }
+
+    @Test
+    public void testHasStartToken() throws Exception {
+        assertFalse(StringHelper.hasStartToken(null, null));
+        assertFalse(StringHelper.hasStartToken(null, "simple"));
+        assertFalse(StringHelper.hasStartToken("", null));
+        assertFalse(StringHelper.hasStartToken("", "simple"));
+        assertFalse(StringHelper.hasStartToken("Hello World", null));
+        assertFalse(StringHelper.hasStartToken("Hello World", "simple"));
+
+        assertFalse(StringHelper.hasStartToken("${body}", null));
+        assertTrue(StringHelper.hasStartToken("${body}", "simple"));
+        assertTrue(StringHelper.hasStartToken("$simple{body}", "simple"));
+
+        assertFalse(StringHelper.hasStartToken("${body}", null));
+        assertFalse(StringHelper.hasStartToken("${body}", "foo"));
+        // $foo{ is valid because its foo language
+        assertTrue(StringHelper.hasStartToken("$foo{body}", "foo"));
+    }
+
+    @Test
+    public void testIsQuoted() throws Exception {
+        assertFalse(StringHelper.isQuoted(null));
+        assertFalse(StringHelper.isQuoted(""));
+        assertFalse(StringHelper.isQuoted(" "));
+        assertFalse(StringHelper.isQuoted("abc"));
+        assertFalse(StringHelper.isQuoted("abc'"));
+        assertFalse(StringHelper.isQuoted("\"abc'"));
+        assertFalse(StringHelper.isQuoted("abc\""));
+        assertFalse(StringHelper.isQuoted("'abc\""));
+        assertFalse(StringHelper.isQuoted("\"abc'"));
+        assertFalse(StringHelper.isQuoted("abc'def'"));
+        assertFalse(StringHelper.isQuoted("abc'def'ghi"));
+        assertFalse(StringHelper.isQuoted("'def'ghi"));
+
+        assertTrue(StringHelper.isQuoted("'abc'"));
+        assertTrue(StringHelper.isQuoted("\"abc\""));
+    }
+
+    @Test
+    public void testRemoveInitialCharacters() throws Exception {
+        assertEquals("foo", StringHelper.removeStartingCharacters("foo", '/'));
+        assertEquals("foo", StringHelper.removeStartingCharacters("/foo", '/'));
+        assertEquals("foo", StringHelper.removeStartingCharacters("//foo", '/'));
+    }
+
+    @Test
+    public void testBefore() {
+        assertEquals("Hello ", StringHelper.before("Hello World", "World"));
+        assertEquals("Hello ", StringHelper.before("Hello World Again", "World"));
+        assertNull(StringHelper.before("Hello Again", "Foo"));
+
+        assertTrue(StringHelper.before("mykey:ignore", ":", "mykey"::equals).orElse(false));
+        assertFalse(StringHelper.before("ignore:ignore", ":", "mykey"::equals).orElse(false));
+
+        assertEquals("", StringHelper.before("Hello World", "Test", ""));
+        assertNull(StringHelper.before("Hello World", "Test", (String) null));
+
+        assertEquals("a:b", StringHelper.beforeLast("a:b:c", ":"));
+        assertEquals("", StringHelper.beforeLast("a:b:c", "_", ""));
+    }
+
+    @Test
+    public void testAfter() {
+        assertEquals(" World", StringHelper.after("Hello World", "Hello"));
+        assertEquals(" World Again", StringHelper.after("Hello World Again", "Hello"));
+        assertNull(StringHelper.after("Hello Again", "Foo"));
+
+        assertTrue(StringHelper.after("ignore:mykey", ":", "mykey"::equals).orElse(false));
+        assertFalse(StringHelper.after("ignore:ignore", ":", "mykey"::equals).orElse(false));
+
+        assertEquals("", StringHelper.after("Hello World", "Test", ""));
+        assertNull(StringHelper.after("Hello World", "Test", (String) null));
+
+        assertEquals("c", StringHelper.afterLast("a:b:c", ":"));
+        assertEquals("", StringHelper.afterLast("a:b:c", "_", ""));
+    }
+
+    @Test
+    public void testBetween() {
+        assertEquals("foo bar", StringHelper.between("Hello 'foo bar' how are you", "'", "'"));
+        assertEquals("foo bar", StringHelper.between("Hello ${foo bar} how are you", "${", "}"));
+        assertNull(StringHelper.between("Hello ${foo bar} how are you", "'", "'"));
+
+        assertTrue(StringHelper.between("begin:mykey:end", "begin:", ":end", "mykey"::equals).orElse(false));
+        assertFalse(StringHelper.between("begin:ignore:end", "begin:", ":end", "mykey"::equals).orElse(false));
+    }
+
+    @Test
+    public void testBetweenOuterPair() {
+        assertEquals("bar(baz)123", StringHelper.betweenOuterPair("foo(bar(baz)123)", '(', ')'));
+        assertNull(StringHelper.betweenOuterPair("foo(bar(baz)123))", '(', ')'));
+        assertNull(StringHelper.betweenOuterPair("foo(bar(baz123", '(', ')'));
+        assertNull(StringHelper.betweenOuterPair("foo)bar)baz123", '(', ')'));
+        assertEquals("bar", StringHelper.betweenOuterPair("foo(bar)baz123", '(', ')'));
+        assertEquals("'bar', 'baz()123', 123", StringHelper.betweenOuterPair("foo('bar', 'baz()123', 123)", '(', ')'));
+
+        assertTrue(StringHelper.betweenOuterPair("foo(bar)baz123", '(', ')', "bar"::equals).orElse(false));
+        assertFalse(StringHelper.betweenOuterPair("foo[bar)baz123", '(', ')', "bar"::equals).orElse(false));
+    }
+
+    @Test
+    public void testIsJavaIdentifier() {
+        assertTrue(StringHelper.isJavaIdentifier("foo"));
+        assertFalse(StringHelper.isJavaIdentifier("foo.bar"));
+        assertFalse(StringHelper.isJavaIdentifier(""));
+        assertFalse(StringHelper.isJavaIdentifier(null));
+    }
+
+    @Test
+    public void testNormalizeClassName() {
+        assertEquals("my.package-info", StringHelper.normalizeClassName("my.package-info"), "Should get the right class name");
+        assertEquals("Integer[]", StringHelper.normalizeClassName("Integer[] \r"), "Should get the right class name");
+        assertEquals("Hello_World", StringHelper.normalizeClassName("Hello_World"), "Should get the right class name");
+        assertEquals("", StringHelper.normalizeClassName("////"), "Should get the right class name");
+    }
+
+    @Test
+    public void testChangedLines() {
+        String oldText = "Hello\nWorld\nHow are you";
+        String newText = "Hello\nWorld\nHow are you";
+
+        List<Integer> changed = StringHelper.changedLines(oldText, newText);
+        assertEquals(0, changed.size());
+
+        oldText = "Hello\nWorld\nHow are you";
+        newText = "Hello\nWorld\nHow are you today";
+
+        changed = StringHelper.changedLines(oldText, newText);
+        assertEquals(1, changed.size());
+        assertEquals(2, changed.get(0).intValue());
+
+        oldText = "Hello\nWorld\nHow are you";
+        newText = "Hello\nCamel\nHow are you today";
+
+        changed = StringHelper.changedLines(oldText, newText);
+        assertEquals(2, changed.size());
+        assertEquals(1, changed.get(0).intValue());
+        assertEquals(2, changed.get(1).intValue());
+
+        oldText = "Hello\nWorld\nHow are you";
+        newText = "Hello\nWorld\nHow are you today\nand tomorrow";
+
+        changed = StringHelper.changedLines(oldText, newText);
+        assertEquals(2, changed.size());
+        assertEquals(2, changed.get(0).intValue());
+        assertEquals(3, changed.get(1).intValue());
+    }
+
+    @Test
+    public void testTrimToNull() {
+        assertEquals("abc", StringHelper.trimToNull("abc"));
+        assertEquals("abc", StringHelper.trimToNull(" abc"));
+        assertEquals("abc", StringHelper.trimToNull(" abc "));
+        assertNull(StringHelper.trimToNull(" "));
+        assertNull(StringHelper.trimToNull("\t"));
+        assertNull(StringHelper.trimToNull(" \t "));
+        assertNull(StringHelper.trimToNull(""));
+    }
+
+    @Test
+    public void testHumanReadableBytes() {
+        assertEquals("0 B", StringHelper.humanReadableBytes(Locale.ENGLISH, 0));
+        assertEquals("32 B", StringHelper.humanReadableBytes(Locale.ENGLISH, 32));
+        assertEquals("1.0 KB", StringHelper.humanReadableBytes(Locale.ENGLISH, 1024));
+        assertEquals("1.7 KB", StringHelper.humanReadableBytes(Locale.ENGLISH, 1730));
+        assertEquals("108.0 KB", StringHelper.humanReadableBytes(Locale.ENGLISH, 110592));
+        assertEquals("6.8 MB", StringHelper.humanReadableBytes(Locale.ENGLISH, 7077888));
+        assertEquals("432.0 MB", StringHelper.humanReadableBytes(Locale.ENGLISH, 452984832));
+        assertEquals("27.0 GB", StringHelper.humanReadableBytes(Locale.ENGLISH, 28991029248L));
+        assertEquals("1.7 TB", StringHelper.humanReadableBytes(Locale.ENGLISH, 1855425871872L));
+    }
+
+    @Test
+    public void testHumanReadableBytesNullLocale() {
+        assertEquals("1.3 KB", StringHelper.humanReadableBytes(null, 1280));
+    }
+
+    @Test
+    public void testHumanReadableBytesDefaultLocale() {
+        assertNotNull(StringHelper.humanReadableBytes(110592));
+    }
+
+    @Test
+    public void testCapitalizeDash() {
+        assertNull(StringHelper.dashToCamelCase(null));
+        assertEquals("", StringHelper.dashToCamelCase(""));
+        assertEquals("hello", StringHelper.dashToCamelCase("hello"));
+        assertEquals("helloGreat", StringHelper.dashToCamelCase("helloGreat"));
+        assertEquals("helloGreat", StringHelper.dashToCamelCase("hello-great"));
+        assertEquals("helloGreatWorld", StringHelper.dashToCamelCase("hello-great-world"));
+    }
+
+    @Test
+    public void testStartsWithIgnoreCase() {
+        assertTrue(StringHelper.startsWithIgnoreCase(null, null));
+        assertFalse(StringHelper.startsWithIgnoreCase("foo", null));
+        assertFalse(StringHelper.startsWithIgnoreCase(null, "bar"));
+        assertFalse(StringHelper.startsWithIgnoreCase("HelloWorld", "bar"));
+        assertTrue(StringHelper.startsWithIgnoreCase("HelloWorld", "Hello"));
+        assertTrue(StringHelper.startsWithIgnoreCase("HelloWorld", "hello"));
+        assertFalse(StringHelper.startsWithIgnoreCase("HelloWorld", "Helo"));
+        assertTrue(StringHelper.startsWithIgnoreCase("HelloWorld", "HelloWorld"));
+        assertTrue(StringHelper.startsWithIgnoreCase("HelloWorld", "helloWORLD"));
+        assertTrue(StringHelper.startsWithIgnoreCase("HelloWorld", "HELLO"));
+        assertTrue(StringHelper.startsWithIgnoreCase("helloworld", "helloWORLD"));
+        assertTrue(StringHelper.startsWithIgnoreCase("HELLOWORLD", "HELLO"));
+    }
+
+    @Test
+    public void testSplitAsStream() {
+        List<String> items = StringHelper.splitAsStream("a,b,c", ",").toList();
+        assertTrue(items.contains("a"));
+        assertTrue(items.contains("b"));
+        assertTrue(items.contains("c"));
+    }
 }


[camel] 01/04: (chores) camel-util: use Java native methods for padding/filling chars

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 10b0f9161b8460236a583746b783b71654839556
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Jun 16 13:11:23 2023 +0200

    (chores) camel-util: use Java native methods for padding/filling chars
---
 .../src/main/java/org/apache/camel/util/StringHelper.java      | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
index f91ba31c4a7..70e29a4a3a3 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
@@ -1157,10 +1157,7 @@ public final class StringHelper {
         if (level == 0) {
             return "";
         } else {
-            byte[] arr = new byte[level * blanks];
-            byte space = ' ';
-            Arrays.fill(arr, space);
-            return new String(arr);
+            return " ".repeat(level * blanks);
         }
     }
 
@@ -1174,10 +1171,7 @@ public final class StringHelper {
         if (count <= 0) {
             return "";
         } else {
-            byte[] arr = new byte[count];
-            byte b = (byte) ch;
-            Arrays.fill(arr, b);
-            return new String(arr);
+            return Character.toString(ch).repeat(count);
         }
     }
 


[camel] 02/04: (chores) camel-util: added missing test annotation

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 8e93fe10200d3ce291eefb19db83d4340e05239c
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Jun 16 13:12:22 2023 +0200

    (chores) camel-util: added missing test annotation
---
 .../camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java | 1 +
 1 file changed, 1 insertion(+)

diff --git a/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java b/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
index 70d6569ecc2..2a8a458ee7b 100644
--- a/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
+++ b/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
@@ -134,6 +134,7 @@ public class StringHelperTest {
         assertEquals("'", removeLeadingAndEndingQuotes("'"));
     }
 
+    @Test
     public void testSplitOnCharacterAsList() throws Exception {
         List<String> list = splitOnCharacterAsList("foo", ',', 1);
         assertEquals(1, list.size());


[camel] 04/04: (chores) camel-util: remove unused exceptions

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 83aa9070710555827b35b4d9cc05e4081e6525d8
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Jun 16 13:18:19 2023 +0200

    (chores) camel-util: remove unused exceptions
---
 .../org/apache/camel/util/StringHelperTest.java    | 42 +++++++++++-----------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java b/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
index ac78aa0795e..20ac66765f9 100644
--- a/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
+++ b/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
@@ -30,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.*;
 public class StringHelperTest {
 
     @Test
-    public void testCamelCashToDash() throws Exception {
+    public void testCamelCashToDash() {
         assertEquals(null, camelCaseToDash(null));
         assertEquals("", camelCaseToDash(""));
 
@@ -65,48 +65,48 @@ public class StringHelperTest {
     class DashToCamelCase {
 
         @Test
-        void testDashToCamelCaseWithNull() throws Exception {
+        void testDashToCamelCaseWithNull() {
             assertThat(dashToCamelCase(null)).isNull();
         }
 
         @Test
-        void testDashToCamelCaseWithEmptyValue() throws Exception {
+        void testDashToCamelCaseWithEmptyValue() {
             assertThat(dashToCamelCase("")).isEmpty();
         }
 
         @Test
-        void testDashToCamelCaseWithNoDash() throws Exception {
+        void testDashToCamelCaseWithNoDash() {
             assertThat(dashToCamelCase("a")).isEqualTo("a");
         }
 
         @Test
-        void testDashToCamelCaseWithOneDash() throws Exception {
+        void testDashToCamelCaseWithOneDash() {
             assertThat(dashToCamelCase("a-b")).isEqualTo("aB");
         }
 
         @Test
-        void testDashToCamelCaseWithSeveralDashes() throws Exception {
+        void testDashToCamelCaseWithSeveralDashes() {
             assertThat(dashToCamelCase("a-bb-cc-dd")).isEqualTo("aBbCcDd");
         }
 
         @Test
-        void testDashToCamelCaseWithEndDash() throws Exception {
+        void testDashToCamelCaseWithEndDash() {
             assertThat(dashToCamelCase("a-")).isEqualTo("a");
         }
 
         @Test
-        void testDashToCamelCaseWithEndDashes() throws Exception {
+        void testDashToCamelCaseWithEndDashes() {
             assertThat(dashToCamelCase("a----")).isEqualTo("a");
         }
 
         @Test
-        void testDashToCamelCaseWithSeceralDashesGrouped() throws Exception {
+        void testDashToCamelCaseWithSeceralDashesGrouped() {
             assertThat(dashToCamelCase("a--b")).isEqualTo("aB");
         }
     }
 
     @Test
-    public void testSplitWords() throws Exception {
+    public void testSplitWords() {
         String[] arr = splitWords("apiName/methodName");
         assertEquals(2, arr.length);
         assertEquals("apiName", arr[0]);
@@ -118,7 +118,7 @@ public class StringHelperTest {
     }
 
     @Test
-    public void testReplaceFirst() throws Exception {
+    public void testReplaceFirst() {
         assertEquals("jms:queue:bar", replaceFirst("jms:queue:bar", "foo", "bar"));
         assertEquals("jms:queue:bar", replaceFirst("jms:queue:foo", "foo", "bar"));
         assertEquals("jms:queue:bar?blah=123", replaceFirst("jms:queue:foo?blah=123", "foo", "bar"));
@@ -126,7 +126,7 @@ public class StringHelperTest {
     }
 
     @Test
-    public void testRemoveLeadingAndEndingQuotes() throws Exception {
+    public void testRemoveLeadingAndEndingQuotes() {
         assertEquals("abc", removeLeadingAndEndingQuotes("'abc'"));
         assertEquals("abc", removeLeadingAndEndingQuotes("\"abc\""));
         assertEquals("a'b'c", removeLeadingAndEndingQuotes("a'b'c"));
@@ -136,7 +136,7 @@ public class StringHelperTest {
     }
 
     @Test
-    public void testRemoveLeadingAndEndingQuotesWithSpaces() throws Exception {
+    public void testRemoveLeadingAndEndingQuotesWithSpaces() {
         assertNull(StringHelper.removeLeadingAndEndingQuotes(null));
         assertEquals(" ", StringHelper.removeLeadingAndEndingQuotes(" "));
         assertEquals("Hello World", StringHelper.removeLeadingAndEndingQuotes("Hello World"));
@@ -146,7 +146,7 @@ public class StringHelperTest {
     }
 
     @Test
-    public void testSplitOnCharacterAsList() throws Exception {
+    public void testSplitOnCharacterAsList() {
         List<String> list = splitOnCharacterAsList("foo", ',', 1);
         assertEquals(1, list.size());
         assertEquals("foo", list.get(0));
@@ -187,7 +187,7 @@ public class StringHelperTest {
     }
 
     @Test
-    public void testSplitOnCharacterAsIterator() throws Exception {
+    public void testSplitOnCharacterAsIterator() {
         Iterator<String> it = splitOnCharacterAsIterator("foo", ',', 1);
         assertEquals("foo", it.next());
         assertFalse(it.hasNext());
@@ -300,7 +300,7 @@ public class StringHelperTest {
     }
 
     @Test
-    public void testRemoveQuotes() throws Exception {
+    public void testRemoveQuotes() {
         assertEquals("Hello World", StringHelper.removeQuotes("Hello World"));
         assertEquals("", StringHelper.removeQuotes(""));
         assertNull(StringHelper.removeQuotes(null));
@@ -315,7 +315,7 @@ public class StringHelperTest {
     }
 
     @Test
-    public void testHasUpper() throws Exception {
+    public void testHasUpper() {
         assertFalse(StringHelper.hasUpperCase(null));
         assertFalse(StringHelper.hasUpperCase(""));
         assertFalse(StringHelper.hasUpperCase(" "));
@@ -330,7 +330,7 @@ public class StringHelperTest {
     }
 
     @Test
-    public void testIsClassName() throws Exception {
+    public void testIsClassName() {
         assertFalse(StringHelper.isClassName(null));
         assertFalse(StringHelper.isClassName(""));
         assertFalse(StringHelper.isClassName(" "));
@@ -345,7 +345,7 @@ public class StringHelperTest {
     }
 
     @Test
-    public void testHasStartToken() throws Exception {
+    public void testHasStartToken() {
         assertFalse(StringHelper.hasStartToken(null, null));
         assertFalse(StringHelper.hasStartToken(null, "simple"));
         assertFalse(StringHelper.hasStartToken("", null));
@@ -364,7 +364,7 @@ public class StringHelperTest {
     }
 
     @Test
-    public void testIsQuoted() throws Exception {
+    public void testIsQuoted() {
         assertFalse(StringHelper.isQuoted(null));
         assertFalse(StringHelper.isQuoted(""));
         assertFalse(StringHelper.isQuoted(" "));
@@ -383,7 +383,7 @@ public class StringHelperTest {
     }
 
     @Test
-    public void testRemoveInitialCharacters() throws Exception {
+    public void testRemoveInitialCharacters() {
         assertEquals("foo", StringHelper.removeStartingCharacters("foo", '/'));
         assertEquals("foo", StringHelper.removeStartingCharacters("/foo", '/'));
         assertEquals("foo", StringHelper.removeStartingCharacters("//foo", '/'));