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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git


The following commit(s) were added to refs/heads/master by this push:
     new 13fe3912 Added new test for CharSequenceTranslator#with. (#725)
13fe3912 is described below

commit 13fe39124867d03110513304edda1312c5c6f0db
Author: Michael Hausegger <[email protected]>
AuthorDate: Fri Nov 21 23:22:10 2025 +0100

    Added new test for CharSequenceTranslator#with. (#725)
    
    * Added new test for CharSequenceTranslator#with.
    
    * Fixed typo
    
    * Reduce whitespace
    
    ---------
    
    Co-authored-by: TheRealHaui <[email protected]>
    Co-authored-by: Gary Gregory <[email protected]>
---
 src/changes/changes.xml                            |  2 +-
 .../text/translate/CharSequenceTranslatorTest.java | 53 ++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ef5abe56..e9c6b331 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -49,7 +49,7 @@ The <action> type attribute can be add,update,fix,remove.
     <!-- FIX -->
     <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix exception 
message typo in XmlStringLookup.XmlStringLookup(Map, Path...).</action>
     <action type="fix" dev="ggregory" due-to="Pierre Post, Sumit Bera, Alex 
Herbert, Gary Gregory" issue="TEXT-236">Inserting at the end of a 
TextStringBuilder throws a StringIndexOutOfBoundsException.</action>
-    <action type="fix" dev="ggregory" due-to="GMichael Hausegger">Fix 
TextStringBuilderTest.testAppendToCharBuffer() to use proper argument type 
#724.</action>
+    <action type="fix" dev="ggregory" due-to="Michael Hausegger">Fix 
TextStringBuilderTest.testAppendToCharBuffer() to use proper argument type 
#724.</action>
     <!-- ADD -->
     <action type="add" dev="ggregory" due-to="Piotr P. Karwasz, Gary 
Gregory">Add experimental CycloneDX VEX file #683.</action>
     <action type="add" dev="ggregory" due-to="LorgeN, Gary Gregory" 
issue="TEXT-235">Add Damerau-Levenshtein distance #687.</action>
diff --git 
a/src/test/java/org/apache/commons/text/translate/CharSequenceTranslatorTest.java
 
b/src/test/java/org/apache/commons/text/translate/CharSequenceTranslatorTest.java
new file mode 100644
index 00000000..8bc38cae
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/text/translate/CharSequenceTranslatorTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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
+ *
+ *      https://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.commons.text.translate;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.junit.jupiter.api.Test;
+
+
+class CharSequenceTranslatorTest {
+
+    //Used to count translate invocations
+    private int translateInvocationCounter;
+
+    @Test
+    void testWith() throws IOException {
+        CharSequenceTranslator charSequenceTranslatorOne = new 
TestCharSequenceTranslator();
+        CharSequenceTranslator charSequenceTranslatorTwo = new 
TestCharSequenceTranslator();
+        CharSequenceTranslator charSequenceTranslatorThree = new 
TestCharSequenceTranslator();
+        CharSequenceTranslator aggregatedTranslator = 
charSequenceTranslatorOne.with(charSequenceTranslatorTwo, 
charSequenceTranslatorThree);
+        aggregatedTranslator.translate("", 0, null);
+        assertTrue(aggregatedTranslator instanceof AggregateTranslator);
+        assertEquals(3, translateInvocationCounter);
+    }
+
+    private final class TestCharSequenceTranslator extends 
CharSequenceTranslator {
+        @Override
+        public int translate(final CharSequence input, final int index, final 
Writer writer) {
+            translateInvocationCounter++;
+            return 0;
+        }
+
+    }
+
+}

Reply via email to