Skip to content

Commit 0a4f290

Browse files
committed
Polish DefaultSingletonBeanRegistryTests
1 parent 6ea4d37 commit 0a4f290

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

spring-beans/src/test/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistryTests.java

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,58 +28,49 @@
2828
* @author Chris Beams
2929
* @since 04.07.2006
3030
*/
31-
public class DefaultSingletonBeanRegistryTests {
31+
class DefaultSingletonBeanRegistryTests {
32+
33+
private final DefaultSingletonBeanRegistry beanRegistry = new DefaultSingletonBeanRegistry();
3234

33-
@Test
34-
public void testSingletons() {
35-
DefaultSingletonBeanRegistry beanRegistry = new DefaultSingletonBeanRegistry();
3635

36+
@Test
37+
void singletons() {
3738
TestBean tb = new TestBean();
3839
beanRegistry.registerSingleton("tb", tb);
3940
assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb);
4041

41-
TestBean tb2 = (TestBean) beanRegistry.getSingleton("tb2", () -> new TestBean());
42+
TestBean tb2 = (TestBean) beanRegistry.getSingleton("tb2", TestBean::new);
4243
assertThat(beanRegistry.getSingleton("tb2")).isSameAs(tb2);
4344

4445
assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb);
4546
assertThat(beanRegistry.getSingleton("tb2")).isSameAs(tb2);
4647
assertThat(beanRegistry.getSingletonCount()).isEqualTo(2);
47-
String[] names = beanRegistry.getSingletonNames();
48-
assertThat(names.length).isEqualTo(2);
49-
assertThat(names[0]).isEqualTo("tb");
50-
assertThat(names[1]).isEqualTo("tb2");
48+
assertThat(beanRegistry.getSingletonNames()).containsExactly("tb", "tb2");
5149

5250
beanRegistry.destroySingletons();
53-
assertThat(beanRegistry.getSingletonCount()).isEqualTo(0);
54-
assertThat(beanRegistry.getSingletonNames().length).isEqualTo(0);
51+
assertThat(beanRegistry.getSingletonCount()).isZero();
52+
assertThat(beanRegistry.getSingletonNames()).isEmpty();
5553
}
5654

5755
@Test
58-
public void testDisposableBean() {
59-
DefaultSingletonBeanRegistry beanRegistry = new DefaultSingletonBeanRegistry();
60-
56+
void disposableBean() {
6157
DerivedTestBean tb = new DerivedTestBean();
6258
beanRegistry.registerSingleton("tb", tb);
6359
beanRegistry.registerDisposableBean("tb", tb);
6460
assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb);
6561

6662
assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb);
6763
assertThat(beanRegistry.getSingletonCount()).isEqualTo(1);
68-
String[] names = beanRegistry.getSingletonNames();
69-
assertThat(names.length).isEqualTo(1);
70-
assertThat(names[0]).isEqualTo("tb");
64+
assertThat(beanRegistry.getSingletonNames()).containsExactly("tb");
7165
assertThat(tb.wasDestroyed()).isFalse();
7266

7367
beanRegistry.destroySingletons();
74-
assertThat(beanRegistry.getSingletonCount()).isEqualTo(0);
75-
assertThat(beanRegistry.getSingletonNames().length).isEqualTo(0);
76-
assertThat(tb.wasDestroyed()).isTrue();
68+
assertThat(beanRegistry.getSingletonCount()).isZero();
69+
assertThat(beanRegistry.getSingletonNames()).isEmpty();
7770
}
7871

7972
@Test
80-
public void testDependentRegistration() {
81-
DefaultSingletonBeanRegistry beanRegistry = new DefaultSingletonBeanRegistry();
82-
73+
void dependentRegistration() {
8374
beanRegistry.registerDependentBean("a", "b");
8475
beanRegistry.registerDependentBean("b", "c");
8576
beanRegistry.registerDependentBean("c", "b");

0 commit comments

Comments
 (0)