diff --git a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/HandlerCallCounter.java b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/HandlerCallCounter.java deleted file mode 100644 index a457cf16b5ea..000000000000 --- a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/HandlerCallCounter.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2015-2024 the original author or authors. - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v2.0 which - * accompanies this distribution and is available at - * - * https://www.eclipse.org/legal/epl-v20.html - */ - -package org.junit.jupiter.engine.extension; - -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++; - } - - public int getBeforeAllCalls() { - return beforeAllCalls; - } - - public int getBeforeEachCalls() { - return beforeEachCalls; - } - - public int getAfterEachCalls() { - return afterEachCalls; - } - - public int getAfterAllCalls() { - return afterAllCalls; - } -} diff --git a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/LifecycleMethodExecutionExceptionHandlerTests.java b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/LifecycleMethodExecutionExceptionHandlerTests.java index e923f03eeebc..b5a01ed5faba 100644 --- a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/LifecycleMethodExecutionExceptionHandlerTests.java +++ b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/LifecycleMethodExecutionExceptionHandlerTests.java @@ -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( // @@ -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( // @@ -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( // @@ -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( // @@ -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( // @@ -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( // @@ -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"); } @@ -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"); } @@ -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"); } @@ -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"); } @@ -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++; + } + + + } }