Skip to content

Commit bef91e7

Browse files
committed
Replace JUnit 4 ThrowingRunnable with JUnit 5 Executable #903
Contributes to #903
1 parent 3d56f06 commit bef91e7

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@
5757
import org.eclipse.core.tests.harness.TestBarrier2;
5858
import org.eclipse.core.tests.harness.TestJob;
5959
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
60-
import org.junit.function.ThrowingRunnable;
6160
import org.junit.jupiter.api.AfterEach;
6261
import org.junit.jupiter.api.BeforeEach;
6362
import org.junit.jupiter.api.Test;
6463
import org.junit.jupiter.api.TestInfo;
6564
import org.junit.jupiter.api.extension.ExtendWith;
65+
import org.junit.jupiter.api.function.Executable;
6666

6767
/**
6868
* This class tests public API related to building and to build specifications.
@@ -553,7 +553,7 @@ public void testChangeDynamicBuildOrderDuringPreBuild() throws Throwable {
553553
// Ensure the builder is instantiated
554554
workspace.build(IncrementalProjectBuilder.FULL_BUILD, createTestMonitor());
555555

556-
final AtomicReference<ThrowingRunnable> exceptionInMainThreadCallback = new AtomicReference<>(
556+
final AtomicReference<Executable> exceptionInMainThreadCallback = new AtomicReference<>(
557557
Function::identity);
558558

559559
// Add pre-build listener that swap around the dependencies
@@ -614,7 +614,7 @@ public void testChangeDynamicBuildOrderDuringPreBuild() throws Throwable {
614614
verifier.assertLifecycleEvents();
615615
verifier.reset();
616616

617-
exceptionInMainThreadCallback.get().run();
617+
exceptionInMainThreadCallback.get().execute();
618618
} finally {
619619
getWorkspace().removeResourceChangeListener(buildListener);
620620
}

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/RelaxedSchedRuleBuilderTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@
5858
import org.eclipse.core.tests.internal.builders.TestBuilder.BuilderRuleCallback;
5959
import org.eclipse.core.tests.resources.TestUtil;
6060
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
61-
import org.junit.function.ThrowingRunnable;
6261
import org.junit.jupiter.api.AfterEach;
6362
import org.junit.jupiter.api.BeforeEach;
6463
import org.junit.jupiter.api.Test;
6564
import org.junit.jupiter.api.TestInfo;
6665
import org.junit.jupiter.api.extension.ExtendWith;
66+
import org.junit.jupiter.api.function.Executable;
6767

6868
/**
6969
* This class tests extended functionality (since 3.6) which allows
@@ -140,7 +140,7 @@ public IProject[] build(int kind, Map<String, String> args, IProgressMonitor mon
140140
}
141141
});
142142

143-
final AtomicReference<ThrowingRunnable> exceptionInMainThreadCallback = new AtomicReference<>(Function::identity);
143+
final AtomicReference<Executable> exceptionInMainThreadCallback = new AtomicReference<>(Function::identity);
144144
Job j = new Job("build job") {
145145
@Override
146146
protected IStatus run(IProgressMonitor monitor) {
@@ -167,7 +167,7 @@ protected IStatus run(IProgressMonitor monitor) {
167167
j.cancel();
168168
tb.waitForStatus(TestBarrier2.STATUS_DONE);
169169

170-
exceptionInMainThreadCallback.get().run();
170+
exceptionInMainThreadCallback.get().execute();
171171
}
172172

173173
/**
@@ -238,7 +238,7 @@ public IProject[] build(int kind, Map<String, String> args, IProgressMonitor mon
238238
}
239239
});
240240

241-
final AtomicReference<ThrowingRunnable> exceptionInMainThreadCallback = new AtomicReference<>(
241+
final AtomicReference<Executable> exceptionInMainThreadCallback = new AtomicReference<>(
242242
Function::identity);
243243
// Run the build
244244
Job j = new Job("build job1") {
@@ -266,7 +266,7 @@ protected IStatus run(IProgressMonitor monitor) {
266266
tb2.setStatus(TestBarrier2.STATUS_WAIT_FOR_DONE);
267267
tb2.waitForStatus(TestBarrier2.STATUS_DONE);
268268

269-
exceptionInMainThreadCallback.get().run();
269+
exceptionInMainThreadCallback.get().execute();
270270
}
271271

272272
HashSet<ISchedulingRule> getRulesAsSet(ISchedulingRule rule) {
@@ -523,7 +523,7 @@ public IProject[] build(int kind, Map<String, String> args, IProgressMonitor mon
523523
// };
524524
// invokeTestBug343256(project, getRules, buildRules, tb1, tb2, j);
525525

526-
final AtomicReference<ThrowingRunnable> exceptionInMainThreadCallback = new AtomicReference<>(
526+
final AtomicReference<Executable> exceptionInMainThreadCallback = new AtomicReference<>(
527527
Function::identity);
528528
// IWorkspace.build(IBuildConfiguration[],...)
529529
j = new Job("IWorkspace.build(IBuildConfiguration[],...)") {
@@ -541,7 +541,7 @@ protected IStatus run(IProgressMonitor monitor) {
541541
};
542542
invokeTestBug343256(project, getRules, buildRules, tb1, tb2, j);
543543

544-
exceptionInMainThreadCallback.get().run();
544+
exceptionInMainThreadCallback.get().execute();
545545
// Test Auto-build
546546
// j = new Job("Auto-build") {
547547
// protected IStatus run(IProgressMonitor monitor) {

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeListenerTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@
6666
import org.eclipse.core.runtime.SubMonitor;
6767
import org.eclipse.core.runtime.jobs.Job;
6868
import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension;
69-
import org.junit.function.ThrowingRunnable;
7069
import org.junit.jupiter.api.AfterEach;
7170
import org.junit.jupiter.api.Assertions;
7271
import org.junit.jupiter.api.BeforeEach;
7372
import org.junit.jupiter.api.Test;
7473
import org.junit.jupiter.api.extension.RegisterExtension;
74+
import org.junit.jupiter.api.function.Executable;
7575
import org.osgi.framework.Bundle;
7676
import org.osgi.framework.BundleContext;
7777
import org.osgi.framework.FrameworkUtil;
@@ -102,7 +102,7 @@ public void resourceChanged(IResourceChangeEvent event) {
102102
}
103103
}
104104

105-
private static final ThrowingRunnable NOOP_RUNNABLE = () -> {
105+
private static final Executable NOOP_RUNNABLE = () -> {
106106
};
107107
protected static final String VERIFIER_NAME = "TestListener";
108108
IFile file1; //below folder1
@@ -272,7 +272,7 @@ public void tearDown() throws Exception {
272272
*/
273273
@Test
274274
public void test_1GDK9OG() throws Throwable {
275-
final AtomicReference<ThrowingRunnable> listenerInMainThreadCallback = new AtomicReference<>(NOOP_RUNNABLE);
275+
final AtomicReference<Executable> listenerInMainThreadCallback = new AtomicReference<>(NOOP_RUNNABLE);
276276
// create the resource change listener
277277
IResourceChangeListener listener = event -> {
278278
try {
@@ -324,7 +324,7 @@ public void run(IProgressMonitor monitor) throws CoreException {
324324
// cleanup: ensure that the listener is removed
325325
getWorkspace().removeResourceChangeListener(listener);
326326
}
327-
listenerInMainThreadCallback.get().run();
327+
listenerInMainThreadCallback.get().execute();
328328
}
329329

330330
@Test
@@ -403,7 +403,7 @@ public void testAddProject() throws CoreException {
403403
*/
404404
@Test
405405
public void testBug45996() throws Throwable {
406-
final AtomicReference<ThrowingRunnable> listenerInMainThreadCallback = new AtomicReference<>(NOOP_RUNNABLE);
406+
final AtomicReference<Executable> listenerInMainThreadCallback = new AtomicReference<>(NOOP_RUNNABLE);
407407
// create the resource change listener
408408
IResourceChangeListener listener = event -> {
409409
try {
@@ -447,7 +447,7 @@ public void run(IProgressMonitor monitor) throws CoreException {
447447
// cleanup: ensure that the listener is removed
448448
getWorkspace().removeResourceChangeListener(listener);
449449
}
450-
listenerInMainThreadCallback.get().run();
450+
listenerInMainThreadCallback.get().execute();
451451
}
452452

453453
@Test
@@ -721,7 +721,7 @@ public void testDeleteMoveFile() throws CoreException {
721721

722722
@Test
723723
public void testDeleteProject() throws Throwable {
724-
final AtomicReference<ThrowingRunnable> listenerInMainThreadCallback = new AtomicReference<>(NOOP_RUNNABLE);
724+
final AtomicReference<Executable> listenerInMainThreadCallback = new AtomicReference<>(NOOP_RUNNABLE);
725725
//test that marker deltas are fired when projects are deleted
726726
verifier.reset();
727727
final IMarker marker = project1.createMarker(IMarker.TASK);
@@ -760,7 +760,7 @@ public void resourceChanged(IResourceChangeEvent event) {
760760
} finally {
761761
getWorkspace().removeResourceChangeListener(listener);
762762
}
763-
listenerInMainThreadCallback.get().run();
763+
listenerInMainThreadCallback.get().execute();
764764
}
765765

766766
@Test
@@ -968,16 +968,16 @@ public void resourceChanged(final IResourceChangeEvent event) {
968968
*/
969969
@Test
970970
public void testHiddenPhantomChanges() throws Throwable {
971-
final AtomicReference<ThrowingRunnable> listenerInMainThreadCallback = new AtomicReference<>(NOOP_RUNNABLE);
971+
final AtomicReference<Executable> listenerInMainThreadCallback = new AtomicReference<>(NOOP_RUNNABLE);
972972
final IWorkspace workspace = getWorkspace();
973973
final IFolder phantomFolder = project1.getFolder("PhantomFolder");
974974
final IFile phantomFile = folder1.getFile("PhantomFile");
975975
final IResource[] phantomResources = new IResource[] {phantomFolder, phantomFile};
976976
final QualifiedName partner = new QualifiedName("Test", "Infected");
977977
IResourceChangeListener listener = event -> {
978-
ThrowingRunnable oldCallback = listenerInMainThreadCallback.get();
978+
Executable oldCallback = listenerInMainThreadCallback.get();
979979
listenerInMainThreadCallback.set(() -> {
980-
oldCallback.run();
980+
oldCallback.execute();
981981
// make sure the delta doesn't include the phantom members
982982
assertNotDeltaIncludes(event.getDelta(), phantomResources);
983983
// make sure a visitor does not find phantom members
@@ -1011,7 +1011,7 @@ public void testHiddenPhantomChanges() throws Throwable {
10111011
} finally {
10121012
workspace.removeResourceChangeListener(listener);
10131013
}
1014-
listenerInMainThreadCallback.get().run();
1014+
listenerInMainThreadCallback.get().execute();
10151015
}
10161016

10171017
/**
@@ -1020,15 +1020,15 @@ public void testHiddenPhantomChanges() throws Throwable {
10201020
*/
10211021
@Test
10221022
public void testHiddenTeamPrivateChanges() throws Throwable {
1023-
final AtomicReference<ThrowingRunnable> listenerInMainThreadCallback = new AtomicReference<>(NOOP_RUNNABLE);
1023+
final AtomicReference<Executable> listenerInMainThreadCallback = new AtomicReference<>(NOOP_RUNNABLE);
10241024
IWorkspace workspace = getWorkspace();
10251025
final IFolder teamPrivateFolder = project1.getFolder("TeamPrivateFolder");
10261026
final IFile teamPrivateFile = folder1.getFile("TeamPrivateFile");
10271027
final IResource[] privateResources = new IResource[] {teamPrivateFolder, teamPrivateFile};
10281028
IResourceChangeListener listener = event -> {
1029-
ThrowingRunnable oldCallback = listenerInMainThreadCallback.get();
1029+
Executable oldCallback = listenerInMainThreadCallback.get();
10301030
listenerInMainThreadCallback.set(() -> {
1031-
oldCallback.run();
1031+
oldCallback.execute();
10321032
// make sure the delta doesn't include the team private members
10331033
assertNotDeltaIncludes(event.getDelta(), privateResources);
10341034
// make sure a visitor does not find team private members
@@ -1066,7 +1066,7 @@ public void testHiddenTeamPrivateChanges() throws Throwable {
10661066
} finally {
10671067
workspace.removeResourceChangeListener(listener);
10681068
}
1069-
listenerInMainThreadCallback.get().run();
1069+
listenerInMainThreadCallback.get().execute();
10701070
}
10711071

10721072
@Test
@@ -1321,7 +1321,7 @@ public void resourceChanged(IResourceChangeEvent event) {
13211321

13221322
@Test
13231323
public void testAutoPublishService() throws Throwable {
1324-
final AtomicReference<ThrowingRunnable> logListenerInMainThreadCallback = new AtomicReference<>(NOOP_RUNNABLE);
1324+
final AtomicReference<Executable> logListenerInMainThreadCallback = new AtomicReference<>(NOOP_RUNNABLE);
13251325
class Loggy implements LogListener {
13261326
public boolean done = false;
13271327
@Override
@@ -1392,7 +1392,7 @@ public void resourceChanged(IResourceChangeEvent event) {
13921392
assertEquals(IResourceChangeEvent.POST_CHANGE, listener1.eventType);
13931393
assertEquals(IResourceChangeEvent.POST_BUILD, listener2.eventType);
13941394
assertEquals(IResourceChangeEvent.POST_CHANGE, listener3.eventType);
1395-
logListenerInMainThreadCallback.get().run();
1395+
logListenerInMainThreadCallback.get().execute();
13961396
}
13971397

13981398
public boolean waitUntil(BooleanSupplier condition) {

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchFileStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import org.eclipse.core.internal.filesystem.local.LocalFileNativesManager;
2424
import org.eclipse.core.runtime.CoreException;
2525
import org.eclipse.core.tests.harness.PerformanceTestRunner;
26-
import org.junit.function.ThrowingRunnable;
2726
import org.junit.jupiter.api.BeforeEach;
2827
import org.junit.jupiter.api.Test;
2928
import org.junit.jupiter.api.TestInfo;
29+
import org.junit.jupiter.api.function.Executable;
3030

3131
/**
3232
* Benchmarks basic operations on the IFileStore interface
@@ -109,11 +109,11 @@ public void testStoreNotExitsNio() throws Throwable {
109109
});
110110
}
111111

112-
private static void withNatives(boolean natives, ThrowingRunnable runnable) throws Throwable {
112+
private static void withNatives(boolean natives, Executable runnable) throws Throwable {
113113
try {
114114
assertEquals("can't set natives to the desired value", natives,
115115
LocalFileNativesManager.setUsingNative(natives));
116-
runnable.run();
116+
runnable.execute();
117117
} finally {
118118
LocalFileNativesManager.reset();
119119
}

0 commit comments

Comments
 (0)