Skip to content

Commit 9949a91

Browse files
committed
Fix javadoc and assertion glitches
1 parent d8b7a59 commit 9949a91

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ public void clear(@Nullable PropertyValues pvs) {
141141
* Return an {@code InjectionMetadata} instance, possibly for empty elements.
142142
* @param elements the elements to inject (possibly empty)
143143
* @param clazz the target class
144-
* @return a new {@link #InjectionMetadata(Class, Collection)} instance,
145-
* or {@link #EMPTY} in case of no elements
144+
* @return a new {@link #InjectionMetadata(Class, Collection)} instance
146145
* @since 5.2
147146
*/
148147
public static InjectionMetadata forElements(Collection<InjectedElement> elements, Class<?> clazz) {

spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -799,9 +799,10 @@ void canReferenceParentBeanFromChildViaAlias() {
799799
TestBean child = (TestBean) factory.getBean("child");
800800
assertThat(child.getName()).isEqualTo(EXPECTED_NAME);
801801
assertThat(child.getAge()).isEqualTo(EXPECTED_AGE);
802+
Object mergedBeanDefinition1 = factory.getMergedBeanDefinition("child");
802803
Object mergedBeanDefinition2 = factory.getMergedBeanDefinition("child");
803804

804-
assertThat(mergedBeanDefinition2).as("Use cached merged bean definition").isEqualTo(mergedBeanDefinition2);
805+
assertThat(mergedBeanDefinition1).as("Use cached merged bean definition").isEqualTo(mergedBeanDefinition2);
805806
}
806807

807808
@Test
@@ -1849,8 +1850,7 @@ void autowireBeanWithFactoryBeanByType() {
18491850
assertThat(factoryBean).as("The FactoryBean should have been registered.").isNotNull();
18501851
FactoryBeanDependentBean bean = (FactoryBeanDependentBean) lbf.autowire(FactoryBeanDependentBean.class,
18511852
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
1852-
Object mergedBeanDefinition2 = bean.getFactoryBean();
1853-
assertThat(mergedBeanDefinition2).as("The FactoryBeanDependentBean should have been autowired 'by type' with the LazyInitFactory.").isEqualTo(mergedBeanDefinition2);
1853+
assertThat(bean.getFactoryBean()).as("The FactoryBeanDependentBean should have been autowired 'by type' with the LazyInitFactory.").isEqualTo(factoryBean);
18541854
}
18551855

18561856
@Test
@@ -2556,8 +2556,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) {
25562556
BeanWithDestroyMethod.closeCount = 0;
25572557
lbf.preInstantiateSingletons();
25582558
lbf.destroySingletons();
2559-
Object mergedBeanDefinition2 = BeanWithDestroyMethod.closeCount;
2560-
assertThat(mergedBeanDefinition2).as("Destroy methods invoked").isEqualTo(mergedBeanDefinition2);
2559+
assertThat(BeanWithDestroyMethod.closeCount).as("Destroy methods invoked").isEqualTo(1);
25612560
}
25622561

25632562
@Test
@@ -2571,8 +2570,7 @@ void destroyMethodOnInnerBean() {
25712570
BeanWithDestroyMethod.closeCount = 0;
25722571
lbf.preInstantiateSingletons();
25732572
lbf.destroySingletons();
2574-
Object mergedBeanDefinition2 = BeanWithDestroyMethod.closeCount;
2575-
assertThat(mergedBeanDefinition2).as("Destroy methods invoked").isEqualTo(mergedBeanDefinition2);
2573+
assertThat(BeanWithDestroyMethod.closeCount).as("Destroy methods invoked").isEqualTo(2);
25762574
}
25772575

25782576
@Test
@@ -2587,8 +2585,7 @@ void destroyMethodOnInnerBeanAsPrototype() {
25872585
BeanWithDestroyMethod.closeCount = 0;
25882586
lbf.preInstantiateSingletons();
25892587
lbf.destroySingletons();
2590-
Object mergedBeanDefinition2 = BeanWithDestroyMethod.closeCount;
2591-
assertThat(mergedBeanDefinition2).as("Destroy methods invoked").isEqualTo(mergedBeanDefinition2);
2588+
assertThat(BeanWithDestroyMethod.closeCount).as("Destroy methods invoked").isEqualTo(1);
25922589
}
25932590

25942591
@Test
@@ -2710,14 +2707,15 @@ void explicitScopeInheritanceForChildBeanDefinitions() {
27102707
factory.registerBeanDefinition("child", child);
27112708

27122709
AbstractBeanDefinition def = (AbstractBeanDefinition) factory.getBeanDefinition("child");
2713-
Object mergedBeanDefinition2 = def.getScope();
2714-
assertThat(mergedBeanDefinition2).as("Child 'scope' not overriding parent scope (it must).").isEqualTo(mergedBeanDefinition2);
2710+
assertThat(def.getScope()).as("Child 'scope' not overriding parent scope (it must).").isEqualTo(theChildScope);
27152711
}
27162712

27172713
@Test
27182714
void scopeInheritanceForChildBeanDefinitions() {
2715+
String theParentScope = "bonanza!";
2716+
27192717
RootBeanDefinition parent = new RootBeanDefinition();
2720-
parent.setScope("bonanza!");
2718+
parent.setScope(theParentScope);
27212719

27222720
AbstractBeanDefinition child = new ChildBeanDefinition("parent");
27232721
child.setBeanClass(TestBean.class);
@@ -2727,8 +2725,7 @@ void scopeInheritanceForChildBeanDefinitions() {
27272725
factory.registerBeanDefinition("child", child);
27282726

27292727
BeanDefinition def = factory.getMergedBeanDefinition("child");
2730-
Object mergedBeanDefinition2 = def.getScope();
2731-
assertThat(mergedBeanDefinition2).as("Child 'scope' not inherited").isEqualTo(mergedBeanDefinition2);
2728+
assertThat(def.getScope()).as("Child 'scope' not inherited").isEqualTo(theParentScope);
27322729
}
27332730

27342731
@Test
@@ -2764,15 +2761,12 @@ public boolean postProcessAfterInstantiation(Object bean, String beanName) throw
27642761
});
27652762
lbf.preInstantiateSingletons();
27662763
TestBean tb = (TestBean) lbf.getBean("test");
2767-
Object mergedBeanDefinition2 = tb.getName();
2768-
assertThat(mergedBeanDefinition2).as("Name was set on field by IAPP").isEqualTo(mergedBeanDefinition2);
2764+
assertThat(tb.getName()).as("Name was set on field by IAPP").isEqualTo(nameSetOnField);
27692765
if (!skipPropertyPopulation) {
2770-
Object mergedBeanDefinition21 = tb.getAge();
2771-
assertThat(mergedBeanDefinition21).as("Property value still set").isEqualTo(mergedBeanDefinition21);
2766+
assertThat(tb.getAge()).as("Property value still set").isEqualTo(ageSetByPropertyValue);
27722767
}
27732768
else {
2774-
Object mergedBeanDefinition21 = tb.getAge();
2775-
assertThat(mergedBeanDefinition21).as("Property value was NOT set and still has default value").isEqualTo(mergedBeanDefinition21);
2769+
assertThat(tb.getAge()).as("Property value was NOT set and still has default value").isEqualTo(0);
27762770
}
27772771
}
27782772

0 commit comments

Comments
 (0)