Polish MergedAnnotation tests
(cherry picked from commit952223dcf9) (cherry picked from commit20dd585c93)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -194,7 +194,7 @@ class AnnotationsScannerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void typeHierarchyStrategyOnClassWhenHasInterfaceDoesNotIncludeInterfaces() {
|
||||
void typeHierarchyStrategyOnClassWhenHasSingleInterfaceScansInterfaces() {
|
||||
Class<?> source = WithSingleInterface.class;
|
||||
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
|
||||
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2");
|
||||
@@ -350,7 +350,7 @@ class AnnotationsScannerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void typeHierarchyStrategyOnMethodWhenHasInterfaceDoesNotIncludeInterfaces() {
|
||||
void typeHierarchyStrategyOnMethodWhenHasInterfaceScansInterfaces() {
|
||||
Method source = methodFrom(WithSingleInterface.class);
|
||||
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
|
||||
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -549,12 +549,9 @@ class MergedAnnotationsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithTypeHierarchyInheritedFromInterfaceMethod()
|
||||
throws NoSuchMethodException {
|
||||
Method method = ConcreteClassWithInheritedAnnotation.class.getMethod(
|
||||
"handleFromInterface");
|
||||
MergedAnnotation<?> annotation = MergedAnnotations.from(method,
|
||||
SearchStrategy.TYPE_HIERARCHY).get(Order.class);
|
||||
void getWithTypeHierarchyInheritedFromInterfaceMethod() throws Exception {
|
||||
Method method = ConcreteClassWithInheritedAnnotation.class.getMethod("handleFromInterface");
|
||||
MergedAnnotation<?> annotation = MergedAnnotations.from(method,SearchStrategy.TYPE_HIERARCHY).get(Order.class);
|
||||
assertThat(annotation.isPresent()).isTrue();
|
||||
assertThat(annotation.getAggregateIndex()).isEqualTo(1);
|
||||
}
|
||||
@@ -1268,7 +1265,7 @@ class MergedAnnotationsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRepeatableDeclaredOnMethod() throws Exception {
|
||||
void streamRepeatableDeclaredOnMethod() throws Exception {
|
||||
Method method = InterfaceWithRepeated.class.getMethod("foo");
|
||||
Stream<MergedAnnotation<MyRepeatable>> annotations = MergedAnnotations.from(
|
||||
method, SearchStrategy.TYPE_HIERARCHY).stream(MyRepeatable.class);
|
||||
@@ -1279,7 +1276,7 @@ class MergedAnnotationsTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void getRepeatableDeclaredOnClassWithAttributeAliases() {
|
||||
void streamRepeatableDeclaredOnClassWithAttributeAliases() {
|
||||
assertThat(MergedAnnotations.from(HierarchyClass.class).stream(
|
||||
TestConfiguration.class)).isEmpty();
|
||||
RepeatableContainers containers = RepeatableContainers.of(TestConfiguration.class,
|
||||
@@ -1293,7 +1290,7 @@ class MergedAnnotationsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRepeatableDeclaredOnClass() {
|
||||
void streamRepeatableDeclaredOnClass() {
|
||||
Class<?> element = MyRepeatableClass.class;
|
||||
String[] expectedValuesJava = { "A", "B", "C" };
|
||||
String[] expectedValuesSpring = { "A", "B", "C", "meta1" };
|
||||
@@ -1301,7 +1298,7 @@ class MergedAnnotationsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRepeatableDeclaredOnSuperclass() {
|
||||
void streamRepeatableDeclaredOnSuperclass() {
|
||||
Class<?> element = SubMyRepeatableClass.class;
|
||||
String[] expectedValuesJava = { "A", "B", "C" };
|
||||
String[] expectedValuesSpring = { "A", "B", "C", "meta1" };
|
||||
@@ -1309,7 +1306,7 @@ class MergedAnnotationsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRepeatableDeclaredOnClassAndSuperclass() {
|
||||
void streamRepeatableDeclaredOnClassAndSuperclass() {
|
||||
Class<?> element = SubMyRepeatableWithAdditionalLocalDeclarationsClass.class;
|
||||
String[] expectedValuesJava = { "X", "Y", "Z" };
|
||||
String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" };
|
||||
@@ -1317,7 +1314,7 @@ class MergedAnnotationsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRepeatableDeclaredOnMultipleSuperclasses() {
|
||||
void streamRepeatableDeclaredOnMultipleSuperclasses() {
|
||||
Class<?> element = SubSubMyRepeatableWithAdditionalLocalDeclarationsClass.class;
|
||||
String[] expectedValuesJava = { "X", "Y", "Z" };
|
||||
String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" };
|
||||
@@ -1325,7 +1322,7 @@ class MergedAnnotationsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDirectRepeatablesDeclaredOnClass() {
|
||||
void streamDirectRepeatablesDeclaredOnClass() {
|
||||
Class<?> element = MyRepeatableClass.class;
|
||||
String[] expectedValuesJava = { "A", "B", "C" };
|
||||
String[] expectedValuesSpring = { "A", "B", "C", "meta1" };
|
||||
@@ -1333,7 +1330,7 @@ class MergedAnnotationsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDirectRepeatablesDeclaredOnSuperclass() {
|
||||
void streamDirectRepeatablesDeclaredOnSuperclass() {
|
||||
Class<?> element = SubMyRepeatableClass.class;
|
||||
String[] expectedValuesJava = {};
|
||||
String[] expectedValuesSpring = {};
|
||||
@@ -1360,20 +1357,17 @@ class MergedAnnotationsTests {
|
||||
MergedAnnotations annotations = MergedAnnotations.from(element, searchStrategy,
|
||||
RepeatableContainers.of(MyRepeatable.class, MyRepeatableContainer.class),
|
||||
AnnotationFilter.PLAIN);
|
||||
assertThat(annotations.stream(MyRepeatable.class).filter(
|
||||
MergedAnnotationPredicates.firstRunOf(
|
||||
MergedAnnotation::getAggregateIndex)).map(
|
||||
annotation -> annotation.getString(
|
||||
"value"))).containsExactly(expected);
|
||||
Stream<String> values = annotations.stream(MyRepeatable.class)
|
||||
.filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex))
|
||||
.map(annotation -> annotation.getString("value"));
|
||||
assertThat(values).containsExactly(expected);
|
||||
}
|
||||
|
||||
private void testStandardRepeatables(SearchStrategy searchStrategy, Class<?> element, String[] expected) {
|
||||
MergedAnnotations annotations = MergedAnnotations.from(element, searchStrategy);
|
||||
assertThat(annotations.stream(MyRepeatable.class).filter(
|
||||
MergedAnnotationPredicates.firstRunOf(
|
||||
MergedAnnotation::getAggregateIndex)).map(
|
||||
annotation -> annotation.getString(
|
||||
"value"))).containsExactly(expected);
|
||||
Stream<String> values = MergedAnnotations.from(element, searchStrategy).stream(MyRepeatable.class)
|
||||
.filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex))
|
||||
.map(annotation -> annotation.getString("value"));
|
||||
assertThat(values).containsExactly(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user