|
| 1 | +/* |
| 2 | + * Copyright 2002-2011 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.spr8761; |
| 18 | + |
| 19 | +import static org.hamcrest.CoreMatchers.is; |
| 20 | +import static org.junit.Assert.assertThat; |
| 21 | + |
| 22 | +import java.lang.annotation.Retention; |
| 23 | +import java.lang.annotation.RetentionPolicy; |
| 24 | + |
| 25 | +import org.junit.Test; |
| 26 | +import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
| 27 | +import org.springframework.stereotype.Component; |
| 28 | + |
| 29 | +/** |
| 30 | + * Tests cornering the regression reported in SPR-8761. |
| 31 | + * |
| 32 | + * @author Chris Beams |
| 33 | + */ |
| 34 | +public class Spr8761Tests { |
| 35 | + |
| 36 | + /** |
| 37 | + * Prior to the fix for SPR-8761, this test threw because the nested MyComponent |
| 38 | + * annotation was being falsely considered as a 'lite' Configuration class candidate. |
| 39 | + */ |
| 40 | + @Test |
| 41 | + public void repro() { |
| 42 | + AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
| 43 | + ctx.scan(getClass().getPackage().getName()); |
| 44 | + ctx.refresh(); |
| 45 | + assertThat(ctx.containsBean("withNestedAnnotation"), is(true)); |
| 46 | + } |
| 47 | + |
| 48 | +} |
| 49 | + |
| 50 | +@Component |
| 51 | +class WithNestedAnnotation { |
| 52 | + |
| 53 | + @Retention(RetentionPolicy.RUNTIME) |
| 54 | + @Component |
| 55 | + public static @interface MyComponent { |
| 56 | + } |
| 57 | +} |
0 commit comments