forked from jycr/java-diff-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatchTest.java
More file actions
48 lines (39 loc) · 1.61 KB
/
PatchTest.java
File metadata and controls
48 lines (39 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package diffutils;
import difflib.DiffUtils;
import difflib.Patch;
import difflib.PatchFailedException;
import junit.framework.TestCase;
import java.util.Arrays;
import java.util.List;
public class PatchTest extends TestCase {
public void testPatch_Insert() {
final List<String> insertTest_from = Arrays.asList("hhh");
final List<String> insertTest_to = Arrays.asList("hhh", "jjj", "kkk", "lll");
final Patch<String> patch = DiffUtils.diff(insertTest_from, insertTest_to);
try {
assertEquals(insertTest_to, DiffUtils.patch(insertTest_from, patch));
} catch (PatchFailedException e) {
fail(e.getMessage());
}
}
public void testPatch_Delete() {
final List<String> deleteTest_from = Arrays.asList("ddd", "fff", "ggg", "hhh");
final List<String> deleteTest_to = Arrays.asList("ggg");
final Patch<String> patch = DiffUtils.diff(deleteTest_from, deleteTest_to);
try {
assertEquals(deleteTest_to, DiffUtils.patch(deleteTest_from, patch));
} catch (PatchFailedException e) {
fail(e.getMessage());
}
}
public void testPatch_Change() {
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");
final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to);
try {
assertEquals(changeTest_to, DiffUtils.patch(changeTest_from, patch));
} catch (PatchFailedException e) {
fail(e.getMessage());
}
}
}