Skip to content

Commit 00a39a9

Browse files
committed
[IO-867] Add ThresholdingOutputStreamTest.testResetByteCount()
1 parent 9330932 commit 00a39a9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/test/java/org/apache/commons/io/output/ThresholdingOutputStreamTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.io.IOException;
2727
import java.io.OutputStream;
2828
import java.util.concurrent.atomic.AtomicBoolean;
29+
import java.util.concurrent.atomic.AtomicInteger;
2930

3031
import org.junit.jupiter.api.Test;
3132

@@ -49,6 +50,27 @@ static void assertThresholdingInitialState(final ThresholdingOutputStream out, f
4950
assertEquals(expectedByeCount, out.getByteCount());
5051
}
5152

53+
@Test
54+
public void testResetByteCount() throws Exception {
55+
final int threshold = 1;
56+
final AtomicInteger counter = new AtomicInteger();
57+
try (ByteArrayOutputStream os = new ByteArrayOutputStream(); ThresholdingOutputStream out = new ThresholdingOutputStream(threshold, tos -> {
58+
counter.incrementAndGet();
59+
tos.resetByteCount();
60+
}, o -> os)) {
61+
assertThresholdingInitialState(out, threshold, 0);
62+
assertEquals(0, counter.get());
63+
out.write('a');
64+
assertFalse(out.isThresholdExceeded());
65+
out.write('a');
66+
assertEquals(1, counter.get());
67+
assertFalse(out.isThresholdExceeded());
68+
out.write('a');
69+
out.write('a');
70+
assertEquals(3, counter.get());
71+
}
72+
}
73+
5274
@Test
5375
public void testSetByteCountOutputStream() throws Exception {
5476
final AtomicBoolean reached = new AtomicBoolean();

0 commit comments

Comments
 (0)