Polishing

This commit is contained in:
Juergen Hoeller
2014-04-18 13:23:05 +02:00
parent 5aa93674a3
commit ffaac0ecf3
12 changed files with 164 additions and 60 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,19 +16,20 @@
package org.springframework.context.annotation;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.springframework.stereotype.Component;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
/**
* Tests ensuring that nested static @Configuration classes are automatically detected
* and registered without the need for explicit registration or @Import. See SPR-8186.
*
* @author Chris Beams
* @author Juergen Hoeller
* @since 3.1
*/
public class NestedConfigurationClassTests {
@@ -89,9 +90,40 @@ public class NestedConfigurationClassTests {
assertThat(ctx.getBean("overrideBean", TestBean.class).getName(), is("override-s1"));
}
@Test
public void twoLevelsInLiteMode() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(L0ConfigLight.class);
ctx.refresh();
ctx.getBean(L0ConfigLight.class);
ctx.getBean("l0Bean");
ctx.getBean(L0ConfigLight.L1ConfigLight.class);
ctx.getBean("l1Bean");
ctx.getBean(L0ConfigLight.L1ConfigLight.L2ConfigLight.class);
ctx.getBean("l2Bean");
// ensure that override order is correct
assertThat(ctx.getBean("overrideBean", TestBean.class).getName(), is("override-l0"));
}
@Test
public void twoLevelsWithNoBeanMethods() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(L0ConfigEmpty.class);
ctx.refresh();
ctx.getBean(L0ConfigEmpty.class);
ctx.getBean(L0ConfigEmpty.L1ConfigEmpty.class);
ctx.getBean(L0ConfigEmpty.L1ConfigEmpty.L2ConfigEmpty.class);
}
@Configuration
static class L0Config {
@Bean
public TestBean l0Bean() {
return new TestBean("l0");
@@ -104,6 +136,7 @@ public class NestedConfigurationClassTests {
@Configuration
static class L1Config {
@Bean
public TestBean l1Bean() {
return new TestBean("l1");
@@ -116,6 +149,7 @@ public class NestedConfigurationClassTests {
@Configuration
protected static class L2Config {
@Bean
public TestBean l2Bean() {
return new TestBean("l2");
@@ -130,8 +164,65 @@ public class NestedConfigurationClassTests {
}
@Component
static class L0ConfigLight {
@Bean
public TestBean l0Bean() {
return new TestBean("l0");
}
@Bean
public TestBean overrideBean() {
return new TestBean("override-l0");
}
@Component
static class L1ConfigLight {
@Bean
public TestBean l1Bean() {
return new TestBean("l1");
}
@Bean
public TestBean overrideBean() {
return new TestBean("override-l1");
}
@Component
protected static class L2ConfigLight {
@Bean
public TestBean l2Bean() {
return new TestBean("l2");
}
@Bean
public TestBean overrideBean() {
return new TestBean("override-l2");
}
}
}
}
@Component
static class L0ConfigEmpty {
@Component
static class L1ConfigEmpty {
@Component
protected static class L2ConfigEmpty {
}
}
}
@Configuration
static class S1Config extends L0Config {
@Override
@Bean
public TestBean overrideBean() {
@@ -139,4 +230,4 @@ public class NestedConfigurationClassTests {
}
}
}
}

View File

@@ -1,4 +1,3 @@
/*
* Copyright 2002-2012 the original author or authors.
*
@@ -17,19 +16,10 @@
package org.springframework.tests.sample.beans;
import org.springframework.tests.sample.beans.TestBean;
public class Employee extends TestBean {
private String co;
/**
* Constructor for Employee.
*/
public Employee() {
super();
}
public String getCompany() {
return co;
}