1
1
/*
2
- * Copyright 2002-2024 the original author or authors.
2
+ * Copyright 2002-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
package org .springframework .util ;
18
18
19
19
import java .util .Properties ;
20
+ import java .util .stream .Stream ;
20
21
21
22
import org .junit .jupiter .api .Nested ;
22
23
import org .junit .jupiter .api .Test ;
23
24
import org .junit .jupiter .params .ParameterizedTest ;
24
- import org .junit .jupiter .params .provider .CsvSource ;
25
+ import org .junit .jupiter .params .provider .Arguments ;
26
+ import org .junit .jupiter .params .provider .MethodSource ;
25
27
26
28
import org .springframework .util .PropertyPlaceholderHelper .PlaceholderResolver ;
27
29
@@ -125,14 +127,7 @@ class DefaultValueTests {
125
127
private final PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper ("${" , "}" , ":" , null , true );
126
128
127
129
@ ParameterizedTest (name = "{0} -> {1}" )
128
- @ CsvSource (delimiterString = "->" , textBlock = """
129
- ${invalid:test} -> test
130
- ${invalid:${one}} -> 1
131
- ${invalid:${one}${two}} -> 12
132
- ${invalid:${one}:${two}} -> 1:2
133
- ${invalid:${also_invalid:test}} -> test
134
- ${invalid:${also_invalid:${one}}} -> 1
135
- """ )
130
+ @ MethodSource ("defaultValues" )
136
131
void defaultValueIsApplied (String text , String value ) {
137
132
Properties properties = new Properties ();
138
133
properties .setProperty ("one" , "1" );
@@ -148,18 +143,33 @@ void defaultValueIsNotEvaluatedEarly() {
148
143
verify (resolver , never ()).resolvePlaceholder ("two" );
149
144
}
150
145
146
+ static Stream <Arguments > defaultValues () {
147
+ return Stream .of (
148
+ Arguments .of ("${invalid:test}" , "test" ),
149
+ Arguments .of ("${invalid:${one}}" , "1" ),
150
+ Arguments .of ("${invalid:${one}${two}}" , "12" ),
151
+ Arguments .of ("${invalid:${one}:${two}}" , "1:2" ),
152
+ Arguments .of ("${invalid:${also_invalid:test}}" , "test" ),
153
+ Arguments .of ("${invalid:${also_invalid:${one}}}" , "1" )
154
+ );
155
+ }
156
+
151
157
@ ParameterizedTest (name = "{0} -> {1}" )
152
- @ CsvSource (delimiterString = "->" , textBlock = """
153
- ${prefix://my-service} -> example-service
154
- ${p1} -> example-service
155
- """ )
158
+ @ MethodSource ("exactMatchPlaceholders" )
156
159
void placeholdersWithExactMatchAreConsidered (String text , String expected ) {
157
160
Properties properties = new Properties ();
158
161
properties .setProperty ("prefix://my-service" , "example-service" );
159
162
properties .setProperty ("px" , "prefix" );
160
163
properties .setProperty ("p1" , "${prefix://my-service}" );
161
164
assertThat (this .helper .replacePlaceholders (text , properties )).isEqualTo (expected );
162
165
}
166
+
167
+ static Stream <Arguments > exactMatchPlaceholders () {
168
+ return Stream .of (
169
+ Arguments .of ("${prefix://my-service}" , "example-service" ),
170
+ Arguments .of ("${p1}" , "example-service" )
171
+ );
172
+ }
163
173
}
164
174
165
175
0 commit comments