package picodedTests.utils;

import org.junit.*;

import static org.junit.Assert.*;

import picoded.utils.StreamRedirectThread;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.commons.io.IOUtils;

public class StreamRedirectThread_test {
    
    private StreamRedirectThread srt = null;
    private InputStream input = null;
    private OutputStream output = null;
    private File outputFile = null;
	
	@Before
	public void setUp() throws FileNotFoundException {
		File outputFolder = new File("./test-files/tmp/utils/StreamRedirectThread/");
		// makes the output directory tmporary folder as needed
		outputFolder.mkdirs();
		outputFile = new File(outputFolder, "outputFile.txt");
		
		input = new FileInputStream("./test-files/test-specific/utils/StreamRedirectThread/inputFile.txt");
		output = new FileOutputStream(outputFile);
		
		srt = new StreamRedirectThread(input, output);
	}
	
	@Test @SuppressWarnings("unchecked")
	public void runTest() throws IOException, FileNotFoundException {
		srt.start();
		
		assertTrue(outputFile.exists());
		assertEquals(IOUtils.toByteArray(input), IOUtils.toByteArray(new FileInputStream(outputFile)));
	}

}

@@ -369,16 +369,56 @@
 IOUtils;
+%0Aimport org.apache.commons.io.FileUtils;
 %0A%0Apublic
@@ -510,73 +510,35 @@
     
-private InputStream input = null;%0A    private OutputStream output
+%0A    private File inputFile
  = n
@@ -616,16 +616,29 @@
 ) throws
+ IOException,
  FileNot
@@ -654,16 +654,43 @@
 ption %7B%0A
+%09    // output file folder%0A
 %09%09File o
@@ -712,16 +712,17 @@
 ew File(
+ 
 %22./test-
@@ -759,19 +759,23 @@
 Thread/%22
+ 
 );%0A
+%09%09%0A
 %09%09// mak
@@ -849,16 +849,36 @@
 dirs();%0A
+%09%09%0A%09%09// output file%0A
 %09%09output
@@ -893,16 +893,17 @@
 ew File(
+ 
 outputFo
@@ -924,24 +924,25 @@
 ile.txt%22
+ 
 );%0A%09%09%0A%09%09
 input = 
@@ -937,36 +937,46 @@
 %09%0A%09%09
+// 
 input 
-= new FileInputStream(
+file%0A%09%09inputFile = new File( 
 %22./t
@@ -1044,21 +1044,82 @@
 txt%22
+ 
 );%0A%09%09
-output =
+%0A%09%09srt = new StreamRedirectThread( new FileInputStream( inputFile ),
  new
@@ -1128,32 +1128,33 @@
 ileOutputStream(
+ 
 outputFile);%0A%09%09%0A
@@ -1151,105 +1151,335 @@
 File
+ ) 
 );%0A%09
+%7D%0A
 %09%0A%09
-%09srt = new StreamRedirectThread(input, output
+@Test%0A%09public void runTest() throws IOException, FileNotFoundException %7B%0A%09%09srt.run();%0A%09%09%0A%09%09// output file should be exist%0A%09%09assertTrue( outputFile.exists() 
 );%0A%09
-%7D%0A%09%0A%09@Test @SuppressWarnings(%22unchecked%22)
+%09%0A%09%09// match contents of input and output files%0A%09%09assertEquals( FileUtils.readFileToString(inputFile), FileUtils.readFileToString(outputFile) );%0A%09%7D%0A%0A%09@Test
 %0A%09pu
@@ -1480,35 +1480,37 @@
 st%0A%09public void 
-run
+start
 Test() throws IO
@@ -1562,16 +1562,49 @@
 t();%0A%09%09%0A
+%09%09// output file should be exist%0A
 %09%09assert
@@ -1608,16 +1608,17 @@
 ertTrue(
+ 
 outputFi
@@ -1628,19 +1628,69 @@
 exists()
+ 
 );%0A
+%09%09%0A%09%09// match contents of input and output files%0A
 %09%09assert
@@ -1700,75 +1700,74 @@
 als(
-IO
+ File
 Utils.
-toByteArray(input), IOUtils.toByteArray(new FileInputStream
+readFileToString(inputFile), FileUtils.readFileToString
 (out
@@ -1774,17 +1774,17 @@
 putFile)
-)
+ 
 );%0A%09%7D%0A%0A%7D

test case added for start method