Skip to content

Commit

Permalink
moved HandlerCallCounter to an internal class and removed getters
Browse files Browse the repository at this point in the history
  • Loading branch information
compf committed Jul 1, 2024
1 parent 863a4d2 commit eb0cf99
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 85 deletions.

This file was deleted.

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

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

executionResults.allEvents().assertEventsMatchExactly( //
Expand All @@ -101,9 +101,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,9 +120,9 @@ void classLevelExceptionHandlersConvertException() {
LauncherDiscoveryRequest request = request().selectors(selectClass(ConvertingTestCase.class)).build();
EngineExecutionResults executionResults = executeTests(request);

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

executionResults.allEvents().assertEventsMatchExactly( //
Expand All @@ -139,9 +139,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,13 +158,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(),
assertEquals(1, SwallowExceptionHandler.callCounter.afterAllCalls,
"Exception should be handled in @AfterAll");

executionResults.allEvents().assertEventsMatchExactly( //
Expand All @@ -180,13 +180,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(),
assertEquals(2, SwallowExceptionHandler.callCounter.afterAllCalls,
"Exception should be handled in @AfterAll");

executionResults.allEvents().assertEventsMatchExactly( //
Expand Down Expand Up @@ -238,9 +238,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 +253,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 +268,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 +283,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 +561,40 @@ public void handleAfterAllMethodExecutionException(ExtensionContext context, Thr
throw throwable;
}
}

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 eb0cf99

Please sign in to comment.