Skip to content

Commit eb0cf99

Browse files
committed
moved HandlerCallCounter to an internal class and removed getters
1 parent 863a4d2 commit eb0cf99

File tree

2 files changed

+60
-85
lines changed

2 files changed

+60
-85
lines changed

junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/HandlerCallCounter.java

Lines changed: 0 additions & 61 deletions
This file was deleted.

junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/LifecycleMethodExecutionExceptionHandlerTests.java

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ void classLevelExceptionHandlersRethrowException() {
8282
LauncherDiscoveryRequest request = request().selectors(selectClass(RethrowingTestCase.class)).build();
8383
EngineExecutionResults executionResults = executeTests(request);
8484

85-
assertEquals(1, RethrowExceptionHandler.callCounter.getBeforeAllCalls(),
85+
assertEquals(1, RethrowExceptionHandler.callCounter.beforeAllCalls,
8686
"Exception should handled in @BeforeAll");
87-
assertEquals(1, RethrowExceptionHandler.callCounter.getAfterAllCalls(),
87+
assertEquals(1, RethrowExceptionHandler.callCounter.afterAllCalls,
8888
"Exception should handled in @AfterAll");
8989

9090
executionResults.allEvents().assertEventsMatchExactly( //
@@ -101,9 +101,9 @@ void testLevelExceptionHandlersRethrowException() {
101101
LauncherDiscoveryRequest request = request().selectors(selectClass(RethrowingTestCase.class)).build();
102102
EngineExecutionResults executionResults = executeTests(request);
103103

104-
assertEquals(1, RethrowExceptionHandler.callCounter.getBeforeEachCalls(),
104+
assertEquals(1, RethrowExceptionHandler.callCounter.beforeEachCalls,
105105
"Exception should be handled in @BeforeEach");
106-
assertEquals(1, RethrowExceptionHandler.callCounter.getAfterEachCalls(),
106+
assertEquals(1, RethrowExceptionHandler.callCounter.afterEachCalls,
107107
"Exception should be handled in @AfterEach");
108108

109109
executionResults.allEvents().assertEventsMatchExactly( //
@@ -120,9 +120,9 @@ void classLevelExceptionHandlersConvertException() {
120120
LauncherDiscoveryRequest request = request().selectors(selectClass(ConvertingTestCase.class)).build();
121121
EngineExecutionResults executionResults = executeTests(request);
122122

123-
assertEquals(1, ConvertExceptionHandler.callCounter.getBeforeAllCalls(),
123+
assertEquals(1, ConvertExceptionHandler.callCounter.beforeAllCalls,
124124
"Exception should handled in @BeforeAll");
125-
assertEquals(1, ConvertExceptionHandler.callCounter.getAfterAllCalls(),
125+
assertEquals(1, ConvertExceptionHandler.callCounter.afterAllCalls,
126126
"Exception should handled in @AfterAll");
127127

128128
executionResults.allEvents().assertEventsMatchExactly( //
@@ -139,9 +139,9 @@ void testLevelExceptionHandlersConvertException() {
139139
LauncherDiscoveryRequest request = request().selectors(selectClass(ConvertingTestCase.class)).build();
140140
EngineExecutionResults executionResults = executeTests(request);
141141

142-
assertEquals(1, ConvertExceptionHandler.callCounter.getBeforeEachCalls(),
142+
assertEquals(1, ConvertExceptionHandler.callCounter.beforeEachCalls,
143143
"Exception should be handled in @BeforeEach");
144-
assertEquals(1, ConvertExceptionHandler.callCounter.getAfterEachCalls(),
144+
assertEquals(1, ConvertExceptionHandler.callCounter.afterEachCalls,
145145
"Exception should be handled in @AfterEach");
146146

147147
executionResults.allEvents().assertEventsMatchExactly( //
@@ -158,13 +158,13 @@ void exceptionHandlersSwallowException() {
158158
LauncherDiscoveryRequest request = request().selectors(selectClass(SwallowingTestCase.class)).build();
159159
EngineExecutionResults executionResults = executeTests(request);
160160

161-
assertEquals(1, SwallowExceptionHandler.callCounter.getBeforeAllCalls(),
161+
assertEquals(1, SwallowExceptionHandler.callCounter.beforeAllCalls,
162162
"Exception should be handled in @BeforeAll");
163-
assertEquals(1, SwallowExceptionHandler.callCounter.getBeforeEachCalls(),
163+
assertEquals(1, SwallowExceptionHandler.callCounter.beforeEachCalls,
164164
"Exception should be handled in @BeforeEach");
165-
assertEquals(1, SwallowExceptionHandler.callCounter.getAfterEachCalls(),
165+
assertEquals(1, SwallowExceptionHandler.callCounter.afterEachCalls,
166166
"Exception should be handled in @AfterEach");
167-
assertEquals(1, SwallowExceptionHandler.callCounter.getAfterAllCalls(),
167+
assertEquals(1, SwallowExceptionHandler.callCounter.afterAllCalls,
168168
"Exception should be handled in @AfterAll");
169169

170170
executionResults.allEvents().assertEventsMatchExactly( //
@@ -180,13 +180,13 @@ void exceptionHandlersSwallowException() {
180180
void perClassLifecycleMethodsAreHandled() {
181181
LauncherDiscoveryRequest request = request().selectors(selectClass(PerClassLifecycleTestCase.class)).build();
182182
EngineExecutionResults executionResults = executeTests(request);
183-
assertEquals(2, SwallowExceptionHandler.callCounter.getBeforeAllCalls(),
183+
assertEquals(2, SwallowExceptionHandler.callCounter.beforeAllCalls,
184184
"Exception should be handled in @BeforeAll");
185-
assertEquals(1, SwallowExceptionHandler.callCounter.getBeforeEachCalls(),
185+
assertEquals(1, SwallowExceptionHandler.callCounter.beforeEachCalls,
186186
"Exception should be handled in @BeforeEach");
187-
assertEquals(1, SwallowExceptionHandler.callCounter.getAfterEachCalls(),
187+
assertEquals(1, SwallowExceptionHandler.callCounter.afterEachCalls,
188188
"Exception should be handled in @AfterEach");
189-
assertEquals(2, SwallowExceptionHandler.callCounter.getAfterAllCalls(),
189+
assertEquals(2, SwallowExceptionHandler.callCounter.afterAllCalls,
190190
"Exception should be handled in @AfterAll");
191191

192192
executionResults.allEvents().assertEventsMatchExactly( //
@@ -238,9 +238,9 @@ void unrecoverableExceptionsAreNotPropagatedInBeforeAll() {
238238

239239
boolean unrecoverableExceptionThrown = executeThrowingOutOfMemoryException();
240240
assertTrue(unrecoverableExceptionThrown, "Unrecoverable Exception should be thrown");
241-
assertEquals(1, UnrecoverableExceptionHandler.callCounter.getBeforeAllCalls(),
241+
assertEquals(1, UnrecoverableExceptionHandler.callCounter.beforeAllCalls,
242242
"Exception should be handled in @BeforeAll");
243-
assertEquals(0, ShouldNotBeCalledHandler.callCounter.getBeforeAllCalls(),
243+
assertEquals(0, ShouldNotBeCalledHandler.callCounter.beforeAllCalls,
244244
"Exception should not propagate in @BeforeAll");
245245
}
246246

@@ -253,9 +253,9 @@ void unrecoverableExceptionsAreNotPropagatedInBeforeEach() {
253253

254254
boolean unrecoverableExceptionThrown = executeThrowingOutOfMemoryException();
255255
assertTrue(unrecoverableExceptionThrown, "Unrecoverable Exception should be thrown");
256-
assertEquals(1, UnrecoverableExceptionHandler.callCounter.getBeforeEachCalls(),
256+
assertEquals(1, UnrecoverableExceptionHandler.callCounter.beforeEachCalls,
257257
"Exception should be handled in @BeforeEach");
258-
assertEquals(0, ShouldNotBeCalledHandler.callCounter.getBeforeEachCalls(),
258+
assertEquals(0, ShouldNotBeCalledHandler.callCounter.beforeEachCalls,
259259
"Exception should not propagate in @BeforeEach");
260260
}
261261

@@ -268,9 +268,9 @@ void unrecoverableExceptionsAreNotPropagatedInAfterEach() {
268268

269269
boolean unrecoverableExceptionThrown = executeThrowingOutOfMemoryException();
270270
assertTrue(unrecoverableExceptionThrown, "Unrecoverable Exception should be thrown");
271-
assertEquals(1, UnrecoverableExceptionHandler.callCounter.getAfterEachCalls(),
271+
assertEquals(1, UnrecoverableExceptionHandler.callCounter.afterEachCalls,
272272
"Exception should be handled in @AfterEach");
273-
assertEquals(0, ShouldNotBeCalledHandler.callCounter.getAfterEachCalls(),
273+
assertEquals(0, ShouldNotBeCalledHandler.callCounter.afterEachCalls,
274274
"Exception should not propagate in @AfterEach");
275275
}
276276

@@ -283,9 +283,9 @@ void unrecoverableExceptionsAreNotPropagatedInAfterAll() {
283283

284284
boolean unrecoverableExceptionThrown = executeThrowingOutOfMemoryException();
285285
assertTrue(unrecoverableExceptionThrown, "Unrecoverable Exception should be thrown");
286-
assertEquals(1, UnrecoverableExceptionHandler.callCounter.getAfterAllCalls(),
286+
assertEquals(1, UnrecoverableExceptionHandler.callCounter.afterAllCalls,
287287
"Exception should be handled in @AfterAll");
288-
assertEquals(0, ShouldNotBeCalledHandler.callCounter.getAfterAllCalls(),
288+
assertEquals(0, ShouldNotBeCalledHandler.callCounter.afterAllCalls,
289289
"Exception should not propagate in @AfterAll");
290290
}
291291

@@ -561,4 +561,40 @@ public void handleAfterAllMethodExecutionException(ExtensionContext context, Thr
561561
throw throwable;
562562
}
563563
}
564+
565+
class HandlerCallCounter {
566+
private int beforeAllCalls;
567+
private int beforeEachCalls;
568+
private int afterEachCalls;
569+
private int afterAllCalls;
570+
571+
public HandlerCallCounter() {
572+
reset();
573+
}
574+
575+
public void reset() {
576+
this.beforeAllCalls = 0;
577+
this.beforeEachCalls = 0;
578+
this.afterEachCalls = 0;
579+
this.afterAllCalls = 0;
580+
}
581+
582+
public void incrementBeforeAllCalls() {
583+
beforeAllCalls++;
584+
}
585+
586+
public void incrementBeforeEachCalls() {
587+
beforeEachCalls++;
588+
}
589+
590+
public void incrementAfterEachCalls() {
591+
afterEachCalls++;
592+
}
593+
594+
public void incrementAfterAllCalls() {
595+
afterAllCalls++;
596+
}
597+
598+
599+
}
564600
}

0 commit comments

Comments
 (0)