|
| 1 | +/* |
| 2 | + * Copyright 2002-2018 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.core; |
| 18 | + |
| 19 | +import org.junit.Test; |
| 20 | + |
| 21 | +import static org.junit.Assert.*; |
| 22 | + |
| 23 | +/** |
| 24 | + * @author Juergen Hoeller |
| 25 | + */ |
| 26 | +public class SimpleAliasRegistryTests { |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testAliasChaining() { |
| 30 | + SimpleAliasRegistry registry = new SimpleAliasRegistry(); |
| 31 | + registry.registerAlias("test", "testAlias"); |
| 32 | + registry.registerAlias("testAlias", "testAlias2"); |
| 33 | + registry.registerAlias("testAlias2", "testAlias3"); |
| 34 | + |
| 35 | + assertTrue(registry.hasAlias("test", "testAlias")); |
| 36 | + assertTrue(registry.hasAlias("test", "testAlias2")); |
| 37 | + assertTrue(registry.hasAlias("test", "testAlias3")); |
| 38 | + assertSame("test", registry.canonicalName("testAlias")); |
| 39 | + assertSame("test", registry.canonicalName("testAlias2")); |
| 40 | + assertSame("test", registry.canonicalName("testAlias3")); |
| 41 | + } |
| 42 | + |
| 43 | + @Test // SPR-17191 |
| 44 | + public void testAliasChainingWithMultipleAliases() { |
| 45 | + SimpleAliasRegistry registry = new SimpleAliasRegistry(); |
| 46 | + registry.registerAlias("name", "alias_a"); |
| 47 | + registry.registerAlias("name", "alias_b"); |
| 48 | + assertTrue(registry.hasAlias("name", "alias_a")); |
| 49 | + assertTrue(registry.hasAlias("name", "alias_b")); |
| 50 | + |
| 51 | + registry.registerAlias("real_name", "name"); |
| 52 | + assertTrue(registry.hasAlias("real_name", "name")); |
| 53 | + assertTrue(registry.hasAlias("real_name", "alias_a")); |
| 54 | + assertTrue(registry.hasAlias("real_name", "alias_b")); |
| 55 | + |
| 56 | + registry.registerAlias("name", "alias_c"); |
| 57 | + assertTrue(registry.hasAlias("real_name", "name")); |
| 58 | + assertTrue(registry.hasAlias("real_name", "alias_a")); |
| 59 | + assertTrue(registry.hasAlias("real_name", "alias_b")); |
| 60 | + assertTrue(registry.hasAlias("real_name", "alias_c")); |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments