Test injection point match for narrow target return type
Issue: SPR-14960
(cherry picked from commit 845dbf0)
This commit is contained in:
@@ -609,6 +609,12 @@ public class ConfigurationClassPostProcessorTests {
|
||||
ctx.getBean("aFoo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInjectionPointMatchForNarrowTargetReturnType() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(FooBarConfiguration.class);
|
||||
assertSame(ctx.getBean(BarImpl.class), ctx.getBean(FooImpl.class).bar);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -856,7 +862,7 @@ public class ConfigurationClassPostProcessorTests {
|
||||
|
||||
@Bean
|
||||
public Repository<Object> genericRepo() {
|
||||
return new GenericRepository<Object>();
|
||||
return new GenericRepository<>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -918,12 +924,12 @@ public class ConfigurationClassPostProcessorTests {
|
||||
|
||||
@Bean
|
||||
public Repository<? extends String> stringRepo() {
|
||||
return new Repository<String>();
|
||||
return new Repository<>();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Repository<? extends Number> numberRepo() {
|
||||
return new Repository<Number>();
|
||||
return new Repository<>();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -942,7 +948,7 @@ public class ConfigurationClassPostProcessorTests {
|
||||
|
||||
@Bean
|
||||
public Repository<? extends Number> numberRepo() {
|
||||
return new Repository<Number>();
|
||||
return new Repository<>();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -1115,7 +1121,7 @@ public class ConfigurationClassPostProcessorTests {
|
||||
@Configuration
|
||||
public static class A {
|
||||
|
||||
@Autowired(required=true)
|
||||
@Autowired(required = true)
|
||||
Z z;
|
||||
|
||||
@Bean
|
||||
@@ -1221,4 +1227,30 @@ public class ConfigurationClassPostProcessorTests {
|
||||
abstract DependingFoo createFoo(BarArgument bar);
|
||||
}
|
||||
|
||||
interface BarInterface {
|
||||
}
|
||||
|
||||
static class BarImpl implements BarInterface {
|
||||
}
|
||||
|
||||
static class FooImpl {
|
||||
|
||||
@Autowired
|
||||
public BarImpl bar;
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class FooBarConfiguration {
|
||||
|
||||
@Bean @DependsOn("bar")
|
||||
public FooImpl foo() {
|
||||
return new FooImpl();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public BarInterface bar() {
|
||||
return new BarImpl();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user