Skip to content

Commit fa962ef

Browse files
committed
Remove obsolete exception handling in tests
Let the tests throw the exceptions instead to be handled by the JUnit framework. The adapted places do not throw CoreExceptions that would require additional handling for proper formatting.
1 parent ee7762a commit fa962ef

File tree

4 files changed

+24
-44
lines changed

4 files changed

+24
-44
lines changed

tests/org.eclipse.ui.tests.performance/src/org/eclipse/jface/tests/performance/FileImageDescriptorTest.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package org.eclipse.jface.tests.performance;
1616

17-
import java.io.IOException;
1817
import java.net.URL;
1918
import java.util.ArrayList;
2019
import java.util.Enumeration;
@@ -70,12 +69,7 @@ public void testRefresh() throws Throwable {
7069

7170
for (URL file : files) {
7271
startMeasuring();
73-
try {
74-
descriptor = ImageDescriptor.createFromFile(missing, FileLocator.toFileURL(file).getFile());
75-
} catch (IOException e) {
76-
fail(e.getLocalizedMessage(), e);
77-
continue;
78-
}
72+
descriptor = ImageDescriptor.createFromFile(missing, FileLocator.toFileURL(file).getFile());
7973

8074
for (int j = 0; j < 10; j++) {
8175
Image image = descriptor.createImage();

tests/org.eclipse.ui.tests.performance/src/org/eclipse/jface/tests/performance/ProgressMonitorDialogPerformanceTest.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
package org.eclipse.jface.tests.performance;
1616

17-
import java.lang.reflect.InvocationTargetException;
18-
1917
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
2018
import org.eclipse.jface.operation.IRunnableWithProgress;
2119
import org.eclipse.swt.widgets.Display;
@@ -80,11 +78,7 @@ public void testLongNames() throws Throwable {
8078
}
8179
};
8280

83-
try {
84-
dialog.run(false, true, runnable);
85-
} catch (InvocationTargetException | InterruptedException e) {
86-
fail(e.getMessage(), e);
87-
}
81+
dialog.run(false, true, runnable);
8882

8983
commitMeasurements();
9084
assertPerformance();

tests/org.eclipse.ui.tests.performance/src/org/eclipse/ui/tests/performance/BasicPerformanceTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.eclipse.test.performance.Dimension;
2727
import org.eclipse.ui.PlatformUI;
2828
import org.eclipse.ui.tests.harness.util.UITestCase;
29+
import org.junit.function.ThrowingRunnable;
2930
import org.osgi.framework.Bundle;
3031
import org.osgi.framework.BundleContext;
3132
import org.osgi.framework.FrameworkUtil;
@@ -221,7 +222,7 @@ protected IStatus run(IProgressMonitor monitor) {
221222
*
222223
* @since 3.1
223224
*/
224-
public static void exercise(Runnable runnable) throws CoreException {
225+
public static void exercise(ThrowingRunnable runnable) throws CoreException {
225226
exercise(runnable, 3, 100, 4000);
226227
}
227228

@@ -231,7 +232,7 @@ public static void exercise(Runnable runnable) throws CoreException {
231232
*
232233
* @since 3.1
233234
*/
234-
public static void exercise(Runnable runnable,
235+
public static void exercise(ThrowingRunnable runnable,
235236
int minIterations,
236237
int maxIterations, int maxTime) throws CoreException {
237238
long startTime = System.currentTimeMillis();
@@ -240,7 +241,7 @@ public static void exercise(Runnable runnable,
240241

241242
try {
242243
runnable.run();
243-
} catch (Exception e) {
244+
} catch (Throwable e) {
244245
throw new CoreException(new Status(IStatus.ERROR,
245246
FrameworkUtil.getBundle(BasicPerformanceTest.class)
246247
.getSymbolicName(), IStatus.OK,

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IAggregateWorkingSetTest.java

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ public void testWorkingSetCycle() throws Throwable {
173173
aggregateReloaded = (IAggregateWorkingSet) manager.createWorkingSet(memento);
174174
manager.addWorkingSet(aggregateReloaded);
175175
aggregateReloaded.getComponents();
176-
} catch (StackOverflowError e) {
177-
e.printStackTrace();
178-
fail("Stack overflow for self-referenced aggregate working set", e);
179176
} finally {
180177
if (aggregateReloaded != null) {
181178
manager.removeWorkingSet(aggregateReloaded);
@@ -230,9 +227,6 @@ public void testCycleCleanup() throws Throwable {
230227
for (IWorkingSet aggregate2 : aggregates) {
231228
assertFalse("testCycle".equals(aggregate2.getName()));
232229
}
233-
} catch (StackOverflowError e) {
234-
e.printStackTrace();
235-
fail("Stack overflow for self-referenced aggregate working set", e);
236230
} finally {
237231
if (aggregateReloaded != null) {
238232
manager.removeWorkingSet(aggregateReloaded);
@@ -385,7 +379,13 @@ public void testWorkingSetSaveNeverRestoresAggregate() throws Throwable {
385379
if (!(ws instanceof AggregateWorkingSet aws)) {
386380
return;
387381
}
388-
IMemento m = readField(AbstractWorkingSet.class, "workingSetMemento", IMemento.class, aws);
382+
IMemento m;
383+
try {
384+
m = readField(AbstractWorkingSet.class, "workingSetMemento", IMemento.class, aws);
385+
} catch (Exception e) {
386+
error.set(e.getMessage());
387+
return;
388+
}
389389
IWorkingSet[] sets = aws.getComponents();
390390
if (m != null) {
391391
IMemento[] msets = m.getChildren(IWorkbenchConstants.TAG_WORKING_SET);
@@ -442,7 +442,7 @@ public void testWorkingSetSaveNeverRestoresAggregate() throws Throwable {
442442
}
443443
}
444444

445-
private IMemento saveAndRemoveWorkingSets(IWorkingSet... sets) {
445+
private IMemento saveAndRemoveWorkingSets(IWorkingSet... sets) throws Exception {
446446
IMemento managerMemento = XMLMemento
447447
.createWriteRoot(IWorkbenchConstants.TAG_WORKING_SET_MANAGER);
448448
IWorkingSetManager manager = fWorkbench.getWorkingSetManager();
@@ -467,7 +467,7 @@ private IMemento saveAndRemoveWorkingSets(IWorkingSet... sets) {
467467
return managerMemento;
468468
}
469469

470-
private void restoreWorkingSetManager(IMemento managerMemento) {
470+
private void restoreWorkingSetManager(IMemento managerMemento) throws Exception {
471471
IWorkingSetManager manager = fWorkbench.getWorkingSetManager();
472472

473473
invokeMethod(AbstractWorkingSetManager.class, "restoreWorkingSetState",
@@ -479,25 +479,16 @@ private void restoreWorkingSetManager(IMemento managerMemento) {
479479
}
480480

481481
private Object invokeMethod(Class<?> clazz, String methodName, Object instance, Object[] args,
482-
Class<?>[] argsClasses) {
483-
try {
484-
Method method = clazz.getDeclaredMethod(methodName, argsClasses);
485-
method.setAccessible(true);
486-
return method.invoke(instance, args);
487-
} catch (Exception e) {
488-
fail("Failure in invoking " + clazz.getName() + methodName, e);
489-
}
490-
return null;
482+
Class<?>[] argsClasses) throws Exception {
483+
Method method = clazz.getDeclaredMethod(methodName, argsClasses);
484+
method.setAccessible(true);
485+
return method.invoke(instance, args);
491486
}
492487

493-
private <T> T readField(Class<?> clazz, String filedName, Class<T> type, Object instance) {
494-
try {
495-
Field field = clazz.getDeclaredField(filedName);
496-
field.setAccessible(true);
497-
return type.cast(field.get(instance));
498-
} catch (Exception e) {
499-
fail("Failure in reading " + clazz.getName() + filedName, e);
500-
}
501-
return null;
488+
private <T> T readField(Class<?> clazz, String filedName, Class<T> type, Object instance)
489+
throws Exception {
490+
Field field = clazz.getDeclaredField(filedName);
491+
field.setAccessible(true);
492+
return type.cast(field.get(instance));
502493
}
503494
}

0 commit comments

Comments
 (0)