Commit 1ff76459 authored by Phillip Webb's avatar Phillip Webb

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
parent 0d583deb
...@@ -44,8 +44,7 @@ public @interface ConditionalOnClass { ...@@ -44,8 +44,7 @@ public @interface ConditionalOnClass {
public Class<?>[] value() default {}; public Class<?>[] value() default {};
/** /**
* The classes names that must be present. When possible {@link #value()} should be * The classes names that must be present.
* used in preference to this property.
* @return the class names that must be present. * @return the class names that must be present.
*/ */
public String[] name() default {}; public String[] name() default {};
......
...@@ -35,7 +35,8 @@ import org.springframework.context.annotation.Conditional; ...@@ -35,7 +35,8 @@ import org.springframework.context.annotation.Conditional;
public @interface ConditionalOnExpression { 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"; String value() default "true";
} }
...@@ -25,7 +25,8 @@ import java.lang.annotation.Target; ...@@ -25,7 +25,8 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Conditional; 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 * @author Dave Syer
*/ */
...@@ -36,8 +37,17 @@ import org.springframework.context.annotation.Conditional; ...@@ -36,8 +37,17 @@ import org.springframework.context.annotation.Conditional;
public @interface ConditionalOnMissingClass { public @interface ConditionalOnMissingClass {
/** /**
* The classes names that must be absent. * The classes that must not be present. Since this annotation parsed by loading class
* @return the class names that must be absent. * 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 {};
} }
...@@ -33,7 +33,7 @@ import static org.junit.Assert.assertTrue; ...@@ -33,7 +33,7 @@ import static org.junit.Assert.assertTrue;
* @author Dave Syer * @author Dave Syer
*/ */
@Ignore @Ignore
public class OnBeanConditionTests { public class ConditionalOnBeanTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
package org.springframework.boot.autoconfigure.condition; package org.springframework.boot.autoconfigure.condition;
import org.junit.Test; 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.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -30,11 +28,11 @@ import static org.junit.Assert.assertFalse; ...@@ -30,11 +28,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link OnClassCondition}. * Tests for {@link ConditionalOnClass}.
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class OnClassConditionTests { public class ConditionalOnClassTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
...@@ -71,7 +69,7 @@ public class OnClassConditionTests { ...@@ -71,7 +69,7 @@ public class OnClassConditionTests {
} }
@Configuration @Configuration
@ConditionalOnClass(OnClassConditionTests.class) @ConditionalOnClass(ConditionalOnClassTests.class)
protected static class BasicConfiguration { protected static class BasicConfiguration {
@Bean @Bean
public String bar() { public String bar() {
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
package org.springframework.boot.autoconfigure.condition; package org.springframework.boot.autoconfigure.condition;
import org.junit.Test; 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.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -28,11 +26,11 @@ import static org.junit.Assert.assertFalse; ...@@ -28,11 +26,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link OnExpressionCondition}. * Tests for {@link ConditionalOnExpression}.
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class OnExpressionConditionTests { public class ConditionalOnExpressionTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
......
...@@ -34,7 +34,7 @@ import static org.junit.Assert.assertTrue; ...@@ -34,7 +34,7 @@ import static org.junit.Assert.assertTrue;
* @author Phillip Webb * @author Phillip Webb
*/ */
@SuppressWarnings("resource") @SuppressWarnings("resource")
public class OnMissingBeanConditionTests { public class ConditionalOnMissingBeanTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
......
...@@ -30,7 +30,7 @@ import static org.junit.Assert.assertTrue; ...@@ -30,7 +30,7 @@ import static org.junit.Assert.assertTrue;
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class OnMissingClassConditionTests { public class ConditionalOnMissingClassTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
...@@ -51,7 +51,7 @@ public class OnMissingClassConditionTests { ...@@ -51,7 +51,7 @@ public class OnMissingClassConditionTests {
} }
@Configuration @Configuration
@ConditionalOnMissingClass("org.springframework.boot.autoconfigure.condition.OnMissingClassConditionTests") @ConditionalOnMissingClass(ConditionalOnMissingClassTests.class)
protected static class BasicConfiguration { protected static class BasicConfiguration {
@Bean @Bean
public String bar() { public String bar() {
...@@ -60,7 +60,7 @@ public class OnMissingClassConditionTests { ...@@ -60,7 +60,7 @@ public class OnMissingClassConditionTests {
} }
@Configuration @Configuration
@ConditionalOnMissingClass("FOO") @ConditionalOnMissingClass(name = "FOO")
protected static class MissingConfiguration { protected static class MissingConfiguration {
@Bean @Bean
public String bar() { public String bar() {
......
...@@ -30,7 +30,7 @@ import static org.junit.Assert.assertTrue; ...@@ -30,7 +30,7 @@ import static org.junit.Assert.assertTrue;
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class OnNotWebApplicationConditionTests { public class ConditionalOnNotWebApplicationTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
package org.springframework.boot.autoconfigure.condition; package org.springframework.boot.autoconfigure.condition;
import org.junit.Test; 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.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -28,11 +26,11 @@ import static org.junit.Assert.assertFalse; ...@@ -28,11 +26,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link OnResourceCondition}. * Tests for {@link ConditionalOnResource}.
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class OnResourceConditionTests { public class ConditionalOnResourceTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
......
...@@ -17,9 +17,6 @@ ...@@ -17,9 +17,6 @@
package org.springframework.boot.autoconfigure.condition; package org.springframework.boot.autoconfigure.condition;
import org.junit.Test; 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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockServletContext; import org.springframework.mock.web.MockServletContext;
...@@ -30,11 +27,11 @@ import static org.junit.Assert.assertFalse; ...@@ -30,11 +27,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link OnWebApplicationCondition}. * Tests for {@link ConditionalOnWebApplication}.
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class OnWebApplicationConditionTests { public class ConditionalOnWebApplicationTests {
private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment