Skip to content

Commit

Permalink
Merge branch '2.6.x' into 2.7.x
Browse files Browse the repository at this point in the history
Closes gh-30787
  • Loading branch information
wilkinsona committed Apr 25, 2022
2 parents e8b7843 + 5c3be7c commit d0c9d5a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
Expand Down Expand Up @@ -40,7 +40,8 @@ public interface MethodValidationExcludeFilter {

/**
* Factory method to create a {@link MethodValidationExcludeFilter} that excludes
* classes by annotation.
* classes by annotation found using an {@link SearchStrategy#INHERITED_ANNOTATIONS
* inherited annotations search strategy}.
* @param annotationType the annotation to check
* @return a {@link MethodValidationExcludeFilter} instance
*/
Expand All @@ -50,14 +51,14 @@ static MethodValidationExcludeFilter byAnnotation(Class<? extends Annotation> an

/**
* Factory method to create a {@link MethodValidationExcludeFilter} that excludes
* classes by annotation.
* classes by annotation found using the given search strategy.
* @param annotationType the annotation to check
* @param searchStrategy the annotation search strategy
* @return a {@link MethodValidationExcludeFilter} instance
*/
static MethodValidationExcludeFilter byAnnotation(Class<? extends Annotation> annotationType,
SearchStrategy searchStrategy) {
return (type) -> MergedAnnotations.from(type, SearchStrategy.SUPERCLASS).isPresent(annotationType);
return (type) -> MergedAnnotations.from(type, searchStrategy).isPresent(annotationType);
}

}
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
Expand All @@ -16,11 +16,14 @@

package org.springframework.boot.validation.beanvalidation;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import org.junit.jupiter.api.Test;

import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;

import static org.assertj.core.api.Assertions.assertThat;

/**
Expand All @@ -42,6 +45,19 @@ void byAnnotationWhenClassIsNotAnnotatedIncludes() {
assertThat(filter.isExcluded(Plain.class)).isFalse();
}

@Test
void byAnnotationWhenSuperclassIsAnnotatedWithInheritedAnnotationExcludes() {
MethodValidationExcludeFilter filter = MethodValidationExcludeFilter.byAnnotation(Indicator.class);
assertThat(filter.isExcluded(AnnotatedSuperClass.class)).isTrue();
}

@Test
void byAnnotationWithDirectSearchStrategyWhenSuperclassIsAnnotatedWithInheritedAnnotationIncludes() {
MethodValidationExcludeFilter filter = MethodValidationExcludeFilter.byAnnotation(Indicator.class,
SearchStrategy.DIRECT);
assertThat(filter.isExcluded(AnnotatedSuperClass.class)).isFalse();
}

static class Plain {

}
Expand All @@ -51,9 +67,14 @@ static class Annotated {

}

@Inherited
@Retention(RetentionPolicy.RUNTIME)
@interface Indicator {

}

static class AnnotatedSuperClass extends Annotated {

}

}

0 comments on commit d0c9d5a

Please sign in to comment.