Skip to content

Commit 34498a4

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.
1 parent 5802a46 commit 34498a4

2 files changed

Lines changed: 42 additions & 26 deletions

File tree

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)