From ae66e45887480ff6ffffdc6dadba39ec60a74a33 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 7 Jun 2014 00:24:45 +0200 Subject: [PATCH] Refined tests for FactoryBean return type resolution on @Bean methods Issue: SPR-11842 --- ...ttpInvokerFactoryBeanIntegrationTests.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerFactoryBeanIntegrationTests.java b/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerFactoryBeanIntegrationTests.java index c4a93ce17e0..887e02a23db 100644 --- a/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerFactoryBeanIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerFactoryBeanIntegrationTests.java @@ -18,12 +18,15 @@ package org.springframework.remoting.httpinvoker; import org.junit.Test; +import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import static org.junit.Assert.*; @@ -35,9 +38,18 @@ import static org.junit.Assert.*; public class HttpInvokerFactoryBeanIntegrationTests { @Test - public void foo() { + public void testLoadedConfigClass() { ApplicationContext context = new AnnotationConfigApplicationContext(InvokerAutowiringConfig.class); - MyBean myBean = context.getBean(MyBean.class); + MyBean myBean = context.getBean("myBean", MyBean.class); + assertSame(context.getBean("myService"), myBean.myService); + } + + @Test + public void testNonLoadedConfigClass() { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + context.registerBeanDefinition("config", new RootBeanDefinition(InvokerAutowiringConfig.class.getName())); + context.refresh(); + MyBean myBean = context.getBean("myBean", MyBean.class); assertSame(context.getBean("myService"), myBean.myService); } @@ -46,7 +58,7 @@ public class HttpInvokerFactoryBeanIntegrationTests { } - @Component + @Component("myBean") public static class MyBean { @Autowired @@ -56,6 +68,7 @@ public class HttpInvokerFactoryBeanIntegrationTests { @Configuration @ComponentScan + @Lazy public static class InvokerAutowiringConfig { @Bean @@ -65,6 +78,11 @@ public class HttpInvokerFactoryBeanIntegrationTests { factory.setServiceInterface(MyService.class); return factory; } + + @Bean + public FactoryBean myOtherService() { + throw new IllegalStateException("Don't ever call me"); + } } }