Skip to content

Commit edea66a

Browse files
committed
Further tests for getBeanNamesForType(ResolvableType)
Issue: SPR-14097
1 parent 8bfba6a commit edea66a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -109,6 +109,7 @@ public interface ListableBeanFactory extends BeanFactory {
109109
* @return the names of beans (or objects created by FactoryBeans) matching
110110
* the given object type (including subclasses), or an empty array if none
111111
* @since 4.2
112+
* @see #isTypeMatch(String, ResolvableType)
112113
* @see FactoryBean#getObjectType
113114
* @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, ResolvableType)
114115
*/

spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.springframework.beans.factory.support.GenericBeanDefinition;
5656
import org.springframework.beans.factory.support.RootBeanDefinition;
5757
import org.springframework.core.Ordered;
58+
import org.springframework.core.ResolvableType;
5859
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
5960
import org.springframework.core.annotation.Order;
6061
import org.springframework.tests.sample.beans.ITestBean;
@@ -1633,6 +1634,8 @@ public void testGenericsBasedFieldInjectionWithSimpleMatch() {
16331634
assertSame(1, bean.stringRepositoryMap.size());
16341635
assertSame(repo, bean.repositoryMap.get("repo"));
16351636
assertSame(repo, bean.stringRepositoryMap.get("repo"));
1637+
1638+
assertArrayEquals(new String[] {"repo"}, bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class)));
16361639
}
16371640

16381641
@Test
@@ -2018,6 +2021,9 @@ public void testGenericsBasedInjectionIntoTypeVariableSelectingBestMatch() {
20182021
GenericInterface1Impl bean1 = (GenericInterface1Impl) bf.getBean("bean1");
20192022
GenericInterface2Impl bean2 = (GenericInterface2Impl) bf.getBean("bean2");
20202023
assertSame(bean2, bean1.gi2);
2024+
2025+
assertArrayEquals(new String[] {"bean1"}, bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(GenericInterface1.class, String.class)));
2026+
assertArrayEquals(new String[] {"bean2"}, bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(GenericInterface2.class, String.class)));
20212027
}
20222028

20232029
@Test
@@ -3076,7 +3082,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
30763082

30773083
public interface GenericInterface1<T> {
30783084

3079-
public String doSomethingGeneric(T o);
3085+
String doSomethingGeneric(T o);
30803086
}
30813087

30823088

0 commit comments

Comments
 (0)