Skip to content

Commit 346b6f7

Browse files
committed
Polish contribution
See gh-33401
1 parent 4ffeddb commit 346b6f7

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

spring-web/src/test/java/org/springframework/web/method/ControllerAdviceBeanTests.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void shouldFailWhenControllerAdviceNull() {
8989

9090
@Test
9191
void equalsHashCodeAndToString() {
92-
String beanName = getSingletonBeanName(SimpleControllerAdvice.class);
92+
String beanName = SimpleControllerAdvice.class.getSimpleName();
9393
ControllerAdviceBean bean1 = createSingletonControllerAdviceBean(SimpleControllerAdvice.class);
9494
ControllerAdviceBean bean2 = createSingletonControllerAdviceBean(SimpleControllerAdvice.class);
9595
assertEqualsHashCodeAndToString(bean1, bean2, beanName);
@@ -113,16 +113,17 @@ void orderedViaAnnotation() {
113113

114114
@Test
115115
void resolveBeanForSingletonBean() {
116+
String beanName = SimpleControllerAdvice.class.getSimpleName();
116117
ControllerAdviceBean cab = createSingletonControllerAdviceBean(SimpleControllerAdvice.class);
117-
Object bean = this.applicationContext.getBean(getSingletonBeanName(SimpleControllerAdvice.class));
118+
Object bean = this.applicationContext.getBean(beanName);
118119
assertThat(cab).extracting("resolvedBean").isNull();
119120
Object resolvedBean = cab.resolveBean();
120121
assertThat(cab).extracting("resolvedBean").isEqualTo(bean);
121122
assertThat(resolvedBean).isEqualTo(bean);
122123
}
123124

124125
@Test
125-
void resolveBeanForNonSingletonBean() {
126+
void resolveBeanForPrototypeBean() {
126127
ControllerAdviceBean cab = createPrototypeControllerAdviceBean(SimpleControllerAdvice.class);
127128
assertThat(cab).extracting("resolvedBean").isNull();
128129
Object resolvedBean = cab.resolveBean();
@@ -220,27 +221,19 @@ public void findAnnotatedBeansSortsBeans() {
220221
}
221222

222223
private ControllerAdviceBean createSingletonControllerAdviceBean(Class<?> beanType) {
223-
String beanName = getSingletonBeanName(beanType);
224+
String beanName = beanType.getSimpleName();
224225
this.applicationContext.registerSingleton(beanName, beanType);
225226
ControllerAdvice controllerAdvice = AnnotatedElementUtils.findMergedAnnotation(beanType, ControllerAdvice.class);
226227
return new ControllerAdviceBean(beanName, this.applicationContext, controllerAdvice);
227228
}
228229

229-
private static String getSingletonBeanName(Class<?> beanType) {
230-
return beanType.getSimpleName() + "Singleton";
231-
}
232-
233230
private ControllerAdviceBean createPrototypeControllerAdviceBean(Class<?> beanType) {
234-
String beanName = getPrototypeBeanName(beanType);
231+
String beanName = beanType.getSimpleName();
235232
this.applicationContext.registerPrototype(beanName, beanType);
236233
ControllerAdvice controllerAdvice = AnnotatedElementUtils.findMergedAnnotation(beanType, ControllerAdvice.class);
237234
return new ControllerAdviceBean(beanName, this.applicationContext, controllerAdvice);
238235
}
239236

240-
private static String getPrototypeBeanName(Class<?> beanType) {
241-
return beanType.getSimpleName() + "Prototype";
242-
}
243-
244237
private void assertEqualsHashCodeAndToString(ControllerAdviceBean bean1, ControllerAdviceBean bean2, String toString) {
245238
assertThat(bean1).isEqualTo(bean2);
246239
assertThat(bean2).isEqualTo(bean1);

0 commit comments

Comments
 (0)