Skip to content

Commit 32d0122

Browse files
committed
Remove obsolete fail statements in org.eclipse.ui.tests.navigator
Several test methods in org.eclipse.ui.tests.navigator 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 6f838bb commit 32d0122

File tree

10 files changed

+112
-261
lines changed

10 files changed

+112
-261
lines changed

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/ActionProviderTest.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import static org.junit.Assert.assertEquals;
1818
import static org.junit.Assert.assertNotNull;
1919
import static org.junit.Assert.assertNull;
20-
import static org.junit.Assert.fail;
2120

2221
import java.util.ArrayList;
2322
import java.util.List;
@@ -69,7 +68,7 @@ public void testBasicModel() throws Exception {
6968
}
7069

7170
@Test
72-
public void testOverride() {
71+
public void testOverride() throws CoreException {
7372
_contentService.bindExtensions(
7473
new String[] { TEST_CONTENT_ACTION_PROVIDER }, false);
7574
_contentService.getActivationService().activateExtensions(
@@ -79,12 +78,7 @@ public void testOverride() {
7978

8079
refreshViewer();
8180

82-
IStructuredSelection sel = null;
83-
try {
84-
sel = new StructuredSelection(((IContainer) _p2.members()[1]).members()[0]);
85-
} catch (CoreException e) {
86-
fail("Should not throw an exception");
87-
}
81+
IStructuredSelection sel = new StructuredSelection(((IContainer) _p2.members()[1]).members()[0]);
8882
_viewer.setSelection(sel);
8983

9084
if (SLEEP_LONG)
@@ -112,14 +106,9 @@ public void testOverride() {
112106
}
113107

114108
@Test
115-
public void testAppearsBefore() {
109+
public void testAppearsBefore() throws CoreException {
116110

117-
IStructuredSelection sel = null;
118-
try {
119-
sel = new StructuredSelection(((IContainer) _p2.members()[1]).members()[0]);
120-
} catch (CoreException e) {
121-
fail("Should not throw an exception");
122-
}
111+
IStructuredSelection sel = new StructuredSelection(((IContainer) _p2.members()[1]).members()[0]);
123112
_viewer.setSelection(sel);
124113

125114
MenuManager mm = new MenuManager();

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/DecorationSchedulerRaceConditionTest.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package org.eclipse.ui.tests.navigator;
1515

1616
import static org.junit.Assert.assertEquals;
17-
import static org.junit.Assert.fail;
1817

1918
import java.util.concurrent.Semaphore;
2019

@@ -81,28 +80,18 @@ public DecorationSchedulerRaceConditionTest() {
8180

8281
@Override
8382
@Before
84-
public void setUp() {
83+
public void setUp() throws CoreException {
8584
super.setUp();
8685

8786
_contentService.bindExtensions(new String[] { COMMON_NAVIGATOR_RESOURCE_EXT }, true);
8887
_contentService.getActivationService().activateExtensions(new String[] { COMMON_NAVIGATOR_RESOURCE_EXT }, true);
8988

9089
p1Project = ResourcesPlugin.getWorkspace().getRoot().getProject(TestWorkspace.P1_PROJECT_NAME);
9190
p2Project = ResourcesPlugin.getWorkspace().getRoot().getProject(TestWorkspace.P2_PROJECT_NAME);
92-
try {
93-
p1Project.setSessionProperty(DecorationSchedulerRaceConditionTestDecorator.DECO_PROP, DECORATION_TEXT_1);
94-
} catch (CoreException e) {
95-
e.printStackTrace();
96-
fail("Exception caught: " + e);
97-
}
91+
p1Project.setSessionProperty(DecorationSchedulerRaceConditionTestDecorator.DECO_PROP, DECORATION_TEXT_1);
9892

9993
IDecoratorManager manager = PlatformUI.getWorkbench().getDecoratorManager();
100-
try {
101-
manager.setEnabled("org.eclipse.ui.tests.navigator.bug417255Decorator", true);
102-
} catch (CoreException e) {
103-
e.printStackTrace();
104-
fail("Exception caught: " + e);
105-
}
94+
manager.setEnabled("org.eclipse.ui.tests.navigator.bug417255Decorator", true);
10695

10796
waitForP1Decoration.waitForCondition(Display.getCurrent(), TIMEOUT_DECORATOR); // wait for decorator to run
10897
DisplayHelper.sleep(Display.getCurrent(), TIMEOUT_UPDATE_JOB); // wait for update job following decoration to

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/DnDTest.java

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

2322
import org.eclipse.core.resources.IFile;
2423
import org.eclipse.jface.viewers.StructuredSelection;
@@ -32,8 +31,6 @@
3231
import org.eclipse.ui.tests.harness.util.DisplayHelper;
3332
import org.eclipse.ui.tests.harness.util.SWTEventHelper;
3433
import org.eclipse.ui.tests.navigator.extension.TestDragAssistant;
35-
import org.junit.After;
36-
import org.junit.Before;
3734
import org.junit.Test;
3835

3936
public class DnDTest extends NavigatorTestBase {
@@ -42,18 +39,6 @@ public DnDTest() {
4239
_navigatorInstanceId = TEST_VIEWER;
4340
}
4441

45-
@Override
46-
@Before
47-
public void setUp() {
48-
super.setUp();
49-
}
50-
51-
@Override
52-
@After
53-
public void tearDown() {
54-
super.tearDown();
55-
}
56-
5742
@Test
5843
public void testBasicDragDrop() {
5944
_viewer.expandToLevel(_p1, 3);
@@ -90,7 +75,7 @@ public void testBasicDragDrop() {
9075
// CommonDragAdapterAssistant
9176
// to perform clean up after drag has finished
9277
@Test
93-
public void testResourceDrag() {
78+
public void testResourceDrag() throws PartInitException {
9479
_viewer.expandToLevel(_p1, 3);
9580

9681
IFile file = _p1.getFolder("f1").getFile("file1.txt");
@@ -102,12 +87,7 @@ public void testResourceDrag() {
10287
// used
10388
IWorkbenchPage activePage = PlatformUI.getWorkbench()
10489
.getActiveWorkbenchWindow().getActivePage();
105-
TextEditor editorPart = null;
106-
try {
107-
editorPart = (TextEditor) IDE.openEditor(activePage, file);
108-
} catch (PartInitException e) {
109-
fail("Should not throw an exception");
110-
}
90+
TextEditor editorPart = (TextEditor) IDE.openEditor(activePage, file);
11191

11292
Control end = editorPart.getAdapter(Control.class);
11393

@@ -127,7 +107,7 @@ public void testResourceDrag() {
127107

128108
// bug 264323 [CommonNavigator] CommonDragAdapterAssistant should be allowed to opt out of a drag
129109
@Test
130-
public void testDragOptOut() {
110+
public void testDragOptOut() throws PartInitException {
131111
_viewer.expandToLevel(_p1, 3);
132112

133113
IFile file = _p1.getFolder("f1").getFile("file1.txt");
@@ -139,12 +119,7 @@ public void testDragOptOut() {
139119
// used
140120
IWorkbenchPage activePage = PlatformUI.getWorkbench()
141121
.getActiveWorkbenchWindow().getActivePage();
142-
TextEditor editorPart = null;
143-
try {
144-
editorPart = (TextEditor) IDE.openEditor(activePage, file);
145-
} catch (PartInitException e) {
146-
fail("Should not throw an exception");
147-
}
122+
TextEditor editorPart = (TextEditor) IDE.openEditor(activePage, file);
148123

149124
Control end = editorPart.getAdapter(Control.class);
150125

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/EvaluationCacheTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.util.ArrayList;
1717

18+
import org.eclipse.core.runtime.CoreException;
1819
import org.eclipse.ui.internal.navigator.VisibilityAssistant;
1920
import org.eclipse.ui.internal.navigator.extensions.EvaluationCache;
2021
import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor;
@@ -37,7 +38,7 @@ public EvaluationCacheTest() {
3738
}
3839

3940
@Override
40-
public void setUp() {
41+
public void setUp() throws CoreException {
4142
super.setUp();
4243
INavigatorViewerDescriptor mockViewerDescript = new TestNavigatorViewerDescriptor();
4344
INavigatorActivationService mockActivationService = new TestNavigatorActivationService();

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/GoBackForwardsTest.java

Lines changed: 29 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void doSetUp() throws CoreException, IOException {
7676
}
7777

7878
@Test
79-
public void testNavigationHistoryNavigation() {
79+
public void testNavigationHistoryNavigation() throws PartInitException {
8080
IIntroPart introPart = PlatformUI.getWorkbench().getIntroManager().getIntro();
8181
PlatformUI.getWorkbench().getIntroManager().closeIntro(introPart);
8282

@@ -91,39 +91,33 @@ public void testNavigationHistoryNavigation() {
9191

9292
openGenericEditor(editorInput);
9393

94-
if (!processEventsUntil(genericEditorNoSelection, 1000)) {
95-
fail("Timeout during navigation." + getStateDetails());
96-
}
94+
assertTrue("Timeout during navigation." + getStateDetails(),
95+
processEventsUntil(genericEditorNoSelection, 1000));
9796

9897
selectInGenericEditor(editorInput);
9998

100-
if (!processEventsUntil(genericEditorSelection, 1000)) {
101-
fail("Timeout during navigation." + getStateDetails());
102-
}
99+
assertTrue("Timeout during navigation." + getStateDetails(),
100+
processEventsUntil(genericEditorSelection, 1000));
103101

104102
openTextEditor(editorInput);
105103

106-
if (!processEventsUntil(textEditorNoSelection, 1000)) {
107-
fail("Timeout during navigation." + getStateDetails());
108-
}
104+
assertTrue("Timeout during navigation." + getStateDetails(),
105+
processEventsUntil(textEditorNoSelection, 1000));
109106

110107
selectInTextEditor(editorInput);
111108

112-
if (!processEventsUntil(textEditorSelection, 1000)) {
113-
fail("Timeout during navigation." + getStateDetails());
114-
}
109+
assertTrue("Timeout during navigation." + getStateDetails(),
110+
processEventsUntil(textEditorSelection, 1000));
115111

116112
openGenericEditor(editorInput);
117113

118-
if (!processEventsUntil(genericEditorSelection, 1000)) {
119-
fail("Timeout during navigation." + getStateDetails());
120-
}
114+
assertTrue("Timeout during navigation." + getStateDetails(),
115+
processEventsUntil(genericEditorSelection, 1000));
121116

122117
openTextEditor(editorInput);
123118

124-
if (!processEventsUntil(textEditorSelection, 1000)) {
125-
fail("Timeout during navigation." + getStateDetails());
126-
}
119+
assertTrue("Timeout during navigation." + getStateDetails(),
120+
processEventsUntil(textEditorSelection, 1000));
127121

128122
// Navigate backward from text editor to editor
129123
goBackward(EditorTestHelper.getActiveWorkbenchWindow(), genericEditorSelection);
@@ -184,58 +178,38 @@ private Condition currentNavigationHistoryLocationCondition(String editorId, boo
184178
};
185179
}
186180

187-
private void openGenericEditor(IEditorInput editorInput) {
188-
try {
189-
EditorTestHelper.getActivePage().openEditor(editorInput, GENERIC_EDITOR_ID, true,
190-
IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
191-
} catch (PartInitException e) {
192-
fail("Should not throw an exception");
193-
}
181+
private void openGenericEditor(IEditorInput editorInput) throws PartInitException {
182+
EditorTestHelper.getActivePage().openEditor(editorInput, GENERIC_EDITOR_ID, true,
183+
IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
194184
}
195185

196-
private void selectInGenericEditor(IEditorInput editorInput) {
197-
try {
198-
AbstractTextEditor editor = (AbstractTextEditor) EditorTestHelper.getActivePage().openEditor(editorInput,
199-
GENERIC_EDITOR_ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
200-
editor.selectAndReveal(10, 5);
201-
} catch (PartInitException e) {
202-
fail("Should not throw an exception");
203-
}
186+
private void selectInGenericEditor(IEditorInput editorInput) throws PartInitException {
187+
AbstractTextEditor editor = (AbstractTextEditor) EditorTestHelper.getActivePage().openEditor(editorInput,
188+
GENERIC_EDITOR_ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
189+
editor.selectAndReveal(10, 5);
204190
}
205191

206-
private void selectInTextEditor(IEditorInput editorInput) {
207-
try {
208-
AbstractTextEditor editor = (AbstractTextEditor) EditorTestHelper.getActivePage().openEditor(editorInput,
209-
TEXT_EDITOR_ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
210-
editor.selectAndReveal(10, 5);
211-
} catch (PartInitException e) {
212-
fail("Should not throw an exception");
213-
}
192+
private void selectInTextEditor(IEditorInput editorInput) throws PartInitException {
193+
AbstractTextEditor editor = (AbstractTextEditor) EditorTestHelper.getActivePage().openEditor(editorInput,
194+
TEXT_EDITOR_ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
195+
editor.selectAndReveal(10, 5);
214196
}
215197

216-
private void openTextEditor(IEditorInput editorInput) {
217-
try {
218-
EditorTestHelper.getActivePage().openEditor(editorInput, TEXT_EDITOR_ID, true,
219-
IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
220-
} catch (PartInitException e) {
221-
fail("Should not throw an exception");
222-
}
198+
private void openTextEditor(IEditorInput editorInput) throws PartInitException {
199+
EditorTestHelper.getActivePage().openEditor(editorInput, TEXT_EDITOR_ID, true,
200+
IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
223201
}
224202

225203
private void goForward(IWorkbenchWindow window, Condition condition) {
226204
NavigationHistoryAction action = new NavigationHistoryAction(window, true);
227205
action.run();
228-
if (!processEventsUntil(condition, 1000)) {
229-
fail("Timeout during navigation.");
230-
}
206+
assertTrue("Timeout during navigation.", processEventsUntil(condition, 1000));
231207
}
232208

233209
private void goBackward(IWorkbenchWindow window, Condition condition) {
234210
NavigationHistoryAction action = new NavigationHistoryAction(window, false);
235211
action.run();
236-
if (!processEventsUntil(condition, 1000)) {
237-
fail("Timeout during navigation.");
238-
}
212+
assertTrue("Timeout during navigation.", processEventsUntil(condition, 1000));
239213
}
240214

241215
private String getActiveEditorId() {

0 commit comments

Comments
 (0)