Improve tests for synthesized array of annotations

This commit is contained in:
Sam Brannen 2020-04-22 15:17:33 +02:00
parent 5721c747b2
commit a9cc7b3edc
1 changed files with 6 additions and 22 deletions

View File

@ -1956,7 +1956,7 @@ class MergedAnnotationsTests {
} }
@Test @Test
void synthesizeWithAttributeAliasesInNestedAnnotations() throws Exception { void synthesizeWithArrayOfAnnotations() throws Exception {
Hierarchy hierarchy = HierarchyClass.class.getAnnotation(Hierarchy.class); Hierarchy hierarchy = HierarchyClass.class.getAnnotation(Hierarchy.class);
assertThat(hierarchy).isNotNull(); assertThat(hierarchy).isNotNull();
Hierarchy synthesizedHierarchy = MergedAnnotation.from(hierarchy).synthesize(); Hierarchy synthesizedHierarchy = MergedAnnotation.from(hierarchy).synthesize();
@ -1964,33 +1964,17 @@ class MergedAnnotationsTests {
TestConfiguration[] configs = synthesizedHierarchy.value(); TestConfiguration[] configs = synthesizedHierarchy.value();
assertThat(configs).isNotNull(); assertThat(configs).isNotNull();
assertThat(configs).allMatch(SynthesizedAnnotation.class::isInstance); assertThat(configs).allMatch(SynthesizedAnnotation.class::isInstance);
assertThat( assertThat(configs).extracting(TestConfiguration::value).containsExactly("A", "B");
Arrays.stream(configs).map(TestConfiguration::location)).containsExactly( assertThat(configs).extracting(TestConfiguration::location).containsExactly("A", "B");
"A", "B");
assertThat(Arrays.stream(configs).map(TestConfiguration::value)).containsExactly(
"A", "B");
}
@Test TestConfiguration contextConfig = TestConfigurationClass.class.getAnnotation(TestConfiguration.class);
void synthesizeWithArrayOfAnnotations() throws Exception {
Hierarchy hierarchy = HierarchyClass.class.getAnnotation(Hierarchy.class);
assertThat(hierarchy).isNotNull();
Hierarchy synthesizedHierarchy = MergedAnnotation.from(hierarchy).synthesize();
assertThat(synthesizedHierarchy).isInstanceOf(SynthesizedAnnotation.class);
TestConfiguration contextConfig = TestConfigurationClass.class.getAnnotation(
TestConfiguration.class);
assertThat(contextConfig).isNotNull(); assertThat(contextConfig).isNotNull();
TestConfiguration[] configs = synthesizedHierarchy.value();
assertThat(
Arrays.stream(configs).map(TestConfiguration::location)).containsExactly(
"A", "B");
// Alter array returned from synthesized annotation // Alter array returned from synthesized annotation
configs[0] = contextConfig; configs[0] = contextConfig;
assertThat(configs).extracting(TestConfiguration::value).containsExactly("simple.xml", "B");
// Re-retrieve the array from the synthesized annotation // Re-retrieve the array from the synthesized annotation
configs = synthesizedHierarchy.value(); configs = synthesizedHierarchy.value();
assertThat( assertThat(configs).extracting(TestConfiguration::value).containsExactly("A", "B");
Arrays.stream(configs).map(TestConfiguration::location)).containsExactly(
"A", "B");
} }
@Test @Test