|
|
|
|
@ -1520,9 +1520,10 @@ class MergedAnnotationsTests {
@@ -1520,9 +1520,10 @@ class MergedAnnotationsTests {
|
|
|
|
|
RequestMapping synthesizedWebMapping = MergedAnnotation.from(webMapping).synthesize(); |
|
|
|
|
RequestMapping synthesizedAgainWebMapping = MergedAnnotation.from(synthesizedWebMapping).synthesize(); |
|
|
|
|
|
|
|
|
|
assertThat(synthesizedWebMapping).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertThat(synthesizedAgainWebMapping).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesizedWebMapping); |
|
|
|
|
assertSynthesized(synthesizedAgainWebMapping); |
|
|
|
|
assertThat(synthesizedWebMapping).isEqualTo(synthesizedAgainWebMapping); |
|
|
|
|
assertThat(synthesizedWebMapping).isSameAs(synthesizedAgainWebMapping); |
|
|
|
|
assertThat(synthesizedWebMapping.name()).isEqualTo("foo"); |
|
|
|
|
assertThat(synthesizedWebMapping.path()).containsExactly("/test"); |
|
|
|
|
assertThat(synthesizedWebMapping.value()).containsExactly("/test"); |
|
|
|
|
@ -1537,7 +1538,7 @@ class MergedAnnotationsTests {
@@ -1537,7 +1538,7 @@ class MergedAnnotationsTests {
|
|
|
|
|
Id synthesizedId = MergedAnnotation.from(id).synthesize(); |
|
|
|
|
assertThat(id).isEqualTo(synthesizedId); |
|
|
|
|
// It doesn't make sense to synthesize @Id since it declares zero attributes.
|
|
|
|
|
assertThat(synthesizedId).isNotInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertNotSynthesized(synthesizedId); |
|
|
|
|
assertThat(id).isSameAs(synthesizedId); |
|
|
|
|
|
|
|
|
|
GeneratedValue generatedValue = method.getAnnotation(GeneratedValue.class); |
|
|
|
|
@ -1545,7 +1546,7 @@ class MergedAnnotationsTests {
@@ -1545,7 +1546,7 @@ class MergedAnnotationsTests {
|
|
|
|
|
GeneratedValue synthesizedGeneratedValue = MergedAnnotation.from(generatedValue).synthesize(); |
|
|
|
|
assertThat(generatedValue).isEqualTo(synthesizedGeneratedValue); |
|
|
|
|
// It doesn't make sense to synthesize @GeneratedValue since it declares zero attributes with aliases.
|
|
|
|
|
assertThat(synthesizedGeneratedValue).isNotInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertNotSynthesized(synthesizedGeneratedValue); |
|
|
|
|
assertThat(generatedValue).isSameAs(synthesizedGeneratedValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1555,19 +1556,19 @@ class MergedAnnotationsTests {
@@ -1555,19 +1556,19 @@ class MergedAnnotationsTests {
|
|
|
|
|
MergedAnnotations mergedAnnotations = MergedAnnotations.from(directlyAnnotatedField); |
|
|
|
|
RootAnnotation rootAnnotation = mergedAnnotations.get(RootAnnotation.class).synthesize(); |
|
|
|
|
assertThat(rootAnnotation.flag()).isFalse(); |
|
|
|
|
assertThat(rootAnnotation).isNotInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertNotSynthesized(rootAnnotation); |
|
|
|
|
|
|
|
|
|
Field metaAnnotatedField = ReflectionUtils.findField(DomainType.class, "metaAnnotated"); |
|
|
|
|
mergedAnnotations = MergedAnnotations.from(metaAnnotatedField); |
|
|
|
|
rootAnnotation = mergedAnnotations.get(RootAnnotation.class).synthesize(); |
|
|
|
|
assertThat(rootAnnotation.flag()).isTrue(); |
|
|
|
|
assertThat(rootAnnotation).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(rootAnnotation); |
|
|
|
|
|
|
|
|
|
Field metaMetaAnnotatedField = ReflectionUtils.findField(DomainType.class, "metaMetaAnnotated"); |
|
|
|
|
mergedAnnotations = MergedAnnotations.from(metaMetaAnnotatedField); |
|
|
|
|
rootAnnotation = mergedAnnotations.get(RootAnnotation.class).synthesize(); |
|
|
|
|
assertThat(rootAnnotation.flag()).isTrue(); |
|
|
|
|
assertThat(rootAnnotation).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(rootAnnotation); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // gh-28704
|
|
|
|
|
@ -1578,13 +1579,14 @@ class MergedAnnotationsTests {
@@ -1578,13 +1579,14 @@ class MergedAnnotationsTests {
|
|
|
|
|
mergedAnnotations.get(EnableWebSecurity.class); |
|
|
|
|
assertThat(enableWebSecurityAnnotation.isSynthesizable()).isFalse(); |
|
|
|
|
EnableWebSecurity enableWebSecurity = enableWebSecurityAnnotation.synthesize(); |
|
|
|
|
assertThat(enableWebSecurity).isNotInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertNotSynthesized(enableWebSecurity); |
|
|
|
|
|
|
|
|
|
MergedAnnotation<EnableGlobalAuthentication> enableGlobalAuthenticationMergedAnnotation = |
|
|
|
|
mergedAnnotations.get(EnableGlobalAuthentication.class); |
|
|
|
|
assertThat(enableGlobalAuthenticationMergedAnnotation.isSynthesizable()).isFalse(); |
|
|
|
|
EnableGlobalAuthentication enableGlobalAuthentication = enableGlobalAuthenticationMergedAnnotation.synthesize(); |
|
|
|
|
assertThat(enableGlobalAuthentication).isNotInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertNotSynthesized(enableGlobalAuthentication); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -1603,8 +1605,8 @@ class MergedAnnotationsTests {
@@ -1603,8 +1605,8 @@ class MergedAnnotationsTests {
|
|
|
|
|
RequestMapping synthesizedWebMapping1 = mergedAnnotation1.synthesize(); |
|
|
|
|
RequestMapping synthesizedWebMapping2 = MergedAnnotation.from(webMapping).synthesize(); |
|
|
|
|
|
|
|
|
|
assertThat(synthesizedWebMapping1).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertThat(synthesizedWebMapping2).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesizedWebMapping1); |
|
|
|
|
assertSynthesized(synthesizedWebMapping2); |
|
|
|
|
assertThat(synthesizedWebMapping1).isEqualTo(synthesizedWebMapping2); |
|
|
|
|
|
|
|
|
|
// Synthesizing an annotation from a different MergedAnnotation results in a different synthesized annotation instance.
|
|
|
|
|
@ -1726,15 +1728,13 @@ class MergedAnnotationsTests {
@@ -1726,15 +1728,13 @@ class MergedAnnotationsTests {
|
|
|
|
|
testSynthesisWithImplicitAliases(GroovyImplicitAliasesSimpleTestConfigurationClass.class, "groovyScript"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void testSynthesisWithImplicitAliases(Class<?> clazz, String expected) |
|
|
|
|
throws Exception { |
|
|
|
|
ImplicitAliasesTestConfiguration config = clazz.getAnnotation( |
|
|
|
|
ImplicitAliasesTestConfiguration.class); |
|
|
|
|
private void testSynthesisWithImplicitAliases(Class<?> clazz, String expected) throws Exception { |
|
|
|
|
ImplicitAliasesTestConfiguration config = clazz.getAnnotation(ImplicitAliasesTestConfiguration.class); |
|
|
|
|
assertThat(config).isNotNull(); |
|
|
|
|
MergedAnnotation<ImplicitAliasesTestConfiguration> mergedAnnotation = MergedAnnotation.from(config); |
|
|
|
|
assertThat(mergedAnnotation.isSynthesizable()).isTrue(); |
|
|
|
|
ImplicitAliasesTestConfiguration synthesized = mergedAnnotation.synthesize(); |
|
|
|
|
assertThat(synthesized).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesized); |
|
|
|
|
assertThat(synthesized.value()).isEqualTo(expected); |
|
|
|
|
assertThat(synthesized.location1()).isEqualTo(expected); |
|
|
|
|
assertThat(synthesized.xmlFile()).isEqualTo(expected); |
|
|
|
|
@ -1765,7 +1765,7 @@ class MergedAnnotationsTests {
@@ -1765,7 +1765,7 @@ class MergedAnnotationsTests {
|
|
|
|
|
assertThat(mergedAnnotation.isSynthesizable()).isTrue(); |
|
|
|
|
ImplicitAliasesWithImpliedAliasNamesOmittedTestConfiguration synthesized = |
|
|
|
|
mergedAnnotation.synthesize(); |
|
|
|
|
assertThat(synthesized).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesized); |
|
|
|
|
assertThat(synthesized.value()).isEqualTo(expected); |
|
|
|
|
assertThat(synthesized.location()).isEqualTo(expected); |
|
|
|
|
assertThat(synthesized.xmlFile()).isEqualTo(expected); |
|
|
|
|
@ -1777,7 +1777,7 @@ class MergedAnnotationsTests {
@@ -1777,7 +1777,7 @@ class MergedAnnotationsTests {
|
|
|
|
|
ImplicitAliasesForAliasPairTestConfigurationClass.class.getAnnotation( |
|
|
|
|
ImplicitAliasesForAliasPairTestConfiguration.class); |
|
|
|
|
ImplicitAliasesForAliasPairTestConfiguration synthesized = MergedAnnotation.from(config).synthesize(); |
|
|
|
|
assertThat(synthesized).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesized); |
|
|
|
|
assertThat(synthesized.xmlFile()).isEqualTo("test.xml"); |
|
|
|
|
assertThat(synthesized.groovyScript()).isEqualTo("test.xml"); |
|
|
|
|
} |
|
|
|
|
@ -1788,7 +1788,7 @@ class MergedAnnotationsTests {
@@ -1788,7 +1788,7 @@ class MergedAnnotationsTests {
|
|
|
|
|
TransitiveImplicitAliasesTestConfigurationClass.class.getAnnotation( |
|
|
|
|
TransitiveImplicitAliasesTestConfiguration.class); |
|
|
|
|
TransitiveImplicitAliasesTestConfiguration synthesized = MergedAnnotation.from(config).synthesize(); |
|
|
|
|
assertThat(synthesized).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesized); |
|
|
|
|
assertThat(synthesized.xml()).isEqualTo("test.xml"); |
|
|
|
|
assertThat(synthesized.groovy()).isEqualTo("test.xml"); |
|
|
|
|
} |
|
|
|
|
@ -1800,7 +1800,7 @@ class MergedAnnotationsTests {
@@ -1800,7 +1800,7 @@ class MergedAnnotationsTests {
|
|
|
|
|
TransitiveImplicitAliasesForAliasPairTestConfiguration.class); |
|
|
|
|
TransitiveImplicitAliasesForAliasPairTestConfiguration synthesized = MergedAnnotation.from( |
|
|
|
|
config).synthesize(); |
|
|
|
|
assertThat(synthesized).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesized); |
|
|
|
|
assertThat(synthesized.xml()).isEqualTo("test.xml"); |
|
|
|
|
assertThat(synthesized.groovy()).isEqualTo("test.xml"); |
|
|
|
|
} |
|
|
|
|
@ -1859,7 +1859,7 @@ class MergedAnnotationsTests {
@@ -1859,7 +1859,7 @@ class MergedAnnotationsTests {
|
|
|
|
|
Map<String, Object> map = Collections.singletonMap("value", "webController"); |
|
|
|
|
MergedAnnotation<Component> annotation = MergedAnnotation.of(Component.class, map); |
|
|
|
|
Component synthesizedComponent = annotation.synthesize(); |
|
|
|
|
assertThat(synthesizedComponent).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesizedComponent); |
|
|
|
|
assertThat(synthesizedComponent.value()).isEqualTo("webController"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1880,7 +1880,7 @@ class MergedAnnotationsTests {
@@ -1880,7 +1880,7 @@ class MergedAnnotationsTests {
|
|
|
|
|
MergedAnnotation<ComponentScanSingleFilter> annotation = MergedAnnotation.of( |
|
|
|
|
ComponentScanSingleFilter.class, map); |
|
|
|
|
ComponentScanSingleFilter synthesizedComponentScan = annotation.synthesize(); |
|
|
|
|
assertThat(synthesizedComponentScan).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesizedComponentScan); |
|
|
|
|
assertThat(synthesizedComponentScan.value().pattern()).isEqualTo("newFoo"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1904,7 +1904,7 @@ class MergedAnnotationsTests {
@@ -1904,7 +1904,7 @@ class MergedAnnotationsTests {
|
|
|
|
|
MergedAnnotation<ComponentScan> annotation = MergedAnnotation.of( |
|
|
|
|
ComponentScan.class, map); |
|
|
|
|
ComponentScan synthesizedComponentScan = annotation.synthesize(); |
|
|
|
|
assertThat(synthesizedComponentScan).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesizedComponentScan); |
|
|
|
|
assertThat(Arrays.stream(synthesizedComponentScan.excludeFilters()).map( |
|
|
|
|
Filter::pattern)).containsExactly("newFoo", "newBar"); |
|
|
|
|
} |
|
|
|
|
@ -2023,7 +2023,7 @@ class MergedAnnotationsTests {
@@ -2023,7 +2023,7 @@ class MergedAnnotationsTests {
|
|
|
|
|
assertThat(component).isNotNull(); |
|
|
|
|
Map<String, Object> attributes = MergedAnnotation.from(component).asMap(); |
|
|
|
|
Component synthesized = MergedAnnotation.of(Component.class, attributes).synthesize(); |
|
|
|
|
assertThat(synthesized).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesized); |
|
|
|
|
assertThat(synthesized).isEqualTo(component); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -2182,7 +2182,7 @@ class MergedAnnotationsTests {
@@ -2182,7 +2182,7 @@ class MergedAnnotationsTests {
|
|
|
|
|
assertThat(annotation).isNotNull(); |
|
|
|
|
MergedAnnotation<Annotation> mergedAnnotation = MergedAnnotation.from(annotation); |
|
|
|
|
Annotation synthesizedAnnotation = mergedAnnotation.synthesize(); |
|
|
|
|
assertThat(synthesizedAnnotation).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesizedAnnotation); |
|
|
|
|
assertThat(mergedAnnotation.getString("name")).isEqualTo("test"); |
|
|
|
|
assertThat(mergedAnnotation.getString("path")).isEqualTo("/test"); |
|
|
|
|
assertThat(mergedAnnotation.getString("value")).isEqualTo("/test"); |
|
|
|
|
@ -2193,10 +2193,10 @@ class MergedAnnotationsTests {
@@ -2193,10 +2193,10 @@ class MergedAnnotationsTests {
|
|
|
|
|
Hierarchy hierarchy = HierarchyClass.class.getAnnotation(Hierarchy.class); |
|
|
|
|
assertThat(hierarchy).isNotNull(); |
|
|
|
|
Hierarchy synthesizedHierarchy = MergedAnnotation.from(hierarchy).synthesize(); |
|
|
|
|
assertThat(synthesizedHierarchy).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesizedHierarchy); |
|
|
|
|
TestConfiguration[] configs = synthesizedHierarchy.value(); |
|
|
|
|
assertThat(configs).isNotNull(); |
|
|
|
|
assertThat(configs).allMatch(SynthesizedAnnotation.class::isInstance); |
|
|
|
|
assertThat(configs).allMatch(AnnotationUtils::isSynthesizedAnnotation); |
|
|
|
|
assertThat(configs).extracting(TestConfiguration::value).containsExactly("A", "B"); |
|
|
|
|
assertThat(configs).extracting(TestConfiguration::location).containsExactly("A", "B"); |
|
|
|
|
|
|
|
|
|
@ -2217,7 +2217,7 @@ class MergedAnnotationsTests {
@@ -2217,7 +2217,7 @@ class MergedAnnotationsTests {
|
|
|
|
|
assertThat(charsContainer).isNotNull(); |
|
|
|
|
CharsContainer synthesizedCharsContainer = MergedAnnotation.from( |
|
|
|
|
charsContainer).synthesize(); |
|
|
|
|
assertThat(synthesizedCharsContainer).isInstanceOf(SynthesizedAnnotation.class); |
|
|
|
|
assertSynthesized(synthesizedCharsContainer); |
|
|
|
|
char[] chars = synthesizedCharsContainer.chars(); |
|
|
|
|
assertThat(chars).containsExactly('x', 'y', 'z'); |
|
|
|
|
// Alter array returned from synthesized annotation
|
|
|
|
|
@ -3831,4 +3831,12 @@ class MergedAnnotationsTests {
@@ -3831,4 +3831,12 @@ class MergedAnnotationsTests {
|
|
|
|
|
} |
|
|
|
|
// @formatter:on
|
|
|
|
|
|
|
|
|
|
static void assertSynthesized(Annotation annotation) { |
|
|
|
|
assertThat(AnnotationUtils.isSynthesizedAnnotation(annotation)).as("synthesized annotation").isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void assertNotSynthesized(Annotation annotation) { |
|
|
|
|
assertThat(AnnotationUtils.isSynthesizedAnnotation(annotation)).as("synthesized annotation").isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|