11
11
import java .util .Arrays ;
12
12
import java .util .List ;
13
13
14
- import org .junit .jupiter .api .Test ;
15
14
16
15
import com .github .difflib .DiffUtils ;
16
+ import com .github .difflib .algorithm .DiffAlgorithmFactory ;
17
+ import com .github .difflib .algorithm .myers .MeyersDiff ;
18
+ import com .github .difflib .algorithm .myers .MeyersDiffWithLinearSpace ;
19
+ import java .util .stream .Stream ;
20
+ import org .junit .jupiter .api .AfterAll ;
21
+ import org .junit .jupiter .params .ParameterizedTest ;
22
+ import org .junit .jupiter .params .provider .Arguments ;
23
+ import org .junit .jupiter .params .provider .MethodSource ;
24
+
25
+ public class PatchWithAllDiffAlgorithmsTest {
26
+
27
+ private static Stream <Arguments > provideAlgorithms () {
28
+ return Stream .of (
29
+ Arguments .of (MeyersDiff .factory ()),
30
+ Arguments .of (MeyersDiffWithLinearSpace .factory ()));
31
+ }
32
+
33
+ @ AfterAll
34
+ public static void afterAll () {
35
+ DiffUtils .withDefaultDiffAlgorithmFactory (MeyersDiff .factory ());
36
+ }
17
37
18
- public class PatchTest {
19
-
20
- @ Test
21
- public void testPatch_Insert () {
38
+ @ ParameterizedTest
39
+ @ MethodSource ("provideAlgorithms" )
40
+ public void testPatch_Insert (DiffAlgorithmFactory factory ) {
41
+ DiffUtils .withDefaultDiffAlgorithmFactory (factory );
42
+
22
43
final List <String > insertTest_from = Arrays .asList ("hhh" );
23
44
final List <String > insertTest_to = Arrays .asList ("hhh" , "jjj" , "kkk" , "lll" );
24
45
@@ -30,8 +51,11 @@ public void testPatch_Insert() {
30
51
}
31
52
}
32
53
33
- @ Test
34
- public void testPatch_Delete () {
54
+ @ ParameterizedTest
55
+ @ MethodSource ("provideAlgorithms" )
56
+ public void testPatch_Delete (DiffAlgorithmFactory factory ) {
57
+ DiffUtils .withDefaultDiffAlgorithmFactory (factory );
58
+
35
59
final List <String > deleteTest_from = Arrays .asList ("ddd" , "fff" , "ggg" , "hhh" );
36
60
final List <String > deleteTest_to = Arrays .asList ("ggg" );
37
61
@@ -43,8 +67,11 @@ public void testPatch_Delete() {
43
67
}
44
68
}
45
69
46
- @ Test
47
- public void testPatch_Change () {
70
+ @ ParameterizedTest
71
+ @ MethodSource ("provideAlgorithms" )
72
+ public void testPatch_Change (DiffAlgorithmFactory factory ) {
73
+ DiffUtils .withDefaultDiffAlgorithmFactory (factory );
74
+
48
75
final List <String > changeTest_from = Arrays .asList ("aaa" , "bbb" , "ccc" , "ddd" );
49
76
final List <String > changeTest_to = Arrays .asList ("aaa" , "bxb" , "cxc" , "ddd" );
50
77
@@ -56,8 +83,11 @@ public void testPatch_Change() {
56
83
}
57
84
}
58
85
59
- @ Test
60
- public void testPatch_Serializable () throws IOException , ClassNotFoundException {
86
+ @ ParameterizedTest
87
+ @ MethodSource ("provideAlgorithms" )
88
+ public void testPatch_Serializable (DiffAlgorithmFactory factory ) throws IOException , ClassNotFoundException {
89
+ DiffUtils .withDefaultDiffAlgorithmFactory (factory );
90
+
61
91
final List <String > changeTest_from = Arrays .asList ("aaa" , "bbb" , "ccc" , "ddd" );
62
92
final List <String > changeTest_to = Arrays .asList ("aaa" , "bxb" , "cxc" , "ddd" );
63
93
@@ -79,8 +109,11 @@ public void testPatch_Serializable() throws IOException, ClassNotFoundException
79
109
80
110
}
81
111
82
- @ Test
83
- public void testPatch_Change_withExceptionProcessor () {
112
+ @ ParameterizedTest
113
+ @ MethodSource ("provideAlgorithms" )
114
+ public void testPatch_Change_withExceptionProcessor (DiffAlgorithmFactory factory ) {
115
+ DiffUtils .withDefaultDiffAlgorithmFactory (factory );
116
+
84
117
final List <String > changeTest_from = Arrays .asList ("aaa" , "bbb" , "ccc" , "ddd" );
85
118
final List <String > changeTest_to = Arrays .asList ("aaa" , "bxb" , "cxc" , "ddd" );
86
119
@@ -93,9 +126,9 @@ public void testPatch_Change_withExceptionProcessor() {
93
126
try {
94
127
List <String > data = DiffUtils .patch (changeTest_from , patch );
95
128
assertEquals (9 , data .size ());
96
-
129
+
97
130
assertEquals (Arrays .asList ("aaa" , "<<<<<< HEAD" , "bbb" , "CDC" , "======" , "bbb" , "ccc" , ">>>>>>> PATCH" , "ddd" ), data );
98
-
131
+
99
132
} catch (PatchFailedException e ) {
100
133
fail (e .getMessage ());
101
134
}
0 commit comments