Browse Source

Refined tests for FactoryBean return type resolution on @Bean methods

Issue: SPR-11842
pull/547/merge
Juergen Hoeller 11 years ago
parent
commit
ae66e45887
  1. 24
      spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerFactoryBeanIntegrationTests.java

24
spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerFactoryBeanIntegrationTests.java

@ -18,12 +18,15 @@ package org.springframework.remoting.httpinvoker; @@ -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.*; @@ -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 { @@ -46,7 +58,7 @@ public class HttpInvokerFactoryBeanIntegrationTests {
}
@Component
@Component("myBean")
public static class MyBean {
@Autowired
@ -56,6 +68,7 @@ public class HttpInvokerFactoryBeanIntegrationTests { @@ -56,6 +68,7 @@ public class HttpInvokerFactoryBeanIntegrationTests {
@Configuration
@ComponentScan
@Lazy
public static class InvokerAutowiringConfig {
@Bean
@ -65,6 +78,11 @@ public class HttpInvokerFactoryBeanIntegrationTests { @@ -65,6 +78,11 @@ public class HttpInvokerFactoryBeanIntegrationTests {
factory.setServiceInterface(MyService.class);
return factory;
}
@Bean
public FactoryBean<String> myOtherService() {
throw new IllegalStateException("Don't ever call me");
}
}
}

Loading…
Cancel
Save