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 ;
29
28
import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
30
29
import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
31
30
import static org .assertj .core .api .Assertions .assertThatNoException ;
31
+ import static org .assertj .core .api .Assertions .assertThatNullPointerException ;
32
32
33
33
/**
34
34
* Tests for {@link SimpleAliasRegistry}.
@@ -49,10 +49,6 @@ class SimpleAliasRegistryTests {
49
49
private static final String ALIAS1 = "alias1" ;
50
50
private static final String ALIAS2 = "alias2" ;
51
51
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
52
private static final String ALIAS4 = "alias4" ;
57
53
private static final String ALIAS5 = "alias5" ;
58
54
@@ -94,7 +90,21 @@ void aliasChainingWithMultipleAliases() {
94
90
}
95
91
96
92
@ Test
97
- void removeAlias () {
93
+ void removeNullAlias () {
94
+ assertThatNullPointerException ().isThrownBy (() -> registry .removeAlias (null ));
95
+ }
96
+
97
+ @ Test
98
+ void removeNonExistentAlias () {
99
+ String alias = NICKNAME ;
100
+ assertDoesNotHaveAlias (REAL_NAME , alias );
101
+ assertThatIllegalStateException ()
102
+ .isThrownBy (() -> registry .removeAlias (alias ))
103
+ .withMessage ("No alias '%s' registered" , alias );
104
+ }
105
+
106
+ @ Test
107
+ void removeExistingAlias () {
98
108
registerAlias (REAL_NAME , NICKNAME );
99
109
assertHasAlias (REAL_NAME , NICKNAME );
100
110
@@ -213,35 +223,37 @@ void resolveAliasesWithPlaceholderReplacementConflict() {
213
223
"It is already registered for name '%s'." , ALIAS2 , ALIAS1 , NAME1 , NAME2 );
214
224
}
215
225
216
- @ Test
217
- void resolveAliasesWithComplexPlaceholderReplacement () {
226
+ @ ParameterizedTest
227
+ @ ValueSource (strings = {"alias4" , "test" , "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" })
228
+ void resolveAliasesWithComplexPlaceholderReplacementWithAliasSwitching (String aliasX ) {
218
229
StringValueResolver valueResolver = new StubStringValueResolver (Map .of (
219
230
ALIAS3 , ALIAS1 ,
220
- ALIAS4 , ALIAS5 ,
231
+ aliasX , ALIAS5 ,
221
232
ALIAS5 , ALIAS2
222
233
));
223
234
235
+ // Since SimpleAliasRegistry ensures that aliases are processed in declaration
236
+ // order, we need to register ALIAS5 *before* aliasX to support our use case.
224
237
registerAlias (NAME3 , ALIAS3 );
225
- registerAlias (NAME4 , ALIAS4 );
226
238
registerAlias (NAME5 , ALIAS5 );
239
+ registerAlias (NAME4 , aliasX );
227
240
228
241
// Original state:
229
- // WARNING: Based on ConcurrentHashMap iteration order!
230
242
// ALIAS3 -> NAME3
231
243
// ALIAS5 -> NAME5
232
- // ALIAS4 -> NAME4
244
+ // aliasX -> NAME4
233
245
234
246
// State after processing original entry (ALIAS3 -> NAME3):
235
247
// ALIAS1 -> NAME3
236
248
// ALIAS5 -> NAME5
237
- // ALIAS4 -> NAME4
249
+ // aliasX -> NAME4
238
250
239
251
// State after processing original entry (ALIAS5 -> NAME5):
240
252
// ALIAS1 -> NAME3
241
253
// ALIAS2 -> NAME5
242
- // ALIAS4 -> NAME4
254
+ // aliasX -> NAME4
243
255
244
- // State after processing original entry (ALIAS4 -> NAME4):
256
+ // State after processing original entry (aliasX -> NAME4):
245
257
// ALIAS1 -> NAME3
246
258
// ALIAS2 -> NAME5
247
259
// ALIAS5 -> NAME4
@@ -252,72 +264,24 @@ void resolveAliasesWithComplexPlaceholderReplacement() {
252
264
assertThat (registry .getAliases (NAME5 )).containsExactly (ALIAS2 );
253
265
}
254
266
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
267
@ ParameterizedTest // gh-32024
303
268
@ ValueSource (strings = {"alias4" , "test" , "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" })
304
- void resolveAliasesWithComplexPlaceholderReplacementAndNameSwitching (String aliasX ) {
269
+ void resolveAliasesWithComplexPlaceholderReplacementWithAliasAndNameSwitching (String aliasX ) {
305
270
StringValueResolver valueResolver = new StubStringValueResolver (Map .of (
306
- NAME3 , NAME4 ,
307
- NAME4 , NAME3 ,
308
271
ALIAS3 , ALIAS1 ,
309
272
aliasX , ALIAS5 ,
310
- ALIAS5 , ALIAS2
273
+ ALIAS5 , ALIAS2 ,
274
+ NAME3 , NAME4 ,
275
+ NAME4 , NAME3
311
276
));
312
277
313
- // If SimpleAliasRegistry ensures that aliases are processed in declaration
278
+ // Since SimpleAliasRegistry ensures that aliases are processed in declaration
314
279
// order, we need to register ALIAS5 *before* aliasX to support our use case.
315
280
registerAlias (NAME3 , ALIAS3 );
316
281
registerAlias (NAME5 , ALIAS5 );
317
282
registerAlias (NAME4 , aliasX );
318
283
319
284
// Original state:
320
- // WARNING: Based on LinkedHashMap iteration order!
321
285
// ALIAS3 -> NAME3
322
286
// ALIAS5 -> NAME5
323
287
// aliasX -> NAME4
0 commit comments