|
| 1 | +/* |
| 2 | + * Copyright 2002-2015 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.core.annotation; |
| 18 | + |
| 19 | +import java.lang.annotation.Annotation; |
| 20 | +import java.lang.reflect.Method; |
| 21 | + |
| 22 | +import org.junit.Test; |
| 23 | + |
| 24 | +import org.springframework.core.annotation.AnnotationUtilsTests.GroovyImplicitAliasesContextConfigClass; |
| 25 | +import org.springframework.core.annotation.AnnotationUtilsTests.ImplicitAliasesContextConfig; |
| 26 | +import org.springframework.core.annotation.AnnotationUtilsTests.Location1ImplicitAliasesContextConfigClass; |
| 27 | +import org.springframework.core.annotation.AnnotationUtilsTests.Location2ImplicitAliasesContextConfigClass; |
| 28 | +import org.springframework.core.annotation.AnnotationUtilsTests.Location3ImplicitAliasesContextConfigClass; |
| 29 | +import org.springframework.core.annotation.AnnotationUtilsTests.ValueImplicitAliasesContextConfigClass; |
| 30 | +import org.springframework.core.annotation.AnnotationUtilsTests.XmlImplicitAliasesContextConfigClass; |
| 31 | + |
| 32 | +import static org.hamcrest.CoreMatchers.*; |
| 33 | +import static org.junit.Assert.*; |
| 34 | + |
| 35 | +/** |
| 36 | + * Abstract base class for tests involving concrete implementations of |
| 37 | + * {@link AbstractAliasAwareAnnotationAttributeExtractor}. |
| 38 | + * |
| 39 | + * @author Sam Brannen |
| 40 | + * @since 4.2.1 |
| 41 | + */ |
| 42 | +public abstract class AbstractAliasAwareAnnotationAttributeExtractorTestCase { |
| 43 | + |
| 44 | + @Test |
| 45 | + public void getAttributeValueForImplicitAliases() throws Exception { |
| 46 | + assertGetAttributeValueForImplicitAliases(GroovyImplicitAliasesContextConfigClass.class, "groovyScript"); |
| 47 | + assertGetAttributeValueForImplicitAliases(XmlImplicitAliasesContextConfigClass.class, "xmlFile"); |
| 48 | + assertGetAttributeValueForImplicitAliases(ValueImplicitAliasesContextConfigClass.class, "value"); |
| 49 | + assertGetAttributeValueForImplicitAliases(Location1ImplicitAliasesContextConfigClass.class, "location1"); |
| 50 | + assertGetAttributeValueForImplicitAliases(Location2ImplicitAliasesContextConfigClass.class, "location2"); |
| 51 | + assertGetAttributeValueForImplicitAliases(Location3ImplicitAliasesContextConfigClass.class, "location3"); |
| 52 | + } |
| 53 | + |
| 54 | + private void assertGetAttributeValueForImplicitAliases(Class<?> clazz, String expected) throws Exception { |
| 55 | + Method xmlFile = ImplicitAliasesContextConfig.class.getDeclaredMethod("xmlFile"); |
| 56 | + Method groovyScript = ImplicitAliasesContextConfig.class.getDeclaredMethod("groovyScript"); |
| 57 | + Method value = ImplicitAliasesContextConfig.class.getDeclaredMethod("value"); |
| 58 | + |
| 59 | + AnnotationAttributeExtractor<?> extractor = createExtractorFor(clazz, expected, ImplicitAliasesContextConfig.class); |
| 60 | + |
| 61 | + assertThat(extractor.getAttributeValue(value), is(expected)); |
| 62 | + assertThat(extractor.getAttributeValue(groovyScript), is(expected)); |
| 63 | + assertThat(extractor.getAttributeValue(xmlFile), is(expected)); |
| 64 | + } |
| 65 | + |
| 66 | + protected abstract AnnotationAttributeExtractor<?> createExtractorFor(Class<?> clazz, String expected, Class<? extends Annotation> annotationType); |
| 67 | + |
| 68 | +} |
0 commit comments