@@ -53,13 +53,27 @@ void getVariableNames() {
53
53
assertThat (variableNames ).as ("Invalid variable names" ).isEqualTo (Arrays .asList ("hotel" , "booking" ));
54
54
}
55
55
56
+ @ Test
57
+ void getVariableNamesFromEmpty () {
58
+ UriTemplate template = new UriTemplate ("" );
59
+ List <String > variableNames = template .getVariableNames ();
60
+ assertThat (variableNames ).isEmpty ();
61
+ }
62
+
56
63
@ Test
57
64
void expandVarArgs () {
58
65
UriTemplate template = new UriTemplate ("/hotels/{hotel}/bookings/{booking}" );
59
66
URI result = template .expand ("1" , "42" );
60
67
assertThat (result ).as ("Invalid expanded template" ).isEqualTo (URI .create ("/hotels/1/bookings/42" ));
61
68
}
62
69
70
+ @ Test
71
+ void expandVarArgsFromEmpty () {
72
+ UriTemplate template = new UriTemplate ("" );
73
+ URI result = template .expand ();
74
+ assertThat (result ).as ("Invalid expanded template" ).isEqualTo (URI .create ("" ));
75
+ }
76
+
63
77
@ Test // SPR-9712
64
78
void expandVarArgsWithArrayValue () {
65
79
UriTemplate template = new UriTemplate ("/sum?numbers={numbers}" );
@@ -135,6 +149,15 @@ void matches() {
135
149
assertThat (template .matches (null )).as ("UriTemplate matches" ).isFalse ();
136
150
}
137
151
152
+ @ Test
153
+ void matchesAgainstEmpty () {
154
+ UriTemplate template = new UriTemplate ("" );
155
+ assertThat (template .matches ("/hotels/1/bookings/42" )).as ("UriTemplate matches" ).isFalse ();
156
+ assertThat (template .matches ("/hotels/bookings" )).as ("UriTemplate matches" ).isFalse ();
157
+ assertThat (template .matches ("" )).as ("UriTemplate does not match" ).isTrue ();
158
+ assertThat (template .matches (null )).as ("UriTemplate matches" ).isFalse ();
159
+ }
160
+
138
161
@ Test
139
162
void matchesCustomRegex () {
140
163
UriTemplate template = new UriTemplate ("/hotels/{hotel:\\ d+}" );
@@ -153,6 +176,13 @@ void match() {
153
176
assertThat (result ).as ("Invalid match" ).isEqualTo (expected );
154
177
}
155
178
179
+ @ Test
180
+ void matchAgainstEmpty () {
181
+ UriTemplate template = new UriTemplate ("" );
182
+ Map <String , String > result = template .match ("/hotels/1/bookings/42" );
183
+ assertThat (result ).as ("Invalid match" ).isEmpty ();
184
+ }
185
+
156
186
@ Test
157
187
void matchCustomRegex () {
158
188
Map <String , String > expected = new HashMap <>(2 );
0 commit comments