Polish MergedAnnotation tests
This commit is contained in:
parent
125e2902be
commit
952223dcf9
|
|
@ -197,7 +197,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");
|
||||
|
|
@ -353,7 +353,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");
|
||||
|
|
|
|||
|
|
@ -679,12 +679,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);
|
||||
}
|
||||
|
|
@ -1384,7 +1381,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);
|
||||
|
|
@ -1395,7 +1392,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,
|
||||
|
|
@ -1409,7 +1406,7 @@ class MergedAnnotationsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void getRepeatableDeclaredOnClass() {
|
||||
void streamRepeatableDeclaredOnClass() {
|
||||
Class<?> element = MyRepeatableClass.class;
|
||||
String[] expectedValuesJava = { "A", "B", "C" };
|
||||
String[] expectedValuesSpring = { "A", "B", "C", "meta1" };
|
||||
|
|
@ -1417,7 +1414,7 @@ class MergedAnnotationsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void getRepeatableDeclaredOnSuperclass() {
|
||||
void streamRepeatableDeclaredOnSuperclass() {
|
||||
Class<?> element = SubMyRepeatableClass.class;
|
||||
String[] expectedValuesJava = { "A", "B", "C" };
|
||||
String[] expectedValuesSpring = { "A", "B", "C", "meta1" };
|
||||
|
|
@ -1425,7 +1422,7 @@ class MergedAnnotationsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void getRepeatableDeclaredOnClassAndSuperclass() {
|
||||
void streamRepeatableDeclaredOnClassAndSuperclass() {
|
||||
Class<?> element = SubMyRepeatableWithAdditionalLocalDeclarationsClass.class;
|
||||
String[] expectedValuesJava = { "X", "Y", "Z" };
|
||||
String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" };
|
||||
|
|
@ -1433,7 +1430,7 @@ class MergedAnnotationsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void getRepeatableDeclaredOnMultipleSuperclasses() {
|
||||
void streamRepeatableDeclaredOnMultipleSuperclasses() {
|
||||
Class<?> element = SubSubMyRepeatableWithAdditionalLocalDeclarationsClass.class;
|
||||
String[] expectedValuesJava = { "X", "Y", "Z" };
|
||||
String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" };
|
||||
|
|
@ -1441,7 +1438,7 @@ class MergedAnnotationsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void getDirectRepeatablesDeclaredOnClass() {
|
||||
void streamDirectRepeatablesDeclaredOnClass() {
|
||||
Class<?> element = MyRepeatableClass.class;
|
||||
String[] expectedValuesJava = { "A", "B", "C" };
|
||||
String[] expectedValuesSpring = { "A", "B", "C", "meta1" };
|
||||
|
|
@ -1449,7 +1446,7 @@ class MergedAnnotationsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void getDirectRepeatablesDeclaredOnSuperclass() {
|
||||
void streamDirectRepeatablesDeclaredOnSuperclass() {
|
||||
Class<?> element = SubMyRepeatableClass.class;
|
||||
String[] expectedValuesJava = {};
|
||||
String[] expectedValuesSpring = {};
|
||||
|
|
@ -1476,20 +1473,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
|
||||
|
|
|
|||
Loading…
Reference in New Issue