Merge branch 'master' into release
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 5d17e4e..1317b1c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -52,7 +52,7 @@
<action dev="ggregory" type="fix" issue="IO-851" due-to="Sebb, Gary Gregory">FileSystemUtils no longer throws IllegalStateException.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid possible NullPointerException in FileUtils.listAccumulate(File, IOFileFilter, IOFileFilter, FileVisitOption...).</action>
<action dev="ggregory" type="fix" issue="IO-853" due-to="Mike Drob, Gary Gregory">BoundedInputStream.reset() not updating count.</action>
- <action dev="ggregory" type="fix" due-to="rproserpio, Gary Gregory">ThresholdingOutputStream: a negative threshold should behave like a zero threshold and trigger the event on the first write #609.</action>
+ <action dev="ggregory" type="fix" issue="IO-854" due-to="rproserpio, Bill Orpet, Gary Gregory">ThresholdingOutputStream: a negative threshold should behave like a zero threshold and trigger the event on the first write #609.</action>
<!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Gary Gregory">Bump commons.bytebuddy.version from 1.14.12 to 1.14.13 #605.</action>
<action dev="ggregory" type="update" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 67 to 69 #608.</action>
diff --git a/src/test/java/org/apache/commons/io/file/AbstractPathWrapper.java b/src/test/java/org/apache/commons/io/file/AbstractPathWrapper.java
index 4c5857c..ef7ba41 100644
--- a/src/test/java/org/apache/commons/io/file/AbstractPathWrapper.java
+++ b/src/test/java/org/apache/commons/io/file/AbstractPathWrapper.java
@@ -81,11 +81,6 @@
return Objects.equals(path, other.path);
}
- @Override
- public void forEach(final Consumer<? super Path> action) {
- path.forEach(action);
- }
-
/**
* Delegates to {@link Files#exists(Path, LinkOption...)}.
*
@@ -96,6 +91,11 @@
return Files.exists(path, options);
}
+ @Override
+ public void forEach(final Consumer<? super Path> action) {
+ path.forEach(action);
+ }
+
/**
* Gets the delegate Path.
*
diff --git a/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java b/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
index d412845..7cbeeed 100644
--- a/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
@@ -105,28 +105,6 @@
}
/**
- * Tests the case where the threshold is negative, and therefore the data is always written to disk. The actual data
- * written to disk is verified, as is the file itself.
- */
- @ParameterizedTest(name = "initialBufferSize = {0}")
- @MethodSource("data")
- public void testThresholdNegative(final int initialBufferSize) throws IOException {
- final File testFile = Files.createTempFile(tempDirPath, "testThresholdNegative", "dat").toFile();
- try (DeferredFileOutputStream dfos = DeferredFileOutputStream.builder()
- .setThreshold(-1)
- .setBufferSize(initialBufferSize)
- .setOutputFile(testFile)
- .get()) {
- dfos.write(testBytes, 0, testBytes.length);
- dfos.close();
- assertFalse(dfos.isInMemory());
- assertNull(dfos.getData());
- assertEquals(testFile.length(), dfos.getByteCount());
- verifyResultFile(testFile);
- }
- }
-
- /**
* Tests the case where the amount of data is exactly the same as the threshold. The behavior should be the same as
* that for the amount of data being below (i.e. not exceeding) the threshold.
*/
@@ -300,6 +278,28 @@
}
/**
+ * Tests the case where the threshold is negative, and therefore the data is always written to disk. The actual data
+ * written to disk is verified, as is the file itself.
+ */
+ @ParameterizedTest(name = "initialBufferSize = {0}")
+ @MethodSource("data")
+ public void testThresholdNegative(final int initialBufferSize) throws IOException {
+ final File testFile = Files.createTempFile(tempDirPath, "testThresholdNegative", "dat").toFile();
+ try (DeferredFileOutputStream dfos = DeferredFileOutputStream.builder()
+ .setThreshold(-1)
+ .setBufferSize(initialBufferSize)
+ .setOutputFile(testFile)
+ .get()) {
+ dfos.write(testBytes, 0, testBytes.length);
+ dfos.close();
+ assertFalse(dfos.isInMemory());
+ assertNull(dfos.getData());
+ assertEquals(testFile.length(), dfos.getByteCount());
+ verifyResultFile(testFile);
+ }
+ }
+
+ /**
* Tests the case where there are multiple writes beyond the threshold, to ensure that the
* {@code thresholdReached()} method is only called once, as the threshold is crossed for the first time.
* @throws IOException
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 4391643..bf94520 100644
--- a/src/test/java/org/apache/commons/io/output/ThresholdingOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/output/ThresholdingOutputStreamTest.java
@@ -32,63 +32,6 @@
*/
public class ThresholdingOutputStreamTest {
- /**
- * Tests the case where the threshold is negative.
- * The threshold is not reached until something is written to the stream.
- */
- @Test
- public void testThresholdLessThanZero() throws IOException {
- final AtomicBoolean reached = new AtomicBoolean();
- try (final ThresholdingOutputStream out = new ThresholdingOutputStream(-1) {
- @Override
- protected void thresholdReached() throws IOException {
- reached.set(true);
- }
- }) {
- assertFalse(reached.get());
- out.write(89);
- assertTrue(reached.get());
- assertTrue(out.isThresholdExceeded());
- }
- }
-
- /**
- * Tests the case where no bytes are written.
- * The threshold is not reached until something is written to the stream.
- */
- @Test
- public void testThresholdZeroWrite() throws IOException {
- final AtomicBoolean reached = new AtomicBoolean();
- try (final ThresholdingOutputStream out = new ThresholdingOutputStream(7) {
- @Override
- protected void thresholdReached() throws IOException {
- reached.set(true);
- }
- }) {
- assertFalse(out.isThresholdExceeded());
- assertFalse(reached.get());
- out.write(new byte[0]);
- assertFalse(out.isThresholdExceeded());
- assertFalse(reached.get());
- }
- }
-
- @Test
- public void testThresholdZero() throws IOException {
- final AtomicBoolean reached = new AtomicBoolean();
- try (final ThresholdingOutputStream out = new ThresholdingOutputStream(0) {
- @Override
- protected void thresholdReached() throws IOException {
- reached.set(true);
- }
- }) {
- assertFalse(out.isThresholdExceeded());
- out.write(89);
- assertTrue(reached.get());
- assertTrue(out.isThresholdExceeded());
- }
- }
-
@Test
public void testSetByteCount_OutputStream() throws Exception {
final AtomicBoolean reached = new AtomicBoolean();
@@ -189,4 +132,61 @@
assertThrows(IllegalStateException.class, () -> tos.write('a'));
}
}
+
+ /**
+ * Tests the case where the threshold is negative.
+ * The threshold is not reached until something is written to the stream.
+ */
+ @Test
+ public void testThresholdLessThanZero() throws IOException {
+ final AtomicBoolean reached = new AtomicBoolean();
+ try (final ThresholdingOutputStream out = new ThresholdingOutputStream(-1) {
+ @Override
+ protected void thresholdReached() throws IOException {
+ reached.set(true);
+ }
+ }) {
+ assertFalse(reached.get());
+ out.write(89);
+ assertTrue(reached.get());
+ assertTrue(out.isThresholdExceeded());
+ }
+ }
+
+ @Test
+ public void testThresholdZero() throws IOException {
+ final AtomicBoolean reached = new AtomicBoolean();
+ try (final ThresholdingOutputStream out = new ThresholdingOutputStream(0) {
+ @Override
+ protected void thresholdReached() throws IOException {
+ reached.set(true);
+ }
+ }) {
+ assertFalse(out.isThresholdExceeded());
+ out.write(89);
+ assertTrue(reached.get());
+ assertTrue(out.isThresholdExceeded());
+ }
+ }
+
+ /**
+ * Tests the case where no bytes are written.
+ * The threshold is not reached until something is written to the stream.
+ */
+ @Test
+ public void testThresholdZeroWrite() throws IOException {
+ final AtomicBoolean reached = new AtomicBoolean();
+ try (final ThresholdingOutputStream out = new ThresholdingOutputStream(7) {
+ @Override
+ protected void thresholdReached() throws IOException {
+ reached.set(true);
+ }
+ }) {
+ assertFalse(out.isThresholdExceeded());
+ assertFalse(reached.get());
+ out.write(new byte[0]);
+ assertFalse(out.isThresholdExceeded());
+ assertFalse(reached.get());
+ }
+ }
}
\ No newline at end of file