16
16
package org .apache .ibatis .parsing ;
17
17
18
18
import static org .junit .jupiter .api .Assertions .assertEquals ;
19
+ import static org .junit .jupiter .params .provider .Arguments .arguments ;
19
20
20
21
import java .time .Duration ;
21
22
import java .util .HashMap ;
22
23
import java .util .Map ;
24
+ import java .util .stream .Stream ;
23
25
24
26
import org .junit .jupiter .api .Assertions ;
25
27
import org .junit .jupiter .api .Disabled ;
26
28
import org .junit .jupiter .api .Test ;
29
+ import org .junit .jupiter .params .ParameterizedTest ;
30
+ import org .junit .jupiter .params .provider .Arguments ;
31
+ import org .junit .jupiter .params .provider .MethodSource ;
27
32
28
33
class GenericTokenParserTest {
29
34
@@ -40,8 +45,9 @@ public String handleToken(String content) {
40
45
}
41
46
}
42
47
43
- @ Test
44
- void shouldDemonstrateGenericTokenReplacement () {
48
+ @ ParameterizedTest
49
+ @ MethodSource ("shouldDemonstrateGenericTokenReplacementProvider" )
50
+ void shouldDemonstrateGenericTokenReplacement (String expected , String text ) {
45
51
GenericTokenParser parser = new GenericTokenParser ("${" , "}" , new VariableTokenHandler (new HashMap <String , String >() {
46
52
{
47
53
put ("first_name" , "James" );
@@ -51,39 +57,50 @@ void shouldDemonstrateGenericTokenReplacement() {
51
57
put ("" , "" );
52
58
}
53
59
}));
60
+ assertEquals (expected , parser .parse (text ));
61
+ }
54
62
55
- assertEquals ("James T Kirk reporting." , parser .parse ("${first_name} ${initial} ${last_name} reporting." ));
56
- assertEquals ("Hello captain James T Kirk" , parser .parse ("Hello captain ${first_name} ${initial} ${last_name}" ));
57
- assertEquals ("James T Kirk" , parser .parse ("${first_name} ${initial} ${last_name}" ));
58
- assertEquals ("JamesTKirk" , parser .parse ("${first_name}${initial}${last_name}" ));
59
- assertEquals ("{}JamesTKirk" , parser .parse ("{}${first_name}${initial}${last_name}" ));
60
- assertEquals ("}JamesTKirk" , parser .parse ("}${first_name}${initial}${last_name}" ));
61
-
62
- assertEquals ("}James{{T}}Kirk" , parser .parse ("}${first_name}{{${initial}}}${last_name}" ));
63
- assertEquals ("}James}T{Kirk" , parser .parse ("}${first_name}}${initial}{${last_name}" ));
64
- assertEquals ("}James}T{Kirk" , parser .parse ("}${first_name}}${initial}{${last_name}" ));
65
- assertEquals ("}James}T{Kirk{{}}" , parser .parse ("}${first_name}}${initial}{${last_name}{{}}" ));
66
- assertEquals ("}James}T{Kirk{{}}" , parser .parse ("}${first_name}}${initial}{${last_name}{{}}${}" ));
67
-
68
- assertEquals ("{$$something}JamesTKirk" , parser .parse ("{$$something}${first_name}${initial}${last_name}" ));
69
- assertEquals ("${" , parser .parse ("${" ));
70
- assertEquals ("${\\ }" , parser .parse ("${\\ }" ));
71
- assertEquals ("Hiya" , parser .parse ("${var{with\\ }brace}" ));
72
- assertEquals ("" , parser .parse ("${}" ));
73
- assertEquals ("}" , parser .parse ("}" ));
74
- assertEquals ("Hello ${ this is a test." , parser .parse ("Hello ${ this is a test." ));
75
- assertEquals ("Hello } this is a test." , parser .parse ("Hello } this is a test." ));
76
- assertEquals ("Hello } ${ this is a test." , parser .parse ("Hello } ${ this is a test." ));
63
+ static Stream <Arguments > shouldDemonstrateGenericTokenReplacementProvider () {
64
+ return Stream .of (
65
+ arguments ("James T Kirk reporting." , "${first_name} ${initial} ${last_name} reporting." ),
66
+ arguments ("Hello captain James T Kirk" , "Hello captain ${first_name} ${initial} ${last_name}" ),
67
+ arguments ("James T Kirk" , "${first_name} ${initial} ${last_name}" ),
68
+ arguments ("JamesTKirk" , "${first_name}${initial}${last_name}" ),
69
+ arguments ("{}JamesTKirk" , "{}${first_name}${initial}${last_name}" ),
70
+ arguments ("}JamesTKirk" , "}${first_name}${initial}${last_name}" ),
71
+
72
+ arguments ("}James{{T}}Kirk" , "}${first_name}{{${initial}}}${last_name}" ),
73
+ arguments ("}James}T{Kirk" , "}${first_name}}${initial}{${last_name}" ),
74
+ arguments ("}James}T{Kirk" , "}${first_name}}${initial}{${last_name}" ),
75
+ arguments ("}James}T{Kirk{{}}" , "}${first_name}}${initial}{${last_name}{{}}" ),
76
+ arguments ("}James}T{Kirk{{}}" , "}${first_name}}${initial}{${last_name}{{}}${}" ),
77
+
78
+ arguments ("{$$something}JamesTKirk" , "{$$something}${first_name}${initial}${last_name}" ),
79
+ arguments ("${" , "${" ),
80
+ arguments ("${\\ }" , "${\\ }" ),
81
+ arguments ("Hiya" , "${var{with\\ }brace}" ),
82
+ arguments ("" , "${}" ),
83
+ arguments ("}" , "}" ),
84
+ arguments ("Hello ${ this is a test." , "Hello ${ this is a test." ),
85
+ arguments ("Hello } this is a test." , "Hello } this is a test." ),
86
+ arguments ("Hello } ${ this is a test." , "Hello } ${ this is a test." )
87
+ );
77
88
}
78
89
79
- @ Test
80
- void shallNotInterpolateSkippedVaiables () {
90
+ @ ParameterizedTest
91
+ @ MethodSource ("shallNotInterpolateSkippedVariablesProvider" )
92
+ void shallNotInterpolateSkippedVariables (String expected , String text ) {
81
93
GenericTokenParser parser = new GenericTokenParser ("${" , "}" , new VariableTokenHandler (new HashMap <>()));
94
+ assertEquals (expected , parser .parse (text ));
95
+ }
82
96
83
- assertEquals ("${skipped} variable" , parser .parse ("\\ ${skipped} variable" ));
84
- assertEquals ("This is a ${skipped} variable" , parser .parse ("This is a \\ ${skipped} variable" ));
85
- assertEquals ("null ${skipped} variable" , parser .parse ("${skipped} \\ ${skipped} variable" ));
86
- assertEquals ("The null is ${skipped} variable" , parser .parse ("The ${skipped} is \\ ${skipped} variable" ));
97
+ static Stream <Arguments > shallNotInterpolateSkippedVariablesProvider () {
98
+ return Stream .of (
99
+ arguments ("${skipped} variable" , "\\ ${skipped} variable" ),
100
+ arguments ("This is a ${skipped} variable" , "This is a \\ ${skipped} variable" ),
101
+ arguments ("null ${skipped} variable" , "${skipped} \\ ${skipped} variable" ),
102
+ arguments ("The null is ${skipped} variable" , "The ${skipped} is \\ ${skipped} variable" )
103
+ );
87
104
}
88
105
89
106
@ Disabled ("Because it randomly fails on Github CI. It could be useful during development." )
0 commit comments