1616 */
1717package org .apache .commons .io .output ;
1818
19- import org .junit .Test ;
19+ import static org .junit .Assert .assertEquals ;
20+ import static org .junit .Assert .assertFalse ;
21+ import static org .junit .Assert .assertNotNull ;
22+ import static org .junit .Assert .assertNull ;
23+ import static org .junit .Assert .assertTrue ;
24+ import static org .junit .Assert .fail ;
2025
2126import java .io .File ;
2227import java .io .FileInputStream ;
2328import java .io .FileNotFoundException ;
2429import java .io .IOException ;
2530import java .util .Arrays ;
2631
27- import static org .junit .Assert .assertEquals ;
28- import static org .junit .Assert .assertFalse ;
29- import static org .junit .Assert .assertNotNull ;
30- import static org .junit .Assert .assertNull ;
31- import static org .junit .Assert .assertTrue ;
32- import static org .junit .Assert .fail ;
32+ import org .junit .Test ;
33+ import org .junit .runner .RunWith ;
34+ import org .junit .runners .Parameterized ;
35+ import org .junit .runners .Parameterized .Parameters ;
3336
3437/**
3538 * Unit tests for the <code>DeferredFileOutputStream</code> class.
3639 *
3740 * @version $Id$
3841 */
42+ @ RunWith (value =Parameterized .class )
3943public class DeferredFileOutputStreamTest
4044 {
4145
46+ @ Parameters (name = "initialBufferSize = {0}" )
47+ public static Iterable <Object []> data () {
48+ return Arrays .asList (new Object [][] { { 1 }, { 2 }, { 4 }, { 8 }, { 16 }, { 32 }, { 64 }, { 128 }, { 256 },
49+ { 512 }, { 1024 }, { 2048 }, { 4096 } });
50+ }
51+
52+ public DeferredFileOutputStreamTest (final int initialBufferSize ) {
53+ this .initialBufferSize = initialBufferSize ;
54+ }
4255 /**
4356 * The test data as a string (which is the simplest form).
4457 */
@@ -48,6 +61,8 @@ public class DeferredFileOutputStreamTest
4861 * The test data as a byte array, derived from the string.
4962 */
5063 private final byte [] testBytes = testString .getBytes ();
64+
65+ private final int initialBufferSize ;
5166
5267 /**
5368 * Tests the case where the amount of data falls below the threshold, and
@@ -57,7 +72,7 @@ public class DeferredFileOutputStreamTest
5772 public void testBelowThreshold ()
5873 {
5974 final DeferredFileOutputStream dfos =
60- new DeferredFileOutputStream (testBytes .length + 42 , null );
75+ new DeferredFileOutputStream (testBytes .length + 42 , initialBufferSize , null );
6176 try
6277 {
6378 dfos .write (testBytes , 0 , testBytes .length );
@@ -81,7 +96,7 @@ public void testBelowThreshold()
8196 @ Test
8297 public void testAtThreshold () {
8398 final DeferredFileOutputStream dfos =
84- new DeferredFileOutputStream (testBytes .length , null );
99+ new DeferredFileOutputStream (testBytes .length , initialBufferSize , null );
85100 try
86101 {
87102 dfos .write (testBytes , 0 , testBytes .length );
@@ -110,7 +125,7 @@ public void testAboveThreshold() {
110125 testFile .delete ();
111126
112127 final DeferredFileOutputStream dfos =
113- new DeferredFileOutputStream (testBytes .length - 5 , testFile );
128+ new DeferredFileOutputStream (testBytes .length - 5 , initialBufferSize , testFile );
114129 try
115130 {
116131 dfos .write (testBytes , 0 , testBytes .length );
@@ -141,7 +156,7 @@ public void testThresholdReached() {
141156 testFile .delete ();
142157
143158 final DeferredFileOutputStream dfos =
144- new DeferredFileOutputStream (testBytes .length / 2 , testFile );
159+ new DeferredFileOutputStream (testBytes .length / 2 , initialBufferSize , testFile );
145160 final int chunkSize = testBytes .length / 3 ;
146161
147162 try
@@ -171,12 +186,12 @@ public void testThresholdReached() {
171186 @ Test
172187 public void testWriteToSmall (){
173188 final File testFile = new File ("testWriteToMem.dat" );
174- final ByteArrayOutputStream baos = new ByteArrayOutputStream ();
189+ final ByteArrayOutputStream baos = new ByteArrayOutputStream (initialBufferSize );
175190 // Ensure that the test starts from a clean base.
176191 testFile .delete ();
177192
178193 final DeferredFileOutputStream dfos =
179- new DeferredFileOutputStream (testBytes .length *2 , testFile );
194+ new DeferredFileOutputStream (testBytes .length *2 , initialBufferSize , testFile );
180195 try {
181196 dfos .write (testBytes );
182197
@@ -207,7 +222,7 @@ public void testWriteToSmall(){
207222 @ Test
208223 public void testWriteToLarge (){
209224 final File testFile = new File ("testWriteToFile.dat" );
210- final ByteArrayOutputStream baos = new ByteArrayOutputStream ();
225+ final ByteArrayOutputStream baos = new ByteArrayOutputStream (initialBufferSize );
211226 // Ensure that the test starts from a clean base.
212227 testFile .delete ();
213228
@@ -247,7 +262,7 @@ public void testTempFileBelowThreshold() {
247262 final String suffix = ".out" ;
248263 final File tempDir = new File ("." );
249264 final DeferredFileOutputStream dfos =
250- new DeferredFileOutputStream (testBytes .length + 42 , prefix , suffix , tempDir );
265+ new DeferredFileOutputStream (testBytes .length + 42 , initialBufferSize , prefix , suffix , tempDir );
251266 assertNull ("Check file is null-A" , dfos .getFile ());
252267 try
253268 {
@@ -271,7 +286,7 @@ public void testTempFileAboveThreshold() {
271286 final String suffix = ".out" ;
272287 final File tempDir = new File ("." );
273288 final DeferredFileOutputStream dfos =
274- new DeferredFileOutputStream (testBytes .length - 5 , prefix , suffix , tempDir );
289+ new DeferredFileOutputStream (testBytes .length - 5 , initialBufferSize , prefix , suffix , tempDir );
275290 assertNull ("Check file is null-A" , dfos .getFile ());
276291 try
277292 {
@@ -305,7 +320,7 @@ public void testTempFileAboveThresholdPrefixOnly() {
305320 final String suffix = null ;
306321 final File tempDir = null ;
307322 final DeferredFileOutputStream dfos =
308- new DeferredFileOutputStream (testBytes .length - 5 , prefix , suffix , tempDir );
323+ new DeferredFileOutputStream (testBytes .length - 5 , initialBufferSize , prefix , suffix , tempDir );
309324 assertNull ("Check file is null-A" , dfos .getFile ());
310325 try
311326 {
0 commit comments