diff --git a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java index efc6d139a90..5e66aa58f4c 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -20,7 +20,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; import java.lang.reflect.Executable; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.lang.reflect.Parameter; import java.util.Arrays; import java.util.List; @@ -118,9 +117,7 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes List.of(BeforeAll.class, AfterAll.class, BeforeEach.class, AfterEach.class, Testable.class); private static final MethodFilter autowiredTestOrLifecycleMethodFilter = - ReflectionUtils.USER_DECLARED_METHODS - .and(method -> !Modifier.isPrivate(method.getModifiers())) - .and(SpringExtension::isAutowiredTestOrLifecycleMethod); + ReflectionUtils.USER_DECLARED_METHODS.and(SpringExtension::isAutowiredTestOrLifecycleMethod); /** diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/AutowiredConfigurationErrorsIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/AutowiredConfigurationErrorsIntegrationTests.java index 919e0b841b3..11fa6eb0fa4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/AutowiredConfigurationErrorsIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/AutowiredConfigurationErrorsIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -65,9 +65,11 @@ class AutowiredConfigurationErrorsIntegrationTests { @ParameterizedTest @ValueSource(classes = { StaticAutowiredBeforeAllMethod.class, + StaticAutowiredPrivateBeforeAllMethod.class, StaticAutowiredAfterAllMethod.class, AutowiredBeforeEachMethod.class, AutowiredAfterEachMethod.class, + AutowiredPrivateAfterEachMethod.class, AutowiredTestMethod.class, AutowiredRepeatedTestMethod.class, AutowiredParameterizedTestMethod.class @@ -166,6 +168,21 @@ class AutowiredConfigurationErrorsIntegrationTests { } } + @SpringJUnitConfig(Config.class) + @FailingTestCase + static class StaticAutowiredPrivateBeforeAllMethod { + + @Autowired + @BeforeAll + private static void beforeAll(TestInfo testInfo) { + } + + @Test + @DisplayName(DISPLAY_NAME) + void test() { + } + } + @SpringJUnitConfig(Config.class) @TestInstance(PER_CLASS) @FailingTestCase @@ -243,6 +260,22 @@ class AutowiredConfigurationErrorsIntegrationTests { } } + @SpringJUnitConfig(Config.class) + @FailingTestCase + static class AutowiredPrivateAfterEachMethod { + + @Test + @DisplayName(DISPLAY_NAME) + void test() { + } + + @Autowired + @AfterEach + private void afterEach(TestInfo testInfo) { + } + } + + @SpringJUnitConfig(Config.class) @FailingTestCase static class AutowiredTestMethod { diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml index f13676e5139..06360a35221 100644 --- a/src/checkstyle/checkstyle-suppressions.xml +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -107,7 +107,7 @@ - +