package innovimax.mixthem.test001;

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

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() throws MixException, FileNotFoundException, IOException {
          ClassLoader classLoader = getClass().getClassLoader();
          File file1 = classLoader.getResource("file1.txt").getFile();
          File file2 = classLoader.getResource("file2.txt").getFile();
          ByteArrayOutputStream baos_rule_1 = new ByteArrayOutputStream();
          MixThem.processFiles(Constants.RULE_1, file1, file2, baos_rule_1);
          Assert.assertTrue(checkFileEquals(file1, baos_rule_1.toByteArray()));
          ByteArrayOutputStream baos_rule_2 = new ByteArrayOutputStream();
          MixThem.processFiles(Constants.RULE_2, file1, file2, baos_rule_2);
          Assert.assertTrue(checkFileEquals(file2, baos_rule_2.toByteArray()));
    }
	
    private static boolean checkFileEquals(File fileExpected, byte[] result) throws FileNotFoundException, IOException {
       FileInputStream fisExpected = new FileInputStream(fileExpected);
       int c;
       int offset = 0;
       while ((c = fisExpected.read()) != -1) {
	   if (offset >= result.length) return false;
          int d = result[offset++];
          if (c != d) return false;
       }
	   if (offset >= result.length) return false;
          int e = result[offset++];
       if (c != e) return false;
       return true;
    }

}

@@ -156,16 +156,37 @@
 va.io.*;
+%0Aimport java.net.URL;
 %0A%0Aimport
@@ -437,97 +437,87 @@
     
-ClassLoader classLoader = getClass().getClassLoader();%0A          File file1 = classLoader
+URL url1 = getClass().getResource(%22file1.txt%22);%0A          URL url2 = getClass()
 .get
@@ -530,23 +530,61 @@
 ce(%22file
-1
+2
 .txt%22)
+;%0A          File file1 = new File(url1
 .getFile
@@ -577,32 +577,33 @@
 e(url1.getFile()
+)
 ;%0A          File
@@ -615,44 +615,21 @@
 2 = 
-classLoader.getResource(%22file2.txt%22)
+new File(url2
 .get
@@ -634,16 +634,17 @@
 etFile()
+)
 ;%0A      
@@ -1387,17 +1387,24 @@
 = -1) %7B%0A
-%09
+        
    if (o
@@ -1447,24 +1447,25 @@
 ;%0A          
+ 
 int d = resu
@@ -1474,24 +1474,25 @@
 %5Boffset++%5D;%0A
+ 
           if
@@ -1524,17 +1524,20 @@
       %7D%0A
-%09
+    
    if (o
@@ -1535,33 +1535,32 @@
     if (offset %3E
-=
  result.length) 
@@ -1577,77 +1577,8 @@
 se;%0A
-          int e = result%5Boffset++%5D;%0A       if (c != e) return false;%0A
     

fix load resource and comparison