From 432fdad7d06ff3de4d61cdb3003f728525473d69 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 4 Jun 2021 15:31:08 +0200 Subject: [PATCH] Polish contribution See gh-26982 --- .../core/SimpleAliasRegistryTests.java | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/spring-core/src/test/java/org/springframework/core/SimpleAliasRegistryTests.java b/spring-core/src/test/java/org/springframework/core/SimpleAliasRegistryTests.java index ff8c9517de8..5d5dc9dd572 100644 --- a/spring-core/src/test/java/org/springframework/core/SimpleAliasRegistryTests.java +++ b/spring-core/src/test/java/org/springframework/core/SimpleAliasRegistryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,13 +21,18 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; /** + * Unit tests for {@link SimpleAliasRegistry}. + * * @author Juergen Hoeller + * @author Nha Vuong + * @author Sam Brannen */ class SimpleAliasRegistryTests { + private final SimpleAliasRegistry registry = new SimpleAliasRegistry(); + @Test void aliasChaining() { - SimpleAliasRegistry registry = new SimpleAliasRegistry(); registry.registerAlias("test", "testAlias"); registry.registerAlias("testAlias", "testAlias2"); registry.registerAlias("testAlias2", "testAlias3"); @@ -42,7 +47,6 @@ class SimpleAliasRegistryTests { @Test // SPR-17191 void aliasChainingWithMultipleAliases() { - SimpleAliasRegistry registry = new SimpleAliasRegistry(); registry.registerAlias("name", "alias_a"); registry.registerAlias("name", "alias_b"); assertThat(registry.hasAlias("name", "alias_a")).isTrue(); @@ -61,27 +65,34 @@ class SimpleAliasRegistryTests { } @Test - void removeAliasTest() { - SimpleAliasRegistry registry = new SimpleAliasRegistry(); - registry.registerAlias("realname", "nickname"); - assertThat(registry.hasAlias("realname", "nickname")).isTrue(); + void removeAlias() { + registry.registerAlias("real_name", "nickname"); + assertThat(registry.hasAlias("real_name", "nickname")).isTrue(); registry.removeAlias("nickname"); - assertThat(registry.hasAlias("realname", "nickname")).isFalse(); + assertThat(registry.hasAlias("real_name", "nickname")).isFalse(); } @Test - void isAliasTest() { - SimpleAliasRegistry registry = new SimpleAliasRegistry(); - registry.registerAlias("realname", "nickname"); + void isAlias() { + registry.registerAlias("real_name", "nickname"); assertThat(registry.isAlias("nickname")).isTrue(); + assertThat(registry.isAlias("real_name")).isFalse(); assertThat(registry.isAlias("fake")).isFalse(); } @Test - void getAliasesTest() { - SimpleAliasRegistry registry = new SimpleAliasRegistry(); - registry.registerAlias("realname", "nickname"); - assertThat(registry.getAliases("realname")); + void getAliases() { + registry.registerAlias("test", "testAlias1"); + assertThat(registry.getAliases("test")).containsExactly("testAlias1"); + + registry.registerAlias("testAlias1", "testAlias2"); + registry.registerAlias("testAlias2", "testAlias3"); + assertThat(registry.getAliases("test")).containsExactlyInAnyOrder("testAlias1", "testAlias2", "testAlias3"); + assertThat(registry.getAliases("testAlias1")).containsExactlyInAnyOrder("testAlias2", "testAlias3"); + assertThat(registry.getAliases("testAlias2")).containsExactly("testAlias3"); + + assertThat(registry.getAliases("testAlias3")).isEmpty(); } + }