Merge branch '5.2.x'
This commit is contained in:
@@ -25,6 +25,7 @@ import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Provides access to a collection of merged annotations, usually obtained
|
||||
@@ -345,6 +346,8 @@ public interface MergedAnnotations extends Iterable<MergedAnnotation<Annotation>
|
||||
static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStrategy,
|
||||
RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter) {
|
||||
|
||||
Assert.notNull(repeatableContainers, "RepeatableContainers must not be null");
|
||||
Assert.notNull(annotationFilter, "AnnotationFilter must not be null");
|
||||
return TypeMappedAnnotations.from(element, searchStrategy, repeatableContainers, annotationFilter);
|
||||
}
|
||||
|
||||
@@ -405,6 +408,8 @@ public interface MergedAnnotations extends Iterable<MergedAnnotation<Annotation>
|
||||
static MergedAnnotations from(Object source, Annotation[] annotations,
|
||||
RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter) {
|
||||
|
||||
Assert.notNull(repeatableContainers, "RepeatableContainers must not be null");
|
||||
Assert.notNull(annotationFilter, "AnnotationFilter must not be null");
|
||||
return TypeMappedAnnotations.from(source, annotations, repeatableContainers, annotationFilter);
|
||||
}
|
||||
|
||||
@@ -414,10 +419,9 @@ public interface MergedAnnotations extends Iterable<MergedAnnotation<Annotation>
|
||||
* {@link MergedAnnotations} instance to be created from annotations that
|
||||
* are not necessarily loaded using reflection. The provided annotations
|
||||
* must all be {@link MergedAnnotation#isDirectlyPresent() directly present}
|
||||
* and must have a {@link MergedAnnotation#getAggregateIndex() aggregate
|
||||
* and must have an {@link MergedAnnotation#getAggregateIndex() aggregate
|
||||
* index} of {@code 0}.
|
||||
* <p>
|
||||
* The resulting {@link MergedAnnotations} instance will contain both the
|
||||
* <p>The resulting {@link MergedAnnotations} instance will contain both the
|
||||
* specified annotations, and any meta-annotations that can be read using
|
||||
* reflection.
|
||||
* @param annotations the annotations to include
|
||||
|
||||
@@ -53,6 +53,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
@@ -73,6 +74,26 @@ import static org.assertj.core.api.Assertions.entry;
|
||||
*/
|
||||
class MergedAnnotationsTests {
|
||||
|
||||
@Test
|
||||
void fromPreconditions() {
|
||||
SearchStrategy strategy = SearchStrategy.DIRECT;
|
||||
RepeatableContainers containers = RepeatableContainers.standardRepeatables();
|
||||
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> MergedAnnotations.from(getClass(), strategy, null, AnnotationFilter.PLAIN))
|
||||
.withMessage("RepeatableContainers must not be null");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> MergedAnnotations.from(getClass(), strategy, containers, null))
|
||||
.withMessage("AnnotationFilter must not be null");
|
||||
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> MergedAnnotations.from(getClass(), new Annotation[0], null, AnnotationFilter.PLAIN))
|
||||
.withMessage("RepeatableContainers must not be null");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> MergedAnnotations.from(getClass(), new Annotation[0], containers, null))
|
||||
.withMessage("AnnotationFilter must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void streamWhenFromNonAnnotatedClass() {
|
||||
assertThat(MergedAnnotations.from(NonAnnotatedClass.class).
|
||||
|
||||
Reference in New Issue
Block a user