Skip to content

Commit 9533fca

Browse files
committed
#2914: let private @BeforeAll and @afterall methods fail as well and fix formatting
1 parent ad47264 commit 9533fca

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/LifecycleMethodUtils.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ private LifecycleMethodUtils() {
3737
}
3838

3939
static List<Method> findBeforeAllMethods(Class<?> testClass, boolean requireStatic) {
40-
return findMethodsAndAssertStatic(testClass, requireStatic, BeforeAll.class, HierarchyTraversalMode.TOP_DOWN);
40+
return findMethodsAndAssertStaticAndNonPrivate(testClass, requireStatic, BeforeAll.class,
41+
HierarchyTraversalMode.TOP_DOWN);
4142
}
4243

4344
static List<Method> findAfterAllMethods(Class<?> testClass, boolean requireStatic) {
44-
return findMethodsAndAssertStatic(testClass, requireStatic, AfterAll.class, HierarchyTraversalMode.BOTTOM_UP);
45+
return findMethodsAndAssertStaticAndNonPrivate(testClass, requireStatic, AfterAll.class,
46+
HierarchyTraversalMode.BOTTOM_UP);
4547
}
4648

4749
static List<Method> findBeforeEachMethods(Class<?> testClass) {
@@ -81,12 +83,14 @@ private static void assertVoid(Class<? extends Annotation> annotationType, Metho
8183
}
8284
}
8385

84-
private static List<Method> findMethodsAndAssertStatic(Class<?> testClass, boolean requireStatic,
86+
private static List<Method> findMethodsAndAssertStaticAndNonPrivate(Class<?> testClass, boolean requireStatic,
8587
Class<? extends Annotation> annotationType, HierarchyTraversalMode traversalMode) {
8688
List<Method> methods = findMethodsAndCheckVoidReturnType(testClass, annotationType, traversalMode);
8789
if (requireStatic) {
8890
methods.forEach(method -> assertStatic(annotationType, method));
8991
}
92+
methods.forEach(method -> assertNonPrivate(annotationType, method));
93+
9094
return methods;
9195
}
9296

junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/InvalidLifecycleMethodConfigurationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static class TestCaseWithInvalidPrivateBeforeAllMethod {
116116

117117
// must not be private
118118
@BeforeAll
119-
private static void beforeAll() {
119+
private static void beforeAll() {
120120
}
121121

122122
@Test
@@ -138,8 +138,8 @@ void test() {
138138

139139
static class TestCaseWithInvalidPrivateAfterAllMethod {
140140

141-
// must not be private
142-
@AfterAll
141+
// must not be private
142+
@AfterAll
143143
private static void afterAll() {
144144
}
145145

0 commit comments

Comments
 (0)