@@ -33,7 +33,8 @@ static Stream<Arguments> simpleParams() {
33
33
Arguments .of ("[a-zA-Z]+" , "Hello ${world}!" , "world" , "LangSec" , "Hello LangSec!" ),
34
34
Arguments .of ("[a-zA-Z]+" , "Hello {${world}}!" , "world" , "LangSec" , "Hello {LangSec}!" ),
35
35
Arguments .of ("[a-zA-Z]+" , "Hello $${world}!" , "world" , "LangSec" , "Hello $LangSec!" ),
36
- Arguments .of ("[a-zA-Z]+" , "Hello ${} ${world}!" , "world" , "LangSec" , "Hello ${} LangSec!" ));
36
+ Arguments .of ("[a-zA-Z]+" , "Hello ${} ${world}!" , "world" , "LangSec" , "Hello ${} LangSec!" ),
37
+ Arguments .of ("[a-zA-Z]+" , "Hello ${0}!" , "0" , "LangSec" , "Hello LangSec!" ));
37
38
}
38
39
39
40
@ ParameterizedTest
@@ -144,28 +145,21 @@ void tokenNull() {
144
145
assertThatThrownBy (() -> template .withToken ("any" , token )).isExactlyInstanceOf (NullPointerException .class );
145
146
}
146
147
147
- @ Test
148
- void tokenFieldNull () {
149
- Template template = Template .of ("any" );
150
- Token token = Token .of ("any" );
151
- String field = null ;
152
- assertThatThrownBy (() -> template .withToken (field , token )).isExactlyInstanceOf (NullPointerException .class );
153
- }
154
-
155
- @ Test
156
- void tokenFieldEmpty () {
157
- Template template = Template .of ("any" );
158
- Token token = Token .of ("any" );
159
- String field = "" ;
160
- assertThatThrownBy (() -> template .withToken (field , token )).isExactlyInstanceOf (IllegalArgumentException .class );
148
+ static Stream <Arguments > invalidTokenFields () {
149
+ return Stream .of (
150
+ Arguments .of (null , NullPointerException .class , "field is marked non-null but is null" ),
151
+ Arguments .of ("" , IllegalArgumentException .class , "Token field should not be blank/empty" ),
152
+ Arguments .of (" " , IllegalArgumentException .class , "Token field should not be blank/empty" ),
153
+ Arguments .of ("#" , IllegalArgumentException .class , "Token field does not match pattern [a-zA-Z0-9]+" ));
161
154
}
162
155
163
- @ Test
164
- void tokenFieldBlank () {
156
+ @ ParameterizedTest
157
+ @ MethodSource ("invalidTokenFields" )
158
+ void tokenFieldEmpty (String field , Class <Exception > expectedException , String expectedMessage ) {
165
159
Template template = Template .of ("any" );
166
160
Token token = Token .of ("any" );
167
- String field = " " ;
168
- assertThatThrownBy (() -> template . withToken ( field , token )). isExactlyInstanceOf ( IllegalArgumentException . class );
161
+ assertThatThrownBy (() -> template . withToken ( field , token )). isExactlyInstanceOf ( expectedException )
162
+ . hasMessage ( expectedMessage );
169
163
}
170
164
171
165
}
0 commit comments