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

garydgregory 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 c6d867ec Refactor out the copy-pasta.
c6d867ec is described below

commit c6d867ec469ea6b1ed527909daa6d5b82e79e865
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Jun 2 06:44:01 2026 -0400

    Refactor out the copy-pasta.
---
 .../java/org/apache/commons/text/SpyReader.java    | 65 ++++++++++++++++++++++
 .../apache/commons/text/StrBuilderClearTest.java   | 46 ---------------
 .../commons/text/TextStringBuilderClearTest.java   | 46 ---------------
 3 files changed, 65 insertions(+), 92 deletions(-)

diff --git a/src/test/java/org/apache/commons/text/SpyReader.java 
b/src/test/java/org/apache/commons/text/SpyReader.java
new file mode 100644
index 00000000..8c01c298
--- /dev/null
+++ b/src/test/java/org/apache/commons/text/SpyReader.java
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import java.io.Reader;
+
+/**
+ * A Reader that, upon reading, inspects the char array it has been given 
access to (positions beyond offset+len that may contain stale data), records 
them,
+ * then supplies its normal data.
+ */
+class SpyReader extends Reader {
+
+    private boolean done;
+    private char[] observedExtra;
+    private final char[] supply;
+
+    SpyReader(final String supply) {
+        this.supply = supply.toCharArray();
+    }
+
+    @Override
+    public void close() {
+        // empty
+    }
+
+    boolean observedStaleChars(final String marker) {
+        if (observedExtra == null) {
+            return false;
+        }
+        return new String(observedExtra).contains(marker);
+    }
+
+    @Override
+    public int read(final char[] cbuf, final int off, final int len) {
+        if (done) {
+            return -1;
+        }
+        done = true;
+        // Record chars in the buffer beyond where we will write
+        final int toWrite = Math.min(supply.length, len);
+        final int staleStart = off + toWrite;
+        final int staleLen = cbuf.length - staleStart;
+        if (staleLen > 0) {
+            observedExtra = new char[staleLen];
+            System.arraycopy(cbuf, staleStart, observedExtra, 0, staleLen);
+        }
+        System.arraycopy(supply, 0, cbuf, off, toWrite);
+        return toWrite;
+    }
+}
diff --git a/src/test/java/org/apache/commons/text/StrBuilderClearTest.java 
b/src/test/java/org/apache/commons/text/StrBuilderClearTest.java
index b7708992..657ec8e7 100644
--- a/src/test/java/org/apache/commons/text/StrBuilderClearTest.java
+++ b/src/test/java/org/apache/commons/text/StrBuilderClearTest.java
@@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
-import java.io.Reader;
 import java.nio.charset.StandardCharsets;
 
 import org.apache.commons.lang3.CharUtils;
@@ -47,51 +46,6 @@ import org.junit.jupiter.api.Test;
 @SuppressWarnings("deprecation")
 public class StrBuilderClearTest {
 
-    /**
-     * A Reader that, upon reading, inspects the char array it has been given 
access to (positions beyond offset+len that may contain stale data), records 
them,
-     * then supplies its normal data.
-     */
-    static class SpyReader extends Reader {
-
-        private boolean done;
-        private char[] observedExtra;
-        private final char[] supply;
-
-        SpyReader(final String supply) {
-            this.supply = supply.toCharArray();
-        }
-
-        @Override
-        public void close() {
-            // empty
-        }
-
-        boolean observedStaleChars(final String marker) {
-            if (observedExtra == null) {
-                return false;
-            }
-            return new String(observedExtra).contains(marker);
-        }
-
-        @Override
-        public int read(final char[] cbuf, final int off, final int len) {
-            if (done) {
-                return -1;
-            }
-            done = true;
-            // Record chars in the buffer beyond where we will write
-            final int toWrite = Math.min(supply.length, len);
-            final int staleStart = off + toWrite;
-            final int staleLen = cbuf.length - staleStart;
-            if (staleLen > 0) {
-                observedExtra = new char[staleLen];
-                System.arraycopy(cbuf, staleStart, observedExtra, 0, staleLen);
-            }
-            System.arraycopy(supply, 0, cbuf, off, toWrite);
-            return toWrite;
-        }
-    }
-
     /** Search for a string encoded as UTF-16BE (2 bytes per char) in a byte 
array. */
     private static boolean containsUtf16Be(final byte[] haystack, final String 
needle) throws IOException {
         final byte[] needleBytes = needle.getBytes(StandardCharsets.UTF_16BE);
diff --git 
a/src/test/java/org/apache/commons/text/TextStringBuilderClearTest.java 
b/src/test/java/org/apache/commons/text/TextStringBuilderClearTest.java
index 07d0af98..7bf1b41a 100644
--- a/src/test/java/org/apache/commons/text/TextStringBuilderClearTest.java
+++ b/src/test/java/org/apache/commons/text/TextStringBuilderClearTest.java
@@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
-import java.io.Reader;
 import java.nio.charset.StandardCharsets;
 
 import org.apache.commons.lang3.CharUtils;
@@ -43,51 +42,6 @@ import org.junit.jupiter.api.Test;
  */
 public class TextStringBuilderClearTest {
 
-    /**
-     * A Reader that, upon reading, inspects the char array it has been given 
access to (positions beyond offset+len that may contain stale data), records 
them,
-     * then supplies its normal data.
-     */
-    static class SpyReader extends Reader {
-
-        private boolean done;
-        private char[] observedExtra;
-        private final char[] supply;
-
-        SpyReader(final String supply) {
-            this.supply = supply.toCharArray();
-        }
-
-        @Override
-        public void close() {
-            // empty
-        }
-
-        boolean observedStaleChars(final String marker) {
-            if (observedExtra == null) {
-                return false;
-            }
-            return new String(observedExtra).contains(marker);
-        }
-
-        @Override
-        public int read(final char[] cbuf, final int off, final int len) {
-            if (done) {
-                return -1;
-            }
-            done = true;
-            // Record chars in the buffer beyond where we will write
-            final int toWrite = Math.min(supply.length, len);
-            final int staleStart = off + toWrite;
-            final int staleLen = cbuf.length - staleStart;
-            if (staleLen > 0) {
-                observedExtra = new char[staleLen];
-                System.arraycopy(cbuf, staleStart, observedExtra, 0, staleLen);
-            }
-            System.arraycopy(supply, 0, cbuf, off, toWrite);
-            return toWrite;
-        }
-    }
-
     /** Search for a string encoded as UTF-16BE (2 bytes per char) in a byte 
array. */
     private static boolean containsUtf16Be(final byte[] haystack, final String 
needle) {
         final byte[] needleBytes = needle.getBytes(StandardCharsets.UTF_16BE);

Reply via email to