@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2012 - 2016 the original author or authors .
* Copyright 2012 - 2017 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 .
@ -26,10 +26,14 @@ import org.junit.Rule;
@@ -26,10 +26,14 @@ import org.junit.Rule;
import org.junit.Test ;
import org.junit.rules.ExpectedException ;
import org.springframework.boot.WebApplicationType ;
import org.springframework.boot.builder.SpringApplicationBuilder ;
import org.springframework.boot.test.util.EnvironmentTestUtils ;
import org.springframework.context.annotation.AnnotationConfigApplicationContext ;
import org.springframework.context.Configurable ApplicationContext ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.core.env.ConfigurableEnvironment ;
import org.springframework.core.env.StandardEnvironment ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.hamcrest.Matchers.containsString ;
@ -48,7 +52,9 @@ public class ConditionalOnPropertyTests {
@@ -48,7 +52,9 @@ public class ConditionalOnPropertyTests {
@Rule
public ExpectedException thrown = ExpectedException . none ( ) ;
private AnnotationConfigApplicationContext context ;
private ConfigurableApplicationContext context ;
private ConfigurableEnvironment environment = new StandardEnvironment ( ) ;
@After
public void tearDown ( ) {
@ -98,13 +104,6 @@ public class ConditionalOnPropertyTests {
@@ -98,13 +104,6 @@ public class ConditionalOnPropertyTests {
assertThat ( this . context . containsBean ( "foo" ) ) . isTrue ( ) ;
}
@Test
public void nonRelaxedName ( ) throws Exception {
load ( NonRelaxedPropertiesRequiredConfiguration . class ,
"theRelaxedProperty=value1" ) ;
assertThat ( this . context . containsBean ( "foo" ) ) . isFalse ( ) ;
}
@Test
// Enabled by default
public void enabledIfNotConfiguredOtherwise ( ) {
@ -185,18 +184,6 @@ public class ConditionalOnPropertyTests {
@@ -185,18 +184,6 @@ public class ConditionalOnPropertyTests {
assertThat ( this . context . containsBean ( "foo" ) ) . isTrue ( ) ;
}
@Test
public void strictNameMatch ( ) {
load ( StrictNameConfig . class , "simple.my-property:bar" ) ;
assertThat ( this . context . containsBean ( "foo" ) ) . isTrue ( ) ;
}
@Test
public void strictNameNoMatch ( ) {
load ( StrictNameConfig . class , "simple.myProperty:bar" ) ;
assertThat ( this . context . containsBean ( "foo" ) ) . isFalse ( ) ;
}
@Test
public void multiValuesAllSet ( ) {
load ( MultiValuesConfig . class , "simple.my-property:bar" ,
@ -271,10 +258,9 @@ public class ConditionalOnPropertyTests {
@@ -271,10 +258,9 @@ public class ConditionalOnPropertyTests {
}
private void load ( Class < ? > config , String . . . environment ) {
this . context = new AnnotationConfigApplicationContext ( ) ;
EnvironmentTestUtils . addEnvironment ( this . context , environment ) ;
this . context . register ( config ) ;
this . context . refresh ( ) ;
EnvironmentTestUtils . addEnvironment ( this . environment , environment ) ;
this . context = new SpringApplicationBuilder ( config ) . environment ( this . environment )
. web ( WebApplicationType . NONE ) . run ( ) ;
}
@Configuration
@ -310,17 +296,6 @@ public class ConditionalOnPropertyTests {
@@ -310,17 +296,6 @@ public class ConditionalOnPropertyTests {
}
@Configuration
@ConditionalOnProperty ( name = "the-relaxed-property" , relaxedNames = false )
protected static class NonRelaxedPropertiesRequiredConfiguration {
@Bean
public String foo ( ) {
return "foo" ;
}
}
@Configuration
// i.e ${simple.myProperty:true}
@ConditionalOnProperty ( prefix = "simple" , name = "my-property" , havingValue = "true" , matchIfMissing = true )
@ -378,17 +353,6 @@ public class ConditionalOnPropertyTests {
@@ -378,17 +353,6 @@ public class ConditionalOnPropertyTests {
}
@Configuration
@ConditionalOnProperty ( prefix = "simple" , name = "my-property" , havingValue = "bar" , relaxedNames = false )
static class StrictNameConfig {
@Bean
public String foo ( ) {
return "foo" ;
}
}
@Configuration
@ConditionalOnProperty ( prefix = "simple" , name = { "my-property" ,
"my-another-property" } , havingValue = "bar" )
@ -434,6 +398,7 @@ public class ConditionalOnPropertyTests {
@@ -434,6 +398,7 @@ public class ConditionalOnPropertyTests {
}
@Configuration
@ConditionalOnMyFeature
protected static class MetaAnnotation {
@ -444,6 +409,7 @@ public class ConditionalOnPropertyTests {
@@ -444,6 +409,7 @@ public class ConditionalOnPropertyTests {
}
@Configuration
@ConditionalOnMyFeature
@ConditionalOnProperty ( prefix = "my.other.feature" , name = "enabled" , havingValue = "true" , matchIfMissing = false )
protected static class MetaAnnotationAndDirectAnnotation {