Browse Source

Polish @Conditional Javadoc and tests

pull/299/merge
Sam Brannen 12 years ago
parent
commit
96e1fbc3bb
  1. 2
      spring-context/src/main/java/org/springframework/context/annotation/Conditional.java
  2. 19
      spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassWithConditionTests.java

2
spring-context/src/main/java/org/springframework/context/annotation/Conditional.java

@ -22,7 +22,7 @@ import java.lang.annotation.RetentionPolicy; @@ -22,7 +22,7 @@ import java.lang.annotation.RetentionPolicy;
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.
*
* <p>A <em>condition</em> is any state that can be determined programmatically

19
spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassWithConditionTests.java

@ -27,6 +27,7 @@ import java.lang.annotation.Retention; @@ -27,6 +27,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@ -36,18 +37,24 @@ import org.springframework.core.type.AnnotatedTypeMetadata; @@ -36,18 +37,24 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.stereotype.Component;
/**
* Test for {@link Conditional} beans.
*
* Tests for {@link Conditional} beans.
*
* @author Phillip Webb
*/
public class ConfigurationClassWithConditionTests {
private final AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@Rule
public ExpectedException thrown = ExpectedException.none();
@After
public void closeContext() {
ctx.close();
}
@Test
public void conditionalOnMissingBeanMatch() throws Exception {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(BeanOneConfiguration.class, BeanTwoConfiguration.class);
ctx.refresh();
assertTrue(ctx.containsBean("bean1"));
@ -57,7 +64,6 @@ public class ConfigurationClassWithConditionTests { @@ -57,7 +64,6 @@ public class ConfigurationClassWithConditionTests {
@Test
public void conditionalOnMissingBeanNoMatch() throws Exception {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(BeanTwoConfiguration.class);
ctx.refresh();
assertFalse(ctx.containsBean("bean1"));
@ -67,7 +73,6 @@ public class ConfigurationClassWithConditionTests { @@ -67,7 +73,6 @@ public class ConfigurationClassWithConditionTests {
@Test
public void conditionalOnBeanMatch() throws Exception {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(BeanOneConfiguration.class, BeanThreeConfiguration.class);
ctx.refresh();
assertTrue(ctx.containsBean("bean1"));
@ -76,7 +81,6 @@ public class ConfigurationClassWithConditionTests { @@ -76,7 +81,6 @@ public class ConfigurationClassWithConditionTests {
@Test
public void conditionalOnBeanNoMatch() throws Exception {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(BeanThreeConfiguration.class);
ctx.refresh();
assertFalse(ctx.containsBean("bean1"));
@ -85,7 +89,6 @@ public class ConfigurationClassWithConditionTests { @@ -85,7 +89,6 @@ public class ConfigurationClassWithConditionTests {
@Test
public void metaConditional() throws Exception {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigurationWithMetaCondition.class);
ctx.refresh();
assertTrue(ctx.containsBean("bean"));
@ -93,7 +96,6 @@ public class ConfigurationClassWithConditionTests { @@ -93,7 +96,6 @@ public class ConfigurationClassWithConditionTests {
@Test
public void nonConfigurationClass() throws Exception {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(NonConfigurationClass.class);
ctx.refresh();
thrown.expect(NoSuchBeanDefinitionException.class);
@ -102,7 +104,6 @@ public class ConfigurationClassWithConditionTests { @@ -102,7 +104,6 @@ public class ConfigurationClassWithConditionTests {
@Test
public void methodConditional() throws Exception {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConditionOnMethodConfiguration.class);
ctx.refresh();
thrown.expect(NoSuchBeanDefinitionException.class);

Loading…
Cancel
Save