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
commit a66cb84a1fcfdc060f38f57674bc80e3e4485f35 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Thu Apr 4 19:56:37 2024 -0400 Sort members --- .../commons/io/file/AbstractPathWrapper.java | 10 +- .../io/output/DeferredFileOutputStreamTest.java | 44 ++++---- .../io/output/ThresholdingOutputStreamTest.java | 114 ++++++++++----------- 3 files changed, 84 insertions(+), 84 deletions(-) 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 4c5857c49..ef7ba4190 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 @@ public abstract class AbstractPathWrapper implements Path { 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 @@ public abstract class AbstractPathWrapper implements Path { 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 d4128455d..7cbeeedeb 100644 --- a/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java +++ b/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java @@ -104,28 +104,6 @@ public class DeferredFileOutputStreamTest extends AbstractTempDirTest { } } - /** - * 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. @@ -299,6 +277,28 @@ public class DeferredFileOutputStreamTest extends AbstractTempDirTest { assertThrows(NullPointerException.class, () -> new DeferredFileOutputStream(testBytes.length - 5, prefix, suffix, tempDirFile)); } + /** + * 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. 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 43916438d..bf94520f7 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 @@ import org.junit.jupiter.api.Test; */ 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 @@ public class ThresholdingOutputStreamTest { 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