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 74dd3950b [IO-867] Fix ThresholdingOutputStream#isThresholdExceeded
74dd3950b is described below

commit 74dd3950b0f7eb94ebad11197a1a316475ce0593
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Wed Feb 5 17:16:31 2025 -0500

    [IO-867] Fix ThresholdingOutputStream#isThresholdExceeded
    
    Add assertions
---
 .../io/output/ThresholdingOutputStreamTest.java    | 31 ++++++++++++++++++----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/io/output/ThresholdingOutputStreamTest.java 
b/src/test/java/org/apache/commons/io/output/ThresholdingOutputStreamTest.java
index fd0c415a5..a04ba0b65 100644
--- 
a/src/test/java/org/apache/commons/io/output/ThresholdingOutputStreamTest.java
+++ 
b/src/test/java/org/apache/commons/io/output/ThresholdingOutputStreamTest.java
@@ -19,6 +19,7 @@
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -71,8 +72,10 @@ protected void thresholdReached() throws IOException {
             assertThresholdingInitialState(out, threshold, initCount);
             out.write('a');
             assertFalse(reached.get());
+            assertFalse(out.isThresholdExceeded());
             out.write('a');
             assertTrue(reached.get());
+            assertTrue(out.isThresholdExceeded());
         }
     }
 
@@ -99,33 +102,36 @@ protected void thresholdReached() throws IOException {
             assertThresholdingInitialState(out, threshold, initCount);
             out.write('a');
             assertFalse(reached.get());
+            assertFalse(out.isThresholdExceeded());
             out.write('a');
             assertTrue(reached.get());
+            assertTrue(out.isThresholdExceeded());
         }
     }
 
     @Test
     public void testThresholdIOConsumer() throws Exception {
-        final AtomicBoolean reached = new AtomicBoolean();
-        // Null threshold consumer
-        reached.set(false);
         final int threshold = 1;
+        // Null threshold consumer
         try (ThresholdingOutputStream out = new 
ThresholdingOutputStream(threshold, null,
             os -> new ByteArrayOutputStream(4))) {
             assertThresholdingInitialState(out, threshold, 0);
             out.write('a');
-            assertFalse(reached.get());
+            assertFalse(out.isThresholdExceeded());
             out.write('a');
-            assertFalse(reached.get());
+            assertTrue(out.isThresholdExceeded());
         }
         // Null output stream function
+        final AtomicBoolean reached = new AtomicBoolean();
         reached.set(false);
         try (ThresholdingOutputStream out = new 
ThresholdingOutputStream(threshold, os -> reached.set(true), null)) {
             assertThresholdingInitialState(out, threshold, 0);
             out.write('a');
             assertFalse(reached.get());
+            assertFalse(out.isThresholdExceeded());
             out.write('a');
             assertTrue(reached.get());
+            assertTrue(out.isThresholdExceeded());
         }
         // non-null inputs.
         reached.set(false);
@@ -134,8 +140,10 @@ public void testThresholdIOConsumer() throws Exception {
             assertThresholdingInitialState(out, threshold, 0);
             out.write('a');
             assertFalse(reached.get());
+            assertFalse(out.isThresholdExceeded());
             out.write('a');
             assertTrue(reached.get());
+            assertTrue(out.isThresholdExceeded());
         }
     }
 
@@ -147,7 +155,9 @@ public void testThresholdIOConsumerIOException() throws 
Exception {
         }, os -> new ByteArrayOutputStream(4))) {
             assertThresholdingInitialState(out, threshold, 0);
             out.write('a');
+            assertFalse(out.isThresholdExceeded());
             assertThrows(IOException.class, () -> out.write('a'));
+            assertFalse(out.isThresholdExceeded());
         }
     }
 
@@ -159,7 +169,11 @@ public void testThresholdIOConsumerUncheckedException() 
throws Exception {
         }, os -> new ByteArrayOutputStream(4))) {
             assertThresholdingInitialState(out, threshold, 0);
             out.write('a');
+            assertFalse(out.isThresholdExceeded());
             assertThrows(IllegalStateException.class, () -> out.write('a'));
+            assertFalse(out.isThresholdExceeded());
+            assertInstanceOf(ByteArrayOutputStream.class, 
out.getOutputStream());
+            assertFalse(out.isThresholdExceeded());
         }
     }
 
@@ -181,6 +195,8 @@ protected void thresholdReached() throws IOException {
             out.write(89);
             assertTrue(reached.get());
             assertTrue(out.isThresholdExceeded());
+            assertInstanceOf(NullOutputStream.class, out.getOutputStream());
+            assertTrue(out.isThresholdExceeded());
         }
     }
 
@@ -198,6 +214,8 @@ protected void thresholdReached() throws IOException {
             out.write(89);
             assertTrue(reached.get());
             assertTrue(out.isThresholdExceeded());
+            assertInstanceOf(NullOutputStream.class, out.getOutputStream());
+            assertTrue(out.isThresholdExceeded());
         }
     }
 
@@ -212,6 +230,7 @@ public void testThresholdZeroWrite() throws IOException {
         try (final ThresholdingOutputStream out = new 
ThresholdingOutputStream(threshold) {
             @Override
             protected void thresholdReached() throws IOException {
+                super.thresholdReached();
                 reached.set(true);
             }
         }) {
@@ -220,6 +239,8 @@ protected void thresholdReached() throws IOException {
             out.write(new byte[0]);
             assertFalse(out.isThresholdExceeded());
             assertFalse(reached.get());
+            assertInstanceOf(NullOutputStream.class, out.getOutputStream());
+            assertFalse(out.isThresholdExceeded());
         }
     }
 }
\ No newline at end of file

Reply via email to