Skip to content

Commit 7212335

Browse files
committed
Migrate TestFailReporter to JUnit 5 TestFailExtension
Extracts the TestFailReporter inner class from FileBufferFunctions into a standalone TestFailExtension class that implements JUnit 5's TestWatcher interface. Updates FileBufferFunctions to use @RegisterExtension with the new extension. Updates rules-replacement.md to reflect the migration.
1 parent 4ba0593 commit 7212335

3 files changed

Lines changed: 64 additions & 26 deletions

File tree

rules-replacement.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# JUnit 4 to JUnit 5 Migration: Rules and Extensions
2+
3+
The following table summarizes the JUnit 4 constructs and their corresponding JUnit 5 replacements within the Eclipse Platform UI codebase, as identified in issues [#3629](https://github.com/eclipse-platform/eclipse.platform.ui/issues/3629) and [#3639](https://github.com/eclipse-platform/eclipse.platform.ui/issues/3639).
4+
5+
| JUnit 4 Construct | JUnit 5 Replacement | Location / Note |
6+
| :--- | :--- | :--- |
7+
| `CloseTestWindowsRule` | `CloseTestWindowsExtension` | `org.eclipse.ui.tests.harness.util` |
8+
| `PreferenceMementoRule` | `PreferenceMementoExtension` | `org.eclipse.ui.tests.harness.util` |
9+
| `HeadlessApplicationRule` | `HeadlessApplicationExtension` | `org.eclipse.e4.ui.tests.rules` |
10+
| `WorkbenchContextRule` | `WorkbenchContextExtension` | `org.eclipse.e4.ui.tests.rules` |
11+
| `JFaceActionRule` | `JFaceActionExtension` | `org.eclipse.jface.tests.action` |
12+
| `SwtLeakTestWatcher` | `SwtLeakExtension` | `org.eclipse.ui.tests` |
13+
| `PerformanceTestCaseJunit4` | `PerformanceTestCaseJunit5` | Provided by `org.eclipse.test.performance` |
14+
| `UIPerformanceTestRule` | `UIPerformanceTestRule` | Implements `BeforeAllCallback` / `AfterAllCallback` |
15+
| `BindingTestSetup` | **Missing** | |
16+
| `TestFailReporter` | `TestFailExtension` | `org.eclipse.core.filebuffers.tests` |
17+
18+
## Key Observations
19+
20+
* **Dual Support**: `UIPerformanceTestRule` currently implements both JUnit 4 `ExternalResource` and JUnit 5 `BeforeAllCallback`/`AfterAllCallback` interfaces, allowing it to be used in both environments.
21+
* **Performance Migration**: Per issue #3639, `PerformanceTestCaseJunit5` is the functional equivalent of `PerformanceTestCaseJunit4`, requiring updates to annotations and extension usage.
22+
* **Pending Replacements**: `BindingTestSetup` does not yet have a specialized JUnit 5 extension equivalent in the repository.

tests/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferFunctions.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,13 @@
2828
import org.junit.jupiter.api.BeforeEach;
2929
import org.junit.jupiter.api.Test;
3030
import org.junit.jupiter.api.extension.RegisterExtension;
31-
import org.junit.jupiter.api.extension.ExtensionContext;
32-
import org.junit.jupiter.api.extension.TestWatcher;
3331

3432

3533
import org.eclipse.core.filesystem.EFS;
3634
import org.eclipse.core.filesystem.IFileInfo;
3735
import org.eclipse.core.filesystem.IFileStore;
3836

39-
import org.eclipse.core.runtime.ILog;
4037
import org.eclipse.core.runtime.IPath;
41-
import org.eclipse.core.runtime.IStatus;
42-
import org.eclipse.core.runtime.Platform;
43-
import org.eclipse.core.runtime.Status;
4438

4539
import org.eclipse.core.resources.IProject;
4640

@@ -104,26 +98,7 @@ protected IPath getPath() {
10498
}
10599

106100
@RegisterExtension
107-
public TestFailReporter failReporter= new TestFailReporter();
108-
109-
public static class TestFailReporter implements TestWatcher {
110-
111-
private static final String BUNDLE_ID= "org.eclipse.core.filebuffers.tests";
112-
113-
ILog log= ILog.of(Platform.getBundle(BUNDLE_ID));
114-
115-
@Override
116-
public void testFailed(ExtensionContext context, Throwable e) {
117-
IStatus status= new Status(IStatus.ERROR, BUNDLE_ID, "FAIL in " + context.getDisplayName(), e);
118-
log.log(status);
119-
}
120-
121-
@Override
122-
public void testSuccessful(ExtensionContext context) {
123-
IStatus status= new Status(IStatus.INFO, BUNDLE_ID, "PASS in " + context.getDisplayName());
124-
log.log(status);
125-
}
126-
}
101+
public TestFailExtension failReporter= new TestFailExtension();
127102

128103
/*
129104
* Tests getLocation.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2000, 2015 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.core.filebuffers.tests;
15+
16+
import org.junit.jupiter.api.extension.ExtensionContext;
17+
import org.junit.jupiter.api.extension.TestWatcher;
18+
19+
import org.eclipse.core.runtime.ILog;
20+
import org.eclipse.core.runtime.IStatus;
21+
import org.eclipse.core.runtime.Platform;
22+
import org.eclipse.core.runtime.Status;
23+
24+
public class TestFailExtension implements TestWatcher {
25+
26+
private static final String BUNDLE_ID= "org.eclipse.core.filebuffers.tests";
27+
28+
ILog log= ILog.of(Platform.getBundle(BUNDLE_ID));
29+
30+
@Override
31+
public void testFailed(ExtensionContext context, Throwable e) {
32+
IStatus status= new Status(IStatus.ERROR, BUNDLE_ID, "FAIL in " + context.getDisplayName(), e);
33+
log.log(status);
34+
}
35+
36+
@Override
37+
public void testSuccessful(ExtensionContext context) {
38+
IStatus status= new Status(IStatus.INFO, BUNDLE_ID, "PASS in " + context.getDisplayName());
39+
log.log(status);
40+
}
41+
}

0 commit comments

Comments
 (0)