Skip to content

Commit

Permalink
moved HandlerCallsCounter to inner class and removed getter
Browse files Browse the repository at this point in the history
  • Loading branch information
compf committed Jul 1, 2024
1 parent 863a4d2 commit 3f75c2f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 91 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ void classLevelExceptionHandlersRethrowException() {
LauncherDiscoveryRequest request = request().selectors(selectClass(RethrowingTestCase.class)).build();
EngineExecutionResults executionResults = executeTests(request);

assertEquals(1, RethrowExceptionHandler.callCounter.getBeforeAllCalls(),
"Exception should handled in @BeforeAll");
assertEquals(1, RethrowExceptionHandler.callCounter.getAfterAllCalls(),
"Exception should handled in @AfterAll");
assertEquals(1, RethrowExceptionHandler.callCounter.beforeAllCalls, "Exception should handled in @BeforeAll");
assertEquals(1, RethrowExceptionHandler.callCounter.afterAllCalls, "Exception should handled in @AfterAll");

executionResults.allEvents().assertEventsMatchExactly( //
event(engine(), started()), //
Expand All @@ -101,9 +99,9 @@ void testLevelExceptionHandlersRethrowException() {
LauncherDiscoveryRequest request = request().selectors(selectClass(RethrowingTestCase.class)).build();
EngineExecutionResults executionResults = executeTests(request);

assertEquals(1, RethrowExceptionHandler.callCounter.getBeforeEachCalls(),
assertEquals(1, RethrowExceptionHandler.callCounter.beforeEachCalls,
"Exception should be handled in @BeforeEach");
assertEquals(1, RethrowExceptionHandler.callCounter.getAfterEachCalls(),
assertEquals(1, RethrowExceptionHandler.callCounter.afterEachCalls,
"Exception should be handled in @AfterEach");

executionResults.allEvents().assertEventsMatchExactly( //
Expand All @@ -120,10 +118,8 @@ void classLevelExceptionHandlersConvertException() {
LauncherDiscoveryRequest request = request().selectors(selectClass(ConvertingTestCase.class)).build();
EngineExecutionResults executionResults = executeTests(request);

assertEquals(1, ConvertExceptionHandler.callCounter.getBeforeAllCalls(),
"Exception should handled in @BeforeAll");
assertEquals(1, ConvertExceptionHandler.callCounter.getAfterAllCalls(),
"Exception should handled in @AfterAll");
assertEquals(1, ConvertExceptionHandler.callCounter.beforeAllCalls, "Exception should handled in @BeforeAll");
assertEquals(1, ConvertExceptionHandler.callCounter.afterAllCalls, "Exception should handled in @AfterAll");

executionResults.allEvents().assertEventsMatchExactly( //
event(engine(), started()), //
Expand All @@ -139,9 +135,9 @@ void testLevelExceptionHandlersConvertException() {
LauncherDiscoveryRequest request = request().selectors(selectClass(ConvertingTestCase.class)).build();
EngineExecutionResults executionResults = executeTests(request);

assertEquals(1, ConvertExceptionHandler.callCounter.getBeforeEachCalls(),
assertEquals(1, ConvertExceptionHandler.callCounter.beforeEachCalls,
"Exception should be handled in @BeforeEach");
assertEquals(1, ConvertExceptionHandler.callCounter.getAfterEachCalls(),
assertEquals(1, ConvertExceptionHandler.callCounter.afterEachCalls,
"Exception should be handled in @AfterEach");

executionResults.allEvents().assertEventsMatchExactly( //
Expand All @@ -158,14 +154,13 @@ void exceptionHandlersSwallowException() {
LauncherDiscoveryRequest request = request().selectors(selectClass(SwallowingTestCase.class)).build();
EngineExecutionResults executionResults = executeTests(request);

assertEquals(1, SwallowExceptionHandler.callCounter.getBeforeAllCalls(),
assertEquals(1, SwallowExceptionHandler.callCounter.beforeAllCalls,
"Exception should be handled in @BeforeAll");
assertEquals(1, SwallowExceptionHandler.callCounter.getBeforeEachCalls(),
assertEquals(1, SwallowExceptionHandler.callCounter.beforeEachCalls,
"Exception should be handled in @BeforeEach");
assertEquals(1, SwallowExceptionHandler.callCounter.getAfterEachCalls(),
assertEquals(1, SwallowExceptionHandler.callCounter.afterEachCalls,
"Exception should be handled in @AfterEach");
assertEquals(1, SwallowExceptionHandler.callCounter.getAfterAllCalls(),
"Exception should be handled in @AfterAll");
assertEquals(1, SwallowExceptionHandler.callCounter.afterAllCalls, "Exception should be handled in @AfterAll");

executionResults.allEvents().assertEventsMatchExactly( //
event(engine(), started()), //
Expand All @@ -180,14 +175,13 @@ void exceptionHandlersSwallowException() {
void perClassLifecycleMethodsAreHandled() {
LauncherDiscoveryRequest request = request().selectors(selectClass(PerClassLifecycleTestCase.class)).build();
EngineExecutionResults executionResults = executeTests(request);
assertEquals(2, SwallowExceptionHandler.callCounter.getBeforeAllCalls(),
assertEquals(2, SwallowExceptionHandler.callCounter.beforeAllCalls,
"Exception should be handled in @BeforeAll");
assertEquals(1, SwallowExceptionHandler.callCounter.getBeforeEachCalls(),
assertEquals(1, SwallowExceptionHandler.callCounter.beforeEachCalls,
"Exception should be handled in @BeforeEach");
assertEquals(1, SwallowExceptionHandler.callCounter.getAfterEachCalls(),
assertEquals(1, SwallowExceptionHandler.callCounter.afterEachCalls,
"Exception should be handled in @AfterEach");
assertEquals(2, SwallowExceptionHandler.callCounter.getAfterAllCalls(),
"Exception should be handled in @AfterAll");
assertEquals(2, SwallowExceptionHandler.callCounter.afterAllCalls, "Exception should be handled in @AfterAll");

executionResults.allEvents().assertEventsMatchExactly( //
event(engine(), started()), //
Expand Down Expand Up @@ -238,9 +232,9 @@ void unrecoverableExceptionsAreNotPropagatedInBeforeAll() {

boolean unrecoverableExceptionThrown = executeThrowingOutOfMemoryException();
assertTrue(unrecoverableExceptionThrown, "Unrecoverable Exception should be thrown");
assertEquals(1, UnrecoverableExceptionHandler.callCounter.getBeforeAllCalls(),
assertEquals(1, UnrecoverableExceptionHandler.callCounter.beforeAllCalls,
"Exception should be handled in @BeforeAll");
assertEquals(0, ShouldNotBeCalledHandler.callCounter.getBeforeAllCalls(),
assertEquals(0, ShouldNotBeCalledHandler.callCounter.beforeAllCalls,
"Exception should not propagate in @BeforeAll");
}

Expand All @@ -253,9 +247,9 @@ void unrecoverableExceptionsAreNotPropagatedInBeforeEach() {

boolean unrecoverableExceptionThrown = executeThrowingOutOfMemoryException();
assertTrue(unrecoverableExceptionThrown, "Unrecoverable Exception should be thrown");
assertEquals(1, UnrecoverableExceptionHandler.callCounter.getBeforeEachCalls(),
assertEquals(1, UnrecoverableExceptionHandler.callCounter.beforeEachCalls,
"Exception should be handled in @BeforeEach");
assertEquals(0, ShouldNotBeCalledHandler.callCounter.getBeforeEachCalls(),
assertEquals(0, ShouldNotBeCalledHandler.callCounter.beforeEachCalls,
"Exception should not propagate in @BeforeEach");
}

Expand All @@ -268,9 +262,9 @@ void unrecoverableExceptionsAreNotPropagatedInAfterEach() {

boolean unrecoverableExceptionThrown = executeThrowingOutOfMemoryException();
assertTrue(unrecoverableExceptionThrown, "Unrecoverable Exception should be thrown");
assertEquals(1, UnrecoverableExceptionHandler.callCounter.getAfterEachCalls(),
assertEquals(1, UnrecoverableExceptionHandler.callCounter.afterEachCalls,
"Exception should be handled in @AfterEach");
assertEquals(0, ShouldNotBeCalledHandler.callCounter.getAfterEachCalls(),
assertEquals(0, ShouldNotBeCalledHandler.callCounter.afterEachCalls,
"Exception should not propagate in @AfterEach");
}

Expand All @@ -283,9 +277,9 @@ void unrecoverableExceptionsAreNotPropagatedInAfterAll() {

boolean unrecoverableExceptionThrown = executeThrowingOutOfMemoryException();
assertTrue(unrecoverableExceptionThrown, "Unrecoverable Exception should be thrown");
assertEquals(1, UnrecoverableExceptionHandler.callCounter.getAfterAllCalls(),
assertEquals(1, UnrecoverableExceptionHandler.callCounter.afterAllCalls,
"Exception should be handled in @AfterAll");
assertEquals(0, ShouldNotBeCalledHandler.callCounter.getAfterAllCalls(),
assertEquals(0, ShouldNotBeCalledHandler.callCounter.afterAllCalls,
"Exception should not propagate in @AfterAll");
}

Expand Down Expand Up @@ -561,4 +555,39 @@ public void handleAfterAllMethodExecutionException(ExtensionContext context, Thr
throw throwable;
}
}

static class HandlerCallCounter {
private int beforeAllCalls;
private int beforeEachCalls;
private int afterEachCalls;
private int afterAllCalls;

public HandlerCallCounter() {
reset();
}

public void reset() {
this.beforeAllCalls = 0;
this.beforeEachCalls = 0;
this.afterEachCalls = 0;
this.afterAllCalls = 0;
}

public void incrementBeforeAllCalls() {
beforeAllCalls++;
}

public void incrementBeforeEachCalls() {
beforeEachCalls++;
}

public void incrementAfterEachCalls() {
afterEachCalls++;
}

public void incrementAfterAllCalls() {
afterAllCalls++;
}

}
}

0 comments on commit 3f75c2f

Please sign in to comment.