Skip to content

Commit 805b5b9

Browse files
HeikoKlareakurtakov
authored andcommitted
Remove obsolete fail statements in org.eclipse.ui.tests
Several test methods in org.eclipse.ui.tests catch exceptions to then simply fail with the message of that same exception. With this change, the test methods are adapted to directly throw those exceptions so simplify the test implementation and remove obsolete fail statements.
1 parent 82d778f commit 805b5b9

31 files changed

+308
-563
lines changed

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/adaptable/AdaptableDecoratorTestCase.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package org.eclipse.ui.tests.adaptable;
1616

1717
import static org.junit.Assert.assertTrue;
18-
import static org.junit.Assert.fail;
1918

2019
import java.io.ByteArrayInputStream;
2120

@@ -89,11 +88,7 @@ private DecoratorManager getDecoratorManager() {
8988
@After
9089
public void doTearDown() throws Exception {
9190
if (testProject != null) {
92-
try {
93-
testProject.delete(true, null);
94-
} catch (CoreException e) {
95-
fail(e.toString());
96-
}
91+
testProject.delete(true, null);
9792
testProject = null;
9893
testFolder = null;
9994
testFile = null;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
import static org.junit.Assert.assertNotNull;
1919
import static org.junit.Assert.assertNull;
2020
import static org.junit.Assert.assertTrue;
21-
import static org.junit.Assert.fail;
2221

22+
import org.eclipse.core.commands.ExecutionException;
2323
import org.eclipse.core.commands.NotEnabledException;
2424
import org.eclipse.core.commands.NotHandledException;
25+
import org.eclipse.core.commands.common.NotDefinedException;
2526
import org.eclipse.jface.action.Action;
2627
import org.eclipse.jface.action.IMenuManager;
2728
import org.eclipse.jface.action.IStatusLineManager;
@@ -210,7 +211,8 @@ public void testSetGlobalActionHandler() throws Throwable {
210211
assertTrue(quit.hasRun);
211212
}
212213

213-
private void runMatchingCommand(IWorkbenchWindow window, String actionId) {
214+
private void runMatchingCommand(IWorkbenchWindow window, String actionId)
215+
throws ExecutionException, NotDefinedException {
214216
IHandlerService hs = window.getService(IHandlerService.class);
215217
IActionCommandMappingService ms = window.getService(IActionCommandMappingService.class);
216218
String commandId = ms.getCommandId(actionId);
@@ -220,8 +222,6 @@ private void runMatchingCommand(IWorkbenchWindow window, String actionId) {
220222
} catch (NotHandledException | NotEnabledException e) {
221223
// this is not a failure, just a condition to be checked by
222224
// the test
223-
} catch (Exception e) {
224-
fail("Failed to run " + commandId);
225225
}
226226
}
227227
}

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

Lines changed: 34 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,11 +1283,7 @@ public void testGetViews() throws Throwable {
12831283
@Test
12841284
public void testHideViewWithPart() throws Throwable {
12851285
// test that nothing bad happens with a null parameter
1286-
try {
1287-
fActivePage.hideView((IViewPart) null);
1288-
} catch (RuntimeException e) {
1289-
fail(e.getMessage());
1290-
}
1286+
fActivePage.hideView((IViewPart) null);
12911287

12921288
IViewPart view = fActivePage.showView(MockViewPart.ID3);
12931289

@@ -1299,11 +1295,7 @@ public void testHideViewWithPart() throws Throwable {
12991295
@Test
13001296
public void testHideViewWithReference() throws Throwable {
13011297
// test that nothing bad happens with a null parameter
1302-
try {
1303-
fActivePage.hideView((IViewReference) null);
1304-
} catch (RuntimeException e) {
1305-
fail(e.getMessage());
1306-
}
1298+
fActivePage.hideView((IViewReference) null);
13071299

13081300
IViewPart view = fActivePage.showView(MockViewPart.ID4);
13091301
IViewReference ref = fActivePage.findViewReference(MockViewPart.ID4);
@@ -2133,22 +2125,18 @@ public void testView_VISIBLE3() throws PartInitException {
21332125
}
21342126

21352127
/**
2136-
* Test opening a perspective with placeholders for multi instance views.
2137-
* The placeholders are added at top level (not in any folder).
2128+
* Test opening a perspective with placeholders for multi instance views. The
2129+
* placeholders are added at top level (not in any folder).
2130+
*
2131+
* @throws WorkbenchException
21382132
*
21392133
* @since 3.1
21402134
*/
21412135
@Test
21422136
@Ignore
2143-
public void testOpenPerspectiveWithMultiViewPlaceholdersAtTopLevel() {
2137+
public void testOpenPerspectiveWithMultiViewPlaceholdersAtTopLevel() throws WorkbenchException {
21442138

2145-
try {
2146-
fWin.getWorkbench().showPerspective(
2147-
PerspectiveWithMultiViewPlaceholdersAtTopLevel.PERSP_ID,
2148-
fWin);
2149-
} catch (WorkbenchException e) {
2150-
fail("Unexpected WorkbenchException: " + e);
2151-
}
2139+
fWin.getWorkbench().showPerspective(PerspectiveWithMultiViewPlaceholdersAtTopLevel.PERSP_ID, fWin);
21522140

21532141
// ArrayList partIds = facade.getPerspectivePartIds(fActivePage, null);
21542142
// FIXME: No implementation for facade.getPerspectivePartIds()
@@ -2160,26 +2148,20 @@ public void testOpenPerspectiveWithMultiViewPlaceholdersAtTopLevel() {
21602148
}
21612149

21622150
/**
2163-
* Test opening a perspective with placeholders for multi instance views.
2164-
* The placeholders are added in a placeholder folder. This is a regression
2165-
* test for bug 72383 [Perspectives] Placeholder folder error with multiple
2166-
* instance views
2151+
* Test opening a perspective with placeholders for multi instance views. The
2152+
* placeholders are added in a placeholder folder. This is a regression test for
2153+
* bug 72383 [Perspectives] Placeholder folder error with multiple instance
2154+
* views
2155+
*
2156+
* @throws WorkbenchException
21672157
*
21682158
* @since 3.1
21692159
*/
21702160
@Test
21712161
@Ignore
2172-
public void testOpenPerspectiveWithMultiViewPlaceholdersInPlaceholderFolder() {
2162+
public void testOpenPerspectiveWithMultiViewPlaceholdersInPlaceholderFolder() throws WorkbenchException {
21732163

2174-
try {
2175-
fWin
2176-
.getWorkbench()
2177-
.showPerspective(
2178-
PerspectiveWithMultiViewPlaceholdersInPlaceholderFolder.PERSP_ID,
2179-
fWin);
2180-
} catch (WorkbenchException e) {
2181-
fail("Unexpected WorkbenchException: " + e);
2182-
}
2164+
fWin.getWorkbench().showPerspective(PerspectiveWithMultiViewPlaceholdersInPlaceholderFolder.PERSP_ID, fWin);
21832165

21842166
// ArrayList partIds = facade.getPerspectivePartIds(fActivePage,"placeholderFolder");
21852167

@@ -2192,23 +2174,17 @@ public void testOpenPerspectiveWithMultiViewPlaceholdersInPlaceholderFolder() {
21922174
}
21932175

21942176
/**
2195-
* Test opening a perspective with placeholders for multi instance views.
2196-
* The placeholders are added at top level (not in any folder).
2177+
* Test opening a perspective with placeholders for multi instance views. The
2178+
* placeholders are added at top level (not in any folder).
2179+
*
2180+
* @throws WorkbenchException
21972181
*
21982182
* @since 3.1
21992183
*/
22002184
@Test
22012185
@Ignore
2202-
public void testOpenPerspectiveWithMultiViewPlaceholdersInFolder() {
2203-
try {
2204-
fWin
2205-
.getWorkbench()
2206-
.showPerspective(
2207-
PerspectiveWithMultiViewPlaceholdersInFolder.PERSP_ID,
2208-
fWin);
2209-
} catch (WorkbenchException e) {
2210-
fail("Unexpected WorkbenchException: " + e);
2211-
}
2186+
public void testOpenPerspectiveWithMultiViewPlaceholdersInFolder() throws WorkbenchException {
2187+
fWin.getWorkbench().showPerspective(PerspectiveWithMultiViewPlaceholdersInFolder.PERSP_ID, fWin);
22122188

22132189
// ArrayList partIds = facade.getPerspectivePartIds(fActivePage,"folder");
22142190

@@ -2570,20 +2546,19 @@ public void testCloseAllPerspectivesDoesNotPromptBug272070()
25702546
* Tests that relative view is correctly shown if visible parameter specified.
25712547
* See bug 538199 - perspectiveExtension: visible="false" not honored when
25722548
* relative view does not exist
2549+
*
2550+
* @throws WorkbenchException
25732551
*/
25742552
@Test
2575-
public void testRelativeViewVisibility() {
2553+
public void testRelativeViewVisibility() throws WorkbenchException {
25762554
processEvents();
25772555

25782556
fActivePage.closeAllPerspectives(true, false);
25792557
IPerspectiveRegistry reg = fWorkbench.getPerspectiveRegistry();
25802558
IPerspectiveDescriptor testPerspective = reg.findPerspectiveWithId(PerspectiveViewsBug538199.ID);
25812559
fActivePage.setPerspective(testPerspective);
2582-
try {
2583-
fWin.getWorkbench().showPerspective(PerspectiveViewsBug538199.ID, fWin);
2584-
} catch (WorkbenchException e) {
2585-
fail("Unexpected WorkbenchException: " + e);
2586-
}
2560+
fWin.getWorkbench().showPerspective(PerspectiveViewsBug538199.ID, fWin);
2561+
25872562
processEvents();
25882563
IWorkbenchPage activePage = fWin.getActivePage();
25892564

@@ -2605,12 +2580,14 @@ public void testRelativeViewVisibility() {
26052580
}
26062581

26072582
/**
2608-
* Regression test for Bug 76285 [Presentations] Folder tab does not
2609-
* indicate current view. Tests that, when switching between perspectives,
2610-
* the remembered old part correctly handles multi-view instances.
2583+
* Regression test for Bug 76285 [Presentations] Folder tab does not indicate
2584+
* current view. Tests that, when switching between perspectives, the remembered
2585+
* old part correctly handles multi-view instances.
2586+
*
2587+
* @throws PartInitException
26112588
*/
26122589
@Test
2613-
public void testBug76285() {
2590+
public void testBug76285() throws PartInitException {
26142591
IWorkbenchPage page = fActivePage;
26152592
IPerspectiveDescriptor originalPersp = page.getPerspective();
26162593
IPerspectiveDescriptor resourcePersp = PlatformUI.getWorkbench()
@@ -2622,12 +2599,7 @@ public void testBug76285() {
26222599
int n = 5;
26232600
IViewPart[] views = new IViewPart[n];
26242601
for (int i = 0; i < n; ++i) {
2625-
try {
2626-
views[i] = page.showView(MockViewPart.IDMULT, Integer
2627-
.toString(i), IWorkbenchPage.VIEW_CREATE);
2628-
} catch (PartInitException e) {
2629-
fail(e.getMessage());
2630-
}
2602+
views[i] = page.showView(MockViewPart.IDMULT, Integer.toString(i), IWorkbenchPage.VIEW_CREATE);
26312603
}
26322604
assertEquals(5, page.getViews().length);
26332605
for (int i = 0; i < n; ++i) {

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,10 @@ public void testBadFactory_Restore() {
306306
fWorkingSet.saveState(m);
307307
BadElementFactory.shouldFailOnCreateElement = true;
308308
IWorkingSet copy = new WorkingSet(fWorkingSet.getName(), fWorkingSet.getId(), m) {};
309-
try {
310-
assertFalse(BadElementFactory.elementCreationAttemptedWhileShouldFail);
311-
IAdaptable [] elements = copy.getElements();
312-
assertTrue(BadElementFactory.elementCreationAttemptedWhileShouldFail);
313-
assertEquals("Element array should be empty", 0, elements.length);
314-
}
315-
catch (RuntimeException e) {
316-
fail("Error getting elements for broken factory", e);
317-
}
309+
assertFalse(BadElementFactory.elementCreationAttemptedWhileShouldFail);
310+
IAdaptable[] elements = copy.getElements();
311+
assertTrue(BadElementFactory.elementCreationAttemptedWhileShouldFail);
312+
assertEquals("Element array should be empty", 0, elements.length);
318313
}
319314

320315
/**
@@ -328,12 +323,8 @@ public void testBadFactory_Save() {
328323
IMemento m = XMLMemento.createWriteRoot("ws");
329324
BadElementFactory.BadElementInstance.shouldSaveFail = true;
330325
assertFalse(BadElementFactory.BadElementInstance.saveAttemptedWhileShouldFail);
331-
try {
332-
fWorkingSet.saveState(m);
333-
assertTrue(BadElementFactory.BadElementInstance.saveAttemptedWhileShouldFail);
334-
} catch (RuntimeException e) {
335-
fail("Error saving elements for broken persistable", e);
336-
}
326+
fWorkingSet.saveState(m);
327+
assertTrue(BadElementFactory.BadElementInstance.saveAttemptedWhileShouldFail);
337328
}
338329

339330
public static class Foo implements IAdaptable {

0 commit comments

Comments
 (0)