Browse Source

Add missing unit tests for SimpleAliasRegistry

Closes gh-31348
pull/31354/head
Enrico Freni 1 year ago committed by Sam Brannen
parent
commit
d507590abf
  1. 55
      spring-core/src/test/java/org/springframework/core/SimpleAliasRegistryTests.java

55
spring-core/src/test/java/org/springframework/core/SimpleAliasRegistryTests.java

@ -18,7 +18,13 @@ package org.springframework.core; @@ -18,7 +18,13 @@ package org.springframework.core;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringValueResolver;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
/**
* Unit tests for {@link SimpleAliasRegistry}.
@ -43,6 +49,7 @@ class SimpleAliasRegistryTests { @@ -43,6 +49,7 @@ class SimpleAliasRegistryTests {
assertThat(registry.canonicalName("testAlias")).isEqualTo("test");
assertThat(registry.canonicalName("testAlias2")).isEqualTo("test");
assertThat(registry.canonicalName("testAlias3")).isEqualTo("test");
}
@Test // SPR-17191
@ -95,4 +102,52 @@ class SimpleAliasRegistryTests { @@ -95,4 +102,52 @@ class SimpleAliasRegistryTests {
assertThat(registry.getAliases("testAlias3")).isEmpty();
}
@Test
void testCheckForAliasCircle() {
String name = "testName";
String alias = "testAlias";
registry.checkForAliasCircle(name, alias);
registry.registerAlias(name, alias);
assertThatIllegalStateException()
.isThrownBy(() -> registry.checkForAliasCircle(alias, name));
}
@Test
void testResolveAliases() {
assertThatIllegalArgumentException()
.isThrownBy(() -> registry.resolveAliases(null));
StringValueResolver mock = mock();
registry.registerAlias("testName1", "testAlias1");
registry.registerAlias("testName2", "testAlias2");
given(mock.resolveStringValue("testAlias2")).willReturn("anotherAlias2");
given(mock.resolveStringValue("testName2")).willReturn("anotherName2");
registry.resolveAliases(mock);
assertThat(registry.getAliases("anotherName2")).containsExactly("anotherAlias2");
registry.registerAlias("testName3", "testAlias3");
registry.registerAlias("testName4", "testAlias4");
registry.registerAlias("testName5", "testAlias5");
given(mock.resolveStringValue("testName5")).willReturn("testName5");
given(mock.resolveStringValue("testAlias5")).willReturn("testAlias5");
given(mock.resolveStringValue("testName3")).willReturn("testName4");
given(mock.resolveStringValue("testAlias3")).willReturn("testAlias4");
given(mock.resolveStringValue("testName4")).willReturn("testName4");
given(mock.resolveStringValue("testAlias4")).willReturn("testAlias5");
assertThatIllegalStateException()
.isThrownBy(() -> registry.resolveAliases(mock));
given(mock.resolveStringValue("testName4")).willReturn("testName5");
given(mock.resolveStringValue("testAlias4")).willReturn("testAlias4");
assertThatIllegalStateException()
.isThrownBy(() -> registry.resolveAliases(mock));
given(mock.resolveStringValue("testName4")).willReturn("testName4");
given(mock.resolveStringValue("testAlias4")).willReturn("testAlias5");
registry.resolveAliases(mock);
assertThat(registry.getAliases("testName4")).containsExactly("testAlias4");
assertThat(registry.getAliases("testName5")).containsExactly("testAlias5");
}
}

Loading…
Cancel
Save