jmark109 commented on a change in pull request #206:
URL: https://github.com/apache/commons-io/pull/206#discussion_r580301256
##########
File path:
src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
fail("Unexpected IOException");
}
}
+
+ /**
+ * Tests the case where the amount of data falls below the threshold, and
is therefore confined to memory.
+ * Testing the getInputStream() method.
+ */
+ @ParameterizedTest(name = "initialBufferSize = {0}")
+ @MethodSource("data")
+ public void testBelowThresholdGetInputStream(final int initialBufferSize)
throws IOException {
+ final DeferredFileOutputStream dfos = new
DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,
+ null);
+ try {
+ dfos.write(testBytes, 0, testBytes.length);
+ dfos.close();
+ } catch (final IOException e) {
+ fail("Unexpected IOException");
+ }
+ assertTrue(dfos.isInMemory());
+
+ try(InputStream is = dfos.toInputStream()) {
+ final byte[] resultBytes = IOUtils.toByteArray(is);
+ assertArrayEquals(testBytes, resultBytes);
+ }
+ }
+
+ /**
+ * Tests the case where the amount of data exceeds the threshold, and is
therefore written to disk. The actual data
+ * written to disk is verified, as is the file itself.
+ * Testing the getInputStream() method.
+ */
+ @ParameterizedTest(name = "initialBufferSize = {0}")
+ @MethodSource("data")
+ public void testAboveThresholdGetInputStream(final int initialBufferSize,
@TempDir Path tempDir) throws IOException {
+ final File testFile =
tempDir.resolve("testAboveThreshold.dat").toFile();
+
+ final DeferredFileOutputStream dfos = new
DeferredFileOutputStream(testBytes.length - 5, initialBufferSize,
+ testFile);
+ try {
+ dfos.write(testBytes, 0, testBytes.length);
+ dfos.close();
+ } catch (final IOException e) {
+ fail("Unexpected IOException");
+ }
+ assertFalse(dfos.isInMemory());
+
+ try(InputStream is = dfos.toInputStream()) {
Review comment:
Fixed.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]