Skip to content

Commit bfa3f34

Browse files
authored
Merge pull request #24 from Innovimax-SARL/innovimax-add-resources-for-test
Create generic test
2 parents f71e673 + 6d9fd89 commit bfa3f34

File tree

6 files changed

+108
-0
lines changed

6 files changed

+108
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package innovimax.mixthem.test001;
2+
3+
import innovimax.mixthem.MixThem;
4+
import innovimax.mixthem.Constants;
5+
import innovimax.mixthem.MixException;
6+
7+
import java.io.*;
8+
import java.net.URL;
9+
10+
import org.junit.Assert;
11+
import org.junit.Test;
12+
13+
/*
14+
Created by innovimax
15+
Generic tests for this application
16+
*/
17+
public class GenericTest {
18+
19+
@Test
20+
public final void check1() throws MixException, FileNotFoundException, IOException {
21+
URL url1 = getClass().getResource("file1.txt");
22+
URL url2 = getClass().getResource("file2.txt");
23+
File file1 = new File(url1.getFile());
24+
File file2 = new File(url2.getFile());
25+
ByteArrayOutputStream baos_rule_1 = new ByteArrayOutputStream();
26+
MixThem.processFiles(Constants.RULE_1, file1, file2, baos_rule_1);
27+
Assert.assertTrue(checkFileEquals(file1, baos_rule_1.toByteArray()));
28+
ByteArrayOutputStream baos_rule_2 = new ByteArrayOutputStream();
29+
MixThem.processFiles(Constants.RULE_2, file1, file2, baos_rule_2);
30+
Assert.assertTrue(checkFileEquals(file2, baos_rule_2.toByteArray()));
31+
}
32+
33+
private static boolean checkFileEquals(File fileExpected, byte[] result) throws FileNotFoundException, IOException {
34+
FileInputStream fisExpected = new FileInputStream(fileExpected);
35+
int c;
36+
int offset = 0;
37+
while ((c = fisExpected.read()) != -1) {
38+
if (offset >= result.length) return false;
39+
int d = result[offset++];
40+
if (c != d) return false;
41+
}
42+
if (offset > result.length) return false;
43+
return true;
44+
}
45+
46+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
1
2+
2
3+
3
4+
4
5+
5
6+
6
7+
7
8+
8
9+
9
10+
10
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
A
2+
B
3+
C
4+
D
5+
E
6+
F
7+
G
8+
H
9+
I
10+
J
11+
K
12+
L
13+
M
14+
N
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
1
2+
2
3+
3
4+
4
5+
5
6+
6
7+
7
8+
8
9+
9
10+
10
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
A
2+
B
3+
C
4+
D
5+
E
6+
F
7+
G
8+
H
9+
I
10+
J
11+
K
12+
L
13+
M
14+
N
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
1
2+
B
3+
3
4+
D
5+
5
6+
F
7+
7
8+
H
9+
9
10+
I
11+
K
12+
L
13+
M
14+
N

0 commit comments

Comments
 (0)