You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/08/14 21:13:03 UTC

(commons-io) branch master updated: Add ProxyOutputStream tests

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-io.git


The following commit(s) were added to refs/heads/master by this push:
     new ec5e2e12f Add ProxyOutputStream tests
ec5e2e12f is described below

commit ec5e2e12fa1b98086a22d777f5e471da69f2244c
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Thu Aug 14 17:12:57 2025 -0400

    Add ProxyOutputStream tests
    
    Javadoc
---
 .../commons/io/output/ProxyOutputStreamTest.java   | 50 ++++++++++++++++------
 1 file changed, 38 insertions(+), 12 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java b/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java
index 4f120af3c..67a2f3373 100644
--- a/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java
@@ -30,7 +30,7 @@
 import org.junit.jupiter.api.Test;
 
 /**
- * Tests {@link CloseShieldOutputStream}.
+ * Tests {@link ProxyOutputStream}.
  */
 class ProxyOutputStreamTest {
 
@@ -38,7 +38,9 @@ class ProxyOutputStreamTest {
 
     private ProxyOutputStream proxied;
 
-    private final AtomicBoolean hit = new AtomicBoolean();
+    private final AtomicBoolean hitByteArray = new AtomicBoolean();
+    private final AtomicBoolean hitByteArrayAt = new AtomicBoolean();
+    private final AtomicBoolean hitInt = new AtomicBoolean();
 
     @BeforeEach
     public void setUp() {
@@ -46,13 +48,19 @@ public void setUp() {
 
             @Override
             public void write(final byte[] ba) {
-                hit.set(true);
+                hitByteArray.set(true);
                 super.write(ba);
             }
 
+            @Override
+            public void write(final byte[] b, final int off, final int len) {
+                hitByteArrayAt.set(true);
+                super.write(b, off, len);
+            }
+
             @Override
             public synchronized void write(final int ba) {
-                hit.set(true);
+                hitInt.set(true);
                 super.write(ba);
             }
         };
@@ -67,30 +75,48 @@ void testBuilder() throws Exception {
     @SuppressWarnings("resource")
     @Test
     void testSetReference() throws Exception {
-        assertFalse(hit.get());
+        assertFalse(hitByteArray.get());
         proxied.setReference(new ByteArrayOutputStream());
         proxied.write('y');
-        assertFalse(hit.get());
+        assertFalse(hitByteArray.get());
         assertEquals(0, original.size());
         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, original.toByteArray());
     }
 
     @Test
-    void testWrite() throws Exception {
-        assertFalse(hit.get());
+    void testWriteByteArray() throws Exception {
+        assertFalse(hitByteArray.get());
+        proxied.write(new byte[] { 'y', 'z' });
+        assertTrue(hitByteArray.get());
+        assertEquals(2, original.size());
+        assertArrayEquals(new byte[] { 'y', 'z' }, original.toByteArray());
+    }
+
+    @Test
+    void testWriteByteArrayAt() throws Exception {
+        assertFalse(hitByteArrayAt.get());
+        proxied.write(new byte[] { 'y', 'z' }, 1, 1);
+        assertTrue(hitByteArrayAt.get());
+        assertEquals(1, original.size());
+        assertArrayEquals(new byte[] { 'z' }, original.toByteArray());
+    }
+
+    @Test
+    void testWriteInt() throws Exception {
+        assertFalse(hitInt.get());
         proxied.write('y');
-        assertTrue(hit.get());
+        assertTrue(hitInt.get());
         assertEquals(1, original.size());
         assertEquals('y', original.toByteArray()[0]);
     }
 
     @Test
     void testWriteNullArrayProxiesToUnderlying() throws Exception {
-        assertFalse(hit.get());
+        assertFalse(hitByteArray.get());
         final byte[] ba = null;
         assertThrows(NullPointerException.class, () -> original.write(ba));
-        assertTrue(hit.get());
+        assertTrue(hitByteArray.get());
         assertThrows(NullPointerException.class, () -> proxied.write(ba));
-        assertTrue(hit.get());
+        assertTrue(hitByteArray.get());
     }
 }