18
18
19
19
import java .util .Map ;
20
20
21
- import org .junit .jupiter .api .Disabled ;
22
21
import org .junit .jupiter .api .Test ;
23
22
import org .junit .jupiter .params .ParameterizedTest ;
24
23
import org .junit .jupiter .params .provider .ValueSource ;
@@ -49,10 +48,6 @@ class SimpleAliasRegistryTests {
49
48
private static final String ALIAS1 = "alias1" ;
50
49
private static final String ALIAS2 = "alias2" ;
51
50
private static final String ALIAS3 = "alias3" ;
52
- // TODO Determine if we can make SimpleAliasRegistry.resolveAliases() reliable.
53
- // See https://github.com/spring-projects/spring-framework/issues/32024.
54
- // When ALIAS4 is changed to "test", various tests fail due to the iteration
55
- // order of the entries in the aliasMap in SimpleAliasRegistry.
56
51
private static final String ALIAS4 = "alias4" ;
57
52
private static final String ALIAS5 = "alias5" ;
58
53
@@ -213,35 +208,37 @@ void resolveAliasesWithPlaceholderReplacementConflict() {
213
208
"It is already registered for name '%s'." , ALIAS2 , ALIAS1 , NAME1 , NAME2 );
214
209
}
215
210
216
- @ Test
217
- void resolveAliasesWithComplexPlaceholderReplacement () {
211
+ @ ParameterizedTest
212
+ @ ValueSource (strings = {"alias4" , "test" , "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" })
213
+ void resolveAliasesWithComplexPlaceholderReplacementWithAliasSwitching (String aliasX ) {
218
214
StringValueResolver valueResolver = new StubStringValueResolver (Map .of (
219
215
ALIAS3 , ALIAS1 ,
220
- ALIAS4 , ALIAS5 ,
216
+ aliasX , ALIAS5 ,
221
217
ALIAS5 , ALIAS2
222
218
));
223
219
220
+ // Since SimpleAliasRegistry ensures that aliases are processed in declaration
221
+ // order, we need to register ALIAS5 *before* aliasX to support our use case.
224
222
registerAlias (NAME3 , ALIAS3 );
225
- registerAlias (NAME4 , ALIAS4 );
226
223
registerAlias (NAME5 , ALIAS5 );
224
+ registerAlias (NAME4 , aliasX );
227
225
228
226
// Original state:
229
- // WARNING: Based on ConcurrentHashMap iteration order!
230
227
// ALIAS3 -> NAME3
231
228
// ALIAS5 -> NAME5
232
- // ALIAS4 -> NAME4
229
+ // aliasX -> NAME4
233
230
234
231
// State after processing original entry (ALIAS3 -> NAME3):
235
232
// ALIAS1 -> NAME3
236
233
// ALIAS5 -> NAME5
237
- // ALIAS4 -> NAME4
234
+ // aliasX -> NAME4
238
235
239
236
// State after processing original entry (ALIAS5 -> NAME5):
240
237
// ALIAS1 -> NAME3
241
238
// ALIAS2 -> NAME5
242
- // ALIAS4 -> NAME4
239
+ // aliasX -> NAME4
243
240
244
- // State after processing original entry (ALIAS4 -> NAME4):
241
+ // State after processing original entry (aliasX -> NAME4):
245
242
// ALIAS1 -> NAME3
246
243
// ALIAS2 -> NAME5
247
244
// ALIAS5 -> NAME4
@@ -252,72 +249,24 @@ void resolveAliasesWithComplexPlaceholderReplacement() {
252
249
assertThat (registry .getAliases (NAME5 )).containsExactly (ALIAS2 );
253
250
}
254
251
255
- // TODO Remove this test once we have implemented reliable processing in SimpleAliasRegistry.resolveAliases().
256
- // See https://github.com/spring-projects/spring-framework/issues/32024.
257
- // This method effectively duplicates the @ParameterizedTest version below,
258
- // with aliasX hard coded to ALIAS4; however, this method also hard codes
259
- // a different outcome that passes based on ConcurrentHashMap iteration order!
260
- @ Test
261
- void resolveAliasesWithComplexPlaceholderReplacementAndNameSwitching () {
262
- StringValueResolver valueResolver = new StubStringValueResolver (Map .of (
263
- NAME3 , NAME4 ,
264
- NAME4 , NAME3 ,
265
- ALIAS3 , ALIAS1 ,
266
- ALIAS4 , ALIAS5 ,
267
- ALIAS5 , ALIAS2
268
- ));
269
-
270
- registerAlias (NAME3 , ALIAS3 );
271
- registerAlias (NAME4 , ALIAS4 );
272
- registerAlias (NAME5 , ALIAS5 );
273
-
274
- // Original state:
275
- // WARNING: Based on ConcurrentHashMap iteration order!
276
- // ALIAS3 -> NAME3
277
- // ALIAS5 -> NAME5
278
- // ALIAS4 -> NAME4
279
-
280
- // State after processing original entry (ALIAS3 -> NAME3):
281
- // ALIAS1 -> NAME4
282
- // ALIAS5 -> NAME5
283
- // ALIAS4 -> NAME4
284
-
285
- // State after processing original entry (ALIAS5 -> NAME5):
286
- // ALIAS1 -> NAME4
287
- // ALIAS2 -> NAME5
288
- // ALIAS4 -> NAME4
289
-
290
- // State after processing original entry (ALIAS4 -> NAME4):
291
- // ALIAS1 -> NAME4
292
- // ALIAS2 -> NAME5
293
- // ALIAS5 -> NAME3
294
-
295
- registry .resolveAliases (valueResolver );
296
- assertThat (registry .getAliases (NAME3 )).containsExactly (ALIAS5 );
297
- assertThat (registry .getAliases (NAME4 )).containsExactly (ALIAS1 );
298
- assertThat (registry .getAliases (NAME5 )).containsExactly (ALIAS2 );
299
- }
300
-
301
- @ Disabled ("Fails for some values unless alias registration order is honored" )
302
252
@ ParameterizedTest // gh-32024
303
253
@ ValueSource (strings = {"alias4" , "test" , "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" })
304
- void resolveAliasesWithComplexPlaceholderReplacementAndNameSwitching (String aliasX ) {
254
+ void resolveAliasesWithComplexPlaceholderReplacementWithAliasAndNameSwitching (String aliasX ) {
305
255
StringValueResolver valueResolver = new StubStringValueResolver (Map .of (
306
- NAME3 , NAME4 ,
307
- NAME4 , NAME3 ,
308
256
ALIAS3 , ALIAS1 ,
309
257
aliasX , ALIAS5 ,
310
- ALIAS5 , ALIAS2
258
+ ALIAS5 , ALIAS2 ,
259
+ NAME3 , NAME4 ,
260
+ NAME4 , NAME3
311
261
));
312
262
313
- // If SimpleAliasRegistry ensures that aliases are processed in declaration
263
+ // Since SimpleAliasRegistry ensures that aliases are processed in declaration
314
264
// order, we need to register ALIAS5 *before* aliasX to support our use case.
315
265
registerAlias (NAME3 , ALIAS3 );
316
266
registerAlias (NAME5 , ALIAS5 );
317
267
registerAlias (NAME4 , aliasX );
318
268
319
269
// Original state:
320
- // WARNING: Based on LinkedHashMap iteration order!
321
270
// ALIAS3 -> NAME3
322
271
// ALIAS5 -> NAME5
323
272
// aliasX -> NAME4
0 commit comments