Polish @Conditional Javadoc and tests
This commit is contained in:
parent
239ce1466c
commit
96e1fbc3bb
|
|
@ -22,7 +22,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that a component is is only eligible for registration when all
|
* Indicates that a component is only eligible for registration when all
|
||||||
* {@linkplain #value() specified conditions} match.
|
* {@linkplain #value() specified conditions} match.
|
||||||
*
|
*
|
||||||
* <p>A <em>condition</em> is any state that can be determined programmatically
|
* <p>A <em>condition</em> is any state that can be determined programmatically
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
@ -36,18 +37,24 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link Conditional} beans.
|
* Tests for {@link Conditional} beans.
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
*/
|
*/
|
||||||
public class ConfigurationClassWithConditionTests {
|
public class ConfigurationClassWithConditionTests {
|
||||||
|
|
||||||
|
private final AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
public ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void closeContext() {
|
||||||
|
ctx.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void conditionalOnMissingBeanMatch() throws Exception {
|
public void conditionalOnMissingBeanMatch() throws Exception {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
|
||||||
ctx.register(BeanOneConfiguration.class, BeanTwoConfiguration.class);
|
ctx.register(BeanOneConfiguration.class, BeanTwoConfiguration.class);
|
||||||
ctx.refresh();
|
ctx.refresh();
|
||||||
assertTrue(ctx.containsBean("bean1"));
|
assertTrue(ctx.containsBean("bean1"));
|
||||||
|
|
@ -57,7 +64,6 @@ public class ConfigurationClassWithConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void conditionalOnMissingBeanNoMatch() throws Exception {
|
public void conditionalOnMissingBeanNoMatch() throws Exception {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
|
||||||
ctx.register(BeanTwoConfiguration.class);
|
ctx.register(BeanTwoConfiguration.class);
|
||||||
ctx.refresh();
|
ctx.refresh();
|
||||||
assertFalse(ctx.containsBean("bean1"));
|
assertFalse(ctx.containsBean("bean1"));
|
||||||
|
|
@ -67,7 +73,6 @@ public class ConfigurationClassWithConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void conditionalOnBeanMatch() throws Exception {
|
public void conditionalOnBeanMatch() throws Exception {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
|
||||||
ctx.register(BeanOneConfiguration.class, BeanThreeConfiguration.class);
|
ctx.register(BeanOneConfiguration.class, BeanThreeConfiguration.class);
|
||||||
ctx.refresh();
|
ctx.refresh();
|
||||||
assertTrue(ctx.containsBean("bean1"));
|
assertTrue(ctx.containsBean("bean1"));
|
||||||
|
|
@ -76,7 +81,6 @@ public class ConfigurationClassWithConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void conditionalOnBeanNoMatch() throws Exception {
|
public void conditionalOnBeanNoMatch() throws Exception {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
|
||||||
ctx.register(BeanThreeConfiguration.class);
|
ctx.register(BeanThreeConfiguration.class);
|
||||||
ctx.refresh();
|
ctx.refresh();
|
||||||
assertFalse(ctx.containsBean("bean1"));
|
assertFalse(ctx.containsBean("bean1"));
|
||||||
|
|
@ -85,7 +89,6 @@ public class ConfigurationClassWithConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void metaConditional() throws Exception {
|
public void metaConditional() throws Exception {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
|
||||||
ctx.register(ConfigurationWithMetaCondition.class);
|
ctx.register(ConfigurationWithMetaCondition.class);
|
||||||
ctx.refresh();
|
ctx.refresh();
|
||||||
assertTrue(ctx.containsBean("bean"));
|
assertTrue(ctx.containsBean("bean"));
|
||||||
|
|
@ -93,7 +96,6 @@ public class ConfigurationClassWithConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nonConfigurationClass() throws Exception {
|
public void nonConfigurationClass() throws Exception {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
|
||||||
ctx.register(NonConfigurationClass.class);
|
ctx.register(NonConfigurationClass.class);
|
||||||
ctx.refresh();
|
ctx.refresh();
|
||||||
thrown.expect(NoSuchBeanDefinitionException.class);
|
thrown.expect(NoSuchBeanDefinitionException.class);
|
||||||
|
|
@ -102,7 +104,6 @@ public class ConfigurationClassWithConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void methodConditional() throws Exception {
|
public void methodConditional() throws Exception {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
|
||||||
ctx.register(ConditionOnMethodConfiguration.class);
|
ctx.register(ConditionOnMethodConfiguration.class);
|
||||||
ctx.refresh();
|
ctx.refresh();
|
||||||
thrown.expect(NoSuchBeanDefinitionException.class);
|
thrown.expect(NoSuchBeanDefinitionException.class);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue