1111import java .util .Arrays ;
1212import java .util .List ;
1313
14- import org .junit .jupiter .api .Test ;
1514
1615import 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+ }
1737
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+
2243 final List <String > insertTest_from = Arrays .asList ("hhh" );
2344 final List <String > insertTest_to = Arrays .asList ("hhh" , "jjj" , "kkk" , "lll" );
2445
@@ -30,8 +51,11 @@ public void testPatch_Insert() {
3051 }
3152 }
3253
33- @ Test
34- public void testPatch_Delete () {
54+ @ ParameterizedTest
55+ @ MethodSource ("provideAlgorithms" )
56+ public void testPatch_Delete (DiffAlgorithmFactory factory ) {
57+ DiffUtils .withDefaultDiffAlgorithmFactory (factory );
58+
3559 final List <String > deleteTest_from = Arrays .asList ("ddd" , "fff" , "ggg" , "hhh" );
3660 final List <String > deleteTest_to = Arrays .asList ("ggg" );
3761
@@ -43,8 +67,11 @@ public void testPatch_Delete() {
4367 }
4468 }
4569
46- @ Test
47- public void testPatch_Change () {
70+ @ ParameterizedTest
71+ @ MethodSource ("provideAlgorithms" )
72+ public void testPatch_Change (DiffAlgorithmFactory factory ) {
73+ DiffUtils .withDefaultDiffAlgorithmFactory (factory );
74+
4875 final List <String > changeTest_from = Arrays .asList ("aaa" , "bbb" , "ccc" , "ddd" );
4976 final List <String > changeTest_to = Arrays .asList ("aaa" , "bxb" , "cxc" , "ddd" );
5077
@@ -56,8 +83,11 @@ public void testPatch_Change() {
5683 }
5784 }
5885
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+
6191 final List <String > changeTest_from = Arrays .asList ("aaa" , "bbb" , "ccc" , "ddd" );
6292 final List <String > changeTest_to = Arrays .asList ("aaa" , "bxb" , "cxc" , "ddd" );
6393
@@ -79,8 +109,11 @@ public void testPatch_Serializable() throws IOException, ClassNotFoundException
79109
80110 }
81111
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+
84117 final List <String > changeTest_from = Arrays .asList ("aaa" , "bbb" , "ccc" , "ddd" );
85118 final List <String > changeTest_to = Arrays .asList ("aaa" , "bxb" , "cxc" , "ddd" );
86119
@@ -93,9 +126,9 @@ public void testPatch_Change_withExceptionProcessor() {
93126 try {
94127 List <String > data = DiffUtils .patch (changeTest_from , patch );
95128 assertEquals (9 , data .size ());
96-
129+
97130 assertEquals (Arrays .asList ("aaa" , "<<<<<< HEAD" , "bbb" , "CDC" , "======" , "bbb" , "ccc" , ">>>>>>> PATCH" , "ddd" ), data );
98-
131+
99132 } catch (PatchFailedException e ) {
100133 fail (e .getMessage ());
101134 }
0 commit comments