package innovimax.mixthem.test001;

import innovimax.mixthem.MixThem;
import innovimax.mixthem.Constants;

import java.io.*;

import org.junit.Assert;
import org.junit.Test;

/*
    Created by innovimax
    Generic tests for this application
*/
public class GenericTest {

	@Test
  	public final void check1() {
      ClassLoader classLoader = getClass().getClassLoader();
      File file1 = new File(classLoader.getResource("file1.txt").getFile());
      File file2 = new File(classLoader.getResource("file2.txt").getFile());
      Assert.assertTrue(checkFileEquals(file1, MixThem.processFiles(Constants.RULE_1, file1, file2)));
      Assert.assertTrue(checkFileEquals(file2, MixThem.processFiles(Constants.RULE_2, file1, file2)));
  	}
    private static boolean checkFileEquals(File fileExpected, File fileResult) {
       FileInputStream fisExpected = new FileInputStream(fileExpected);
       FileInputStream fisResult = new FileInputStream(fileResult);
       int c;
       while ((c = fisExpected.read()) != -1) {
          int d = fisResult.read();
          if (c != d) return false;
       }
       int e = fisResult.read();
       if (c != e) return false;
       return true;
    }

}

@@ -270,17 +270,19 @@
  %7B%0A%0A
-%09
+   
 @Test%0A  
 %09pub
@@ -277,17 +277,17 @@
 @Test%0A  
-%09
+ 
 public f
@@ -313,16 +313,20 @@
 %7B%0A      
+   
+ 
 ClassLoa
@@ -368,24 +368,28 @@
 ssLoader();%0A
+    
       File f
@@ -449,24 +449,28 @@
 getFile());%0A
+    
       File f
@@ -544,48 +544,86 @@
     
-Assert.assertTrue(checkFileEquals(file1,
+    ByteArrayOutputStream baos_rule_1 = new ByteArrayOutputStream();%0A         
  Mix
@@ -670,21 +670,36 @@
 1, file2
-)));%0A
+, baos_rule_1);%0A    
       As
@@ -738,70 +738,276 @@
 file
-2, MixThem.processFiles(Constants.RULE_2, file1, file2
+1, baos_rule_1.toByteArray()));%0A          ByteArrayOutputStream baos_rule_2 = new ByteArrayOutputStream();%0A          MixThem.processFiles(Constants.RULE_2, file1, file2, baos_rule_2);%0A          Assert.assertTrue(checkFileEquals(file2, baos_rule_2.toByteArray(
 )));%0A  
-%09
+  
 %7D%0A  
@@ -1070,18 +1070,16 @@
 ed, 
-File fileR
+byte%5B%5D r
 esul
@@ -1166,67 +1166,13 @@
     
-FileInputStream fisResult = new FileInputStream(fileResult)
+int c
 ;%0A  
@@ -1172,33 +1172,42 @@
 t c;%0A       int 
-c
+offset = 0
 ;%0A       while (
@@ -1236,24 +1236,71 @@
 )) != -1) %7B%0A
+%09   if (offset %3E= result.length) return false;%0A
           in
@@ -1305,32 +1305,30 @@
 int d = 
-fisResult.read()
+byte%5Boffset++%5D
 ;%0A      
@@ -1370,39 +1370,87 @@
   %7D%0A
-       int e = fisResult.read()
+%09   if (offset %3E= result.length) return false;%0A          int e = byte%5Boffset++%5D
 ;%0A  

use ByteArrayOutputStream