Polish ConditionalOn annotations

Update ConditionalOn annotations :
- Use consistent attribute names for OnClass and OnMissingClass
- Update javadoc
- Rename tests to reflect the annotation rather than the interface
This commit is contained in:
Phillip Webb 2013-08-12 22:17:13 -07:00
parent 0d583deb27
commit 1ff76459db
11 changed files with 32 additions and 31 deletions

View File

@ -44,8 +44,7 @@ public @interface ConditionalOnClass {
public Class<?>[] value() default {};
/**
* The classes names that must be present. When possible {@link #value()} should be
* used in preference to this property.
* The classes names that must be present.
* @return the class names that must be present.
*/
public String[] name() default {};

View File

@ -35,7 +35,8 @@ import org.springframework.context.annotation.Conditional;
public @interface ConditionalOnExpression {
/**
* The SpEL expression.
* The SpEL expression to evaluate. Expression should return {@code true} if the
* condition passes or {@code false} if it fails.
*/
String value() default "true";
}

View File

@ -25,7 +25,8 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Conditional;
/**
* {@link Conditional} that only matches when the specified classes are on the classpath.
* {@link Conditional} that only matches when the specified classes are not on the
* classpath.
*
* @author Dave Syer
*/
@ -36,8 +37,17 @@ import org.springframework.context.annotation.Conditional;
public @interface ConditionalOnMissingClass {
/**
* The classes names that must be absent.
* @return the class names that must be absent.
* The classes that must not be present. Since this annotation parsed by loading class
* bytecode it is safe to specify classes here that may ultimately not be on the
* classpath.
* @return the classes that must be present
*/
public String[] value() default {};
public Class<?>[] value() default {};
/**
* The classes names that must not be present.
* @return the class names that must be present.
*/
public String[] name() default {};
}

View File

@ -33,7 +33,7 @@ import static org.junit.Assert.assertTrue;
* @author Dave Syer
*/
@Ignore
public class OnBeanConditionTests {
public class ConditionalOnBeanTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

View File

@ -17,8 +17,6 @@
package org.springframework.boot.autoconfigure.condition;
import org.junit.Test;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.OnClassCondition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -30,11 +28,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link OnClassCondition}.
* Tests for {@link ConditionalOnClass}.
*
* @author Dave Syer
*/
public class OnClassConditionTests {
public class ConditionalOnClassTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@ -71,7 +69,7 @@ public class OnClassConditionTests {
}
@Configuration
@ConditionalOnClass(OnClassConditionTests.class)
@ConditionalOnClass(ConditionalOnClassTests.class)
protected static class BasicConfiguration {
@Bean
public String bar() {

View File

@ -17,8 +17,6 @@
package org.springframework.boot.autoconfigure.condition;
import org.junit.Test;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.OnExpressionCondition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -28,11 +26,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link OnExpressionCondition}.
* Tests for {@link ConditionalOnExpression}.
*
* @author Dave Syer
*/
public class OnExpressionConditionTests {
public class ConditionalOnExpressionTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

View File

@ -34,7 +34,7 @@ import static org.junit.Assert.assertTrue;
* @author Phillip Webb
*/
@SuppressWarnings("resource")
public class OnMissingBeanConditionTests {
public class ConditionalOnMissingBeanTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

View File

@ -30,7 +30,7 @@ import static org.junit.Assert.assertTrue;
*
* @author Dave Syer
*/
public class OnMissingClassConditionTests {
public class ConditionalOnMissingClassTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@ -51,7 +51,7 @@ public class OnMissingClassConditionTests {
}
@Configuration
@ConditionalOnMissingClass("org.springframework.boot.autoconfigure.condition.OnMissingClassConditionTests")
@ConditionalOnMissingClass(ConditionalOnMissingClassTests.class)
protected static class BasicConfiguration {
@Bean
public String bar() {
@ -60,7 +60,7 @@ public class OnMissingClassConditionTests {
}
@Configuration
@ConditionalOnMissingClass("FOO")
@ConditionalOnMissingClass(name = "FOO")
protected static class MissingConfiguration {
@Bean
public String bar() {

View File

@ -30,7 +30,7 @@ import static org.junit.Assert.assertTrue;
*
* @author Dave Syer
*/
public class OnNotWebApplicationConditionTests {
public class ConditionalOnNotWebApplicationTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

View File

@ -17,8 +17,6 @@
package org.springframework.boot.autoconfigure.condition;
import org.junit.Test;
import org.springframework.boot.autoconfigure.condition.ConditionalOnResource;
import org.springframework.boot.autoconfigure.condition.OnResourceCondition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -28,11 +26,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link OnResourceCondition}.
* Tests for {@link ConditionalOnResource}.
*
* @author Dave Syer
*/
public class OnResourceConditionTests {
public class ConditionalOnResourceTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

View File

@ -17,9 +17,6 @@
package org.springframework.boot.autoconfigure.condition;
import org.junit.Test;
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockServletContext;
@ -30,11 +27,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link OnWebApplicationCondition}.
* Tests for {@link ConditionalOnWebApplication}.
*
* @author Dave Syer
*/
public class OnWebApplicationConditionTests {
public class ConditionalOnWebApplicationTests {
private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();