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