|
36 | 36 | import java.lang.annotation.Target;
|
37 | 37 | import java.lang.reflect.AnnotatedElement;
|
38 | 38 | import java.lang.reflect.Field;
|
| 39 | +import java.lang.reflect.Method; |
39 | 40 | import java.math.BigDecimal;
|
40 | 41 | import java.util.List;
|
41 | 42 | import java.util.Optional;
|
42 | 43 | import java.util.function.Predicate;
|
43 | 44 |
|
| 45 | +import org.junit.jupiter.api.BeforeAll; |
| 46 | +import org.junit.jupiter.api.BeforeEach; |
44 | 47 | import org.junit.jupiter.api.Test;
|
45 | 48 | import org.junit.platform.commons.PreconditionViolationException;
|
| 49 | +import org.junit.platform.commons.util.pkg1.SuperclassWithStaticPackagePrivateBeforeMethod; |
| 50 | +import org.junit.platform.commons.util.pkg1.subpkg.SubclassWithNonStaticPackagePrivateBeforeMethod; |
46 | 51 |
|
47 | 52 | /**
|
48 | 53 | * Unit tests for {@link AnnotationUtils}.
|
@@ -380,6 +385,28 @@ void findAnnotatedMethodsForAnnotationUsedInClassAndSuperclassHierarchyDown() th
|
380 | 385 | assertThat(methods.subList(1, 3)).containsOnly(method1, method3);
|
381 | 386 | }
|
382 | 387 |
|
| 388 | + /** |
| 389 | + * @see https://github.com/junit-team/junit5/issues/3498 |
| 390 | + */ |
| 391 | + @Test |
| 392 | + void findAnnotatedMethodsAppliesPredicateBeforeSearchingTypeHierarchy() throws Exception { |
| 393 | + final String BEFORE = "before"; |
| 394 | + Class<?> superclass = SuperclassWithStaticPackagePrivateBeforeMethod.class; |
| 395 | + Method beforeAllMethod = superclass.getDeclaredMethod(BEFORE); |
| 396 | + Class<?> subclass = SubclassWithNonStaticPackagePrivateBeforeMethod.class; |
| 397 | + Method beforeEachMethod = subclass.getDeclaredMethod(BEFORE); |
| 398 | + |
| 399 | + // Prerequisite |
| 400 | + var methods = findAnnotatedMethods(superclass, BeforeAll.class, TOP_DOWN); |
| 401 | + assertThat(methods).containsExactly(beforeAllMethod); |
| 402 | + |
| 403 | + // Actual use cases for this test |
| 404 | + methods = findAnnotatedMethods(subclass, BeforeAll.class, TOP_DOWN); |
| 405 | + assertThat(methods).containsExactly(beforeAllMethod); |
| 406 | + methods = findAnnotatedMethods(subclass, BeforeEach.class, TOP_DOWN); |
| 407 | + assertThat(methods).containsExactly(beforeEachMethod); |
| 408 | + } |
| 409 | + |
383 | 410 | @Test
|
384 | 411 | void findAnnotatedMethodsForAnnotationUsedInInterface() throws Exception {
|
385 | 412 | var interfaceMethod = InterfaceWithAnnotatedDefaultMethod.class.getDeclaredMethod("interfaceMethod");
|
|
0 commit comments