Skip to content

Commit a425b2c

Browse files
committed
Polish DisabledTests
1 parent 287e8e5 commit a425b2c

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

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

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@
1010

1111
package org.junit.jupiter.engine;
1212

13-
import static org.junit.jupiter.api.Assertions.assertAll;
14-
import static org.junit.jupiter.api.Assertions.assertEquals;
1513
import static org.junit.jupiter.api.Assertions.fail;
14+
import static org.junit.platform.testkit.engine.EventConditions.event;
15+
import static org.junit.platform.testkit.engine.EventConditions.skippedWithReason;
16+
import static org.junit.platform.testkit.engine.EventConditions.test;
17+
18+
import java.lang.reflect.Method;
1619

1720
import org.junit.jupiter.api.Disabled;
1821
import org.junit.jupiter.api.Test;
1922
import org.junit.platform.testkit.engine.EngineExecutionResults;
20-
import org.junit.platform.testkit.engine.Events;
2123

2224
/**
23-
* Integration tests that verify support for {@link Disabled @Disabled} in the {@link JupiterTestEngine}.
25+
* Integration tests that verify support for {@link Disabled @Disabled} in the
26+
* {@link JupiterTestEngine}.
2427
*
2528
* @since 5.0
2629
*/
@@ -36,28 +39,13 @@ void executeTestsWithDisabledTestClass() {
3639

3740
@Test
3841
void executeTestsWithDisabledTestMethods() throws Exception {
39-
Events tests = executeTestsForClass(DisabledTestMethodsTestCase.class).tests();
40-
41-
// MANUAL APPROACH for asserting statistics
42-
//
43-
// @formatter:off
44-
assertAll(
45-
() -> assertEquals(1, tests.started().count(), "# tests started"),
46-
() -> assertEquals(1, tests.skipped().count(), "# tests skipped"),
47-
() -> assertEquals(1, tests.finished().count(), "# tests finished"),
48-
() -> assertEquals(0, tests.aborted().count(), "# tests aborted"),
49-
() -> assertEquals(1, tests.succeeded().count(), "# tests succeeded"),
50-
() -> assertEquals(0, tests.failed().count(), "# tests failed")
51-
);
52-
// @formatter:on
53-
54-
// BUILT-IN APPROACH for asserting statistics
55-
//
56-
tests.assertStatistics(stats -> stats.skipped(1).started(1).finished(1).aborted(0).succeeded(1).failed(0));
57-
58-
String method = DisabledTestMethodsTestCase.class.getDeclaredMethod("disabledTest").toString();
59-
String reason = tests.skipped().map(e -> e.getRequiredPayload(String.class)).findFirst().orElse(null);
60-
assertEquals(method + " is @Disabled", reason);
42+
String methodName = "disabledTest";
43+
Method method = DisabledTestMethodsTestCase.class.getDeclaredMethod(methodName);
44+
45+
executeTestsForClass(DisabledTestMethodsTestCase.class).tests()//
46+
.assertStatistics(stats -> stats.skipped(1).started(1).finished(1).aborted(0).succeeded(1).failed(0))//
47+
.skipped().assertEventsMatchExactly(
48+
event(test(methodName), skippedWithReason(method + " is @Disabled")));
6149
}
6250

6351
// -------------------------------------------------------------------

0 commit comments

Comments
 (0)