|
| 1 | +/* |
| 2 | + * Copyright 2002-2014 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.context.annotation.spr12233; |
| 18 | + |
| 19 | +import org.junit.Test; |
| 20 | +import org.springframework.beans.factory.annotation.Value; |
| 21 | +import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
| 22 | +import org.springframework.context.annotation.ComponentScan; |
| 23 | +import org.springframework.context.annotation.ConditionContext; |
| 24 | +import org.springframework.context.annotation.Conditional; |
| 25 | +import org.springframework.context.annotation.Configuration; |
| 26 | +import org.springframework.context.annotation.ConfigurationCondition; |
| 27 | +import org.springframework.context.annotation.Import; |
| 28 | +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; |
| 29 | +import org.springframework.core.type.AnnotatedTypeMetadata; |
| 30 | + |
| 31 | + |
| 32 | +/** |
| 33 | + * Tests cornering the regression reported in SPR-12233. |
| 34 | + * |
| 35 | + * @author Phillip Webb |
| 36 | + */ |
| 37 | +public class Spr12233Tests { |
| 38 | + |
| 39 | + @Test |
| 40 | + public void spr12233() throws Exception { |
| 41 | + AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
| 42 | + ctx.register(PropertySourcesPlaceholderConfigurer.class); |
| 43 | + ctx.register(ImportConfiguration.class); |
| 44 | + ctx.refresh(); |
| 45 | + ctx.close(); |
| 46 | + } |
| 47 | + |
| 48 | + static class NeverConfigurationCondition implements ConfigurationCondition { |
| 49 | + @Override |
| 50 | + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { |
| 51 | + return false; |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public ConfigurationPhase getConfigurationPhase() { |
| 56 | + return ConfigurationPhase.REGISTER_BEAN; |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + @Import(ComponentScanningConfiguration.class) |
| 61 | + static class ImportConfiguration { |
| 62 | + |
| 63 | + } |
| 64 | + |
| 65 | + @Configuration |
| 66 | + @ComponentScan |
| 67 | + static class ComponentScanningConfiguration { |
| 68 | + |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + @Configuration |
| 73 | + @Conditional(NeverConfigurationCondition.class) |
| 74 | + static class ConditionWithPropertyValueInjection { |
| 75 | + |
| 76 | + @Value("${idontexist}") |
| 77 | + private String property; |
| 78 | + } |
| 79 | +} |
0 commit comments