Skip to content

Commit 7801de7

Browse files
committed
Use Status creation methods in ui.tests
Simplifies the code a bit.
1 parent e5503ef commit 7801de7

10 files changed

Lines changed: 38 additions & 67 deletions

File tree

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2006, 2017 IBM Corporation and others.
2+
* Copyright (c) 2006, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -108,18 +108,11 @@ public void setInitializationData(IConfigurationElement config,
108108
} else if (data instanceof Map) {
109109
parameterMap = (Map<String, String>) data;
110110
if (parameterMap.get(PARM_COMMAND_ID) == null) {
111-
Status status = new Status(IStatus.ERROR,
112-
"org.eclipse.ui.tests", "The '" + id
113-
+ "' action won't work without a commandId");
111+
IStatus status = Status.error("The '" + id + "' action won't work without a commandId");
114112
throw new CoreException(status);
115113
}
116114
} else {
117-
Status status = new Status(
118-
IStatus.ERROR,
119-
"org.eclipse.ui.tests",
120-
"The '"
121-
+ id
122-
+ "' action won't work without some initialization parameters");
115+
IStatus status = Status.error("The '" + id + "' action won't work without some initialization parameters");
123116
throw new CoreException(status);
124117
}
125118
}

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dialogs/UIErrorDialogs.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2006 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -35,15 +35,12 @@ private Shell getShell() {
3535
private ErrorDialog getMultiStatusErrorDialog() {
3636

3737
IStatus[] childStatuses = new IStatus[2];
38-
childStatuses[0] = new Status(IStatus.ERROR, "org.eclipse.ui.tests",
39-
IStatus.ERROR, "Error message 1", new Throwable());
40-
childStatuses[1] = new Status(IStatus.ERROR, "org.eclipse.ui.tests",
41-
IStatus.ERROR, "Error message 2", new Throwable());
42-
MultiStatus mainStatus = new MultiStatus("org.eclipse.ui.tests",
43-
IStatus.ERROR, childStatuses, "Main error", new Throwable());
44-
45-
return new ErrorDialog(getShell(), "Error Test", "Error message",
46-
mainStatus, IStatus.ERROR);
38+
childStatuses[0] = Status.error("Error message 1", new Throwable());
39+
childStatuses[1] = Status.error("Error message 2", new Throwable());
40+
MultiStatus mainStatus = new MultiStatus("org.eclipse.ui.tests", IStatus.ERROR, childStatuses, "Main error",
41+
new Throwable());
42+
43+
return new ErrorDialog(getShell(), "Error Test", "Error message", mainStatus, IStatus.ERROR);
4744
}
4845

4946
@Test

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/VirtualTestFileStore.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.eclipse.core.runtime.CoreException;
1919
import org.eclipse.core.runtime.IPath;
2020
import org.eclipse.core.runtime.IProgressMonitor;
21-
import org.eclipse.core.runtime.IStatus;
2221
import org.eclipse.core.runtime.Status;
2322

2423
/**
@@ -112,8 +111,7 @@ public InputStream openInputStream(int options, IProgressMonitor monitor) throws
112111
if (contents != null) {
113112
return new ByteArrayInputStream(contents);
114113
}
115-
throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.ui.tests", //$NON-NLS-1$
116-
"File does not exist: " + toURI())); //$NON-NLS-1$
114+
throw new CoreException(Status.error("File does not exist: " + toURI())); //$NON-NLS-1$
117115
}
118116

119117
@Override
@@ -133,16 +131,14 @@ public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreExcept
133131
IFileInfo info = fetchInfo();
134132
if (info.exists()) {
135133
if (!info.isDirectory()) {
136-
throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.ui.tests", //$NON-NLS-1$
137-
"mkdir failed - file already exists with name: " + toURI())); //$NON-NLS-1$
134+
throw new CoreException(Status.error("mkdir failed - file already exists with name: " + toURI())); //$NON-NLS-1$
138135
}
139136
} else {
140137
IFileStore parent = getParent();
141138
if (parent.fetchInfo().exists()) {
142139
VirtualTestFileSystem.getDefault().setContents(toURI(), VirtualTestFileSystem.DIRECTORY_BYTES);
143140
} else if ((options & EFS.SHALLOW) > 0) {
144-
throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.ui.tests", //$NON-NLS-1$
145-
"mkdir failed - parent does not exist: " + toURI())); //$NON-NLS-1$
141+
throw new CoreException(Status.error("mkdir failed - parent does not exist: " + toURI())); //$NON-NLS-1$
146142
} else {
147143
parent.mkdir(EFS.NONE, null);
148144
}

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/manual/TestBackgroundSaveEditor.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2006, 2023 IBM Corporation and others.
2+
* Copyright (c) 2006, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -93,9 +93,7 @@ public IJobRunnable doSave(IProgressMonitor monitor,
9393
monitor.worked(1);
9494
}
9595
if (data.throwExceptionInForeground) {
96-
throw new CoreException(new Status(IStatus.ERROR,
97-
"org.eclipse.ui.tests",
98-
"Saving in the foreground failed"));
96+
throw new CoreException(Status.error("Saving in the foreground failed"));
9997
}
10098
monitor.done();
10199
if (!data.saveInBackground) {
@@ -119,7 +117,7 @@ public IJobRunnable doSave(IProgressMonitor monitor,
119117
monitor1.worked(1);
120118
}
121119
if (data.throwExceptionInBackground) {
122-
return new Status(IStatus.ERROR, "org.eclipse.ui.tests", "Saving in the background failed");
120+
return Status.error("Saving in the background failed");
123121
}
124122
data.setOutput(data.getInput());
125123
setDirty(false);

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/AccumulatingProgressMonitorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2021 Red Hat Inc. and others.
2+
* Copyright (c) 2016, 2026 Red Hat Inc. and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -207,7 +207,7 @@ public void run() {
207207
wrapper.worked(10);
208208
wrapper.isCanceled();
209209
wrapper.setCanceled(false);
210-
wrapper.setBlocked(new Status(IStatus.ERROR, "org.eclipse.ui.tests", "Some Error"));
210+
wrapper.setBlocked(Status.error("Some Error"));
211211

212212
uiSemaphore.release();
213213
uiReleaseCount++;

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/ProgressContantsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2024 IBM Corporation and others.
2+
* Copyright (c) 2009, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -219,7 +219,7 @@ public void testKeepOneProperty() throws Exception {
219219
// Solution is to add an unique job after the 'keep one' jobs are finished and
220220
// wait for it's appearance. The UI updates are ordered enough to be sure that
221221
// kept job processing is finished when this error job appears.
222-
DummyJob errorJob = new DummyJob("Last Job", new Status(IStatus.ERROR, TestPlugin.PLUGIN_ID, "error"));
222+
DummyJob errorJob = new DummyJob("Last Job", Status.error("error"));
223223
errorJob.schedule();
224224
processEventsUntil(() -> findProgressInfoItem(errorJob) != null, 3000);
225225
}
@@ -252,7 +252,7 @@ public void testKeepOneProperty() throws Exception {
252252
// Process events to ensure job completion events are handled
253253
processEvents();
254254
{
255-
DummyJob errorJob = new DummyJob("Last Job", new Status(IStatus.ERROR, TestPlugin.PLUGIN_ID, "error"));
255+
DummyJob errorJob = new DummyJob("Last Job", Status.error("error"));
256256
errorJob.schedule();
257257
processEventsUntil(() -> findProgressInfoItem(errorJob) != null, 3000);
258258
}

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/statushandlers/LabelProviderWrapperTest.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2017 IBM Corporation and others.
2+
* Copyright (c) 2009, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -100,13 +100,13 @@ public Image getColumnImage(Object element, int columnIndex) {
100100

101101
@Test
102102
public void testImages(){
103-
StatusAdapter saError = new StatusAdapter(new Status(IStatus.ERROR, "org.eclipse.ui.tests", "errorMessage"));
103+
StatusAdapter saError = new StatusAdapter(Status.error("errorMessage"));
104104
assertEquals(wrapper.getSWTImage(SWT.ICON_ERROR), wrapper.getImage(saError));
105105

106-
StatusAdapter saWarning = new StatusAdapter(new Status(IStatus.WARNING, "org.eclipse.ui.tests", "warningMessage"));
106+
StatusAdapter saWarning = new StatusAdapter(Status.warning("warningMessage"));
107107
assertEquals(wrapper.getSWTImage(SWT.ICON_WARNING), wrapper.getImage(saWarning));
108108

109-
StatusAdapter saInfo = new StatusAdapter(new Status(IStatus.INFO, "org.eclipse.ui.tests", "infoMessage"));
109+
StatusAdapter saInfo = new StatusAdapter(Status.info("infoMessage"));
110110
assertEquals(wrapper.getSWTImage(SWT.ICON_INFORMATION), wrapper.getImage(saInfo));
111111

112112
StatusAdapter cancelOK = new StatusAdapter(new Status(IStatus.CANCEL, "org.eclipse.ui.tests", "cancelMessage"));
@@ -125,7 +125,7 @@ public void testProvidedText_1(){
125125
final String title = "title";
126126
final String message = "errorMessage";
127127

128-
StatusAdapter saError = new StatusAdapter(new Status(IStatus.ERROR, "org.eclipse.ui.tests", message));
128+
StatusAdapter saError = new StatusAdapter(Status.error(message));
129129
saError.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, title);
130130

131131
assertEquals(title, wrapper.getMainMessage(saError));
@@ -144,26 +144,19 @@ public void testDecorating(){
144144
dialogState.put(IStatusDialogConstants.DECORATOR, new ILabelDecorator() {
145145
@Override
146146
public void removeListener(ILabelProviderListener listener) {
147-
// TODO Auto-generated method stub
148-
149147
}
150148

151149
@Override
152150
public boolean isLabelProperty(Object element, String property) {
153-
// TODO Auto-generated method stub
154151
return false;
155152
}
156153

157154
@Override
158155
public void dispose() {
159-
// TODO Auto-generated method stub
160-
161156
}
162157

163158
@Override
164159
public void addListener(ILabelProviderListener listener) {
165-
// TODO Auto-generated method stub
166-
167160
}
168161

169162
@Override
@@ -173,11 +166,10 @@ public String decorateText(String text, Object element) {
173166

174167
@Override
175168
public Image decorateImage(Image image, Object element) {
176-
// TODO Auto-generated method stub
177169
return null;
178170
}
179171
});
180-
StatusAdapter saError = new StatusAdapter(new Status(IStatus.ERROR, "org.eclipse.ui.tests", "message"));
172+
StatusAdapter saError = new StatusAdapter(Status.error("message"));
181173
saError.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, "title");
182174
assertEquals("decoratedtitle", wrapper.getMainMessage(saError));
183175
assertEquals("decoratedmessage", wrapper.getSecondaryMessage(saError));

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/statushandlers/StatusDialogManagerTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2008, 2020 IBM Corporation and others.
2+
* Copyright (c) 2008, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -693,8 +693,7 @@ public void testBug260937(){
693693

694694
@Test
695695
public void testBug276371(){
696-
StatusAdapter bomb = new StatusAdapter(new Status(IStatus.ERROR,
697-
"org.eclipse.ui.tests", "bomb"){
696+
StatusAdapter bomb = new StatusAdapter(new Status(IStatus.ERROR, "org.eclipse.ui.tests", "bomb") {
698697
int i = 0;
699698

700699
@Override
@@ -969,7 +968,7 @@ public void testBug288765() {
969968
selectWidget(StatusDialogUtil.getOkButton());
970969
MultiStatus ms = new MultiStatus("org.eclipse.ui.tests", 0, MESSAGE_1, null);
971970
for (int i = 0; i < 50; i++) {
972-
ms.add(new Status(IStatus.ERROR, "org.eclipse.ui.tests", MESSAGE_2));
971+
ms.add(Status.error(MESSAGE_2));
973972
}
974973
wsdm.addStatusAdapter(new StatusAdapter(ms), false);
975974
shell = StatusDialogUtil.getStatusShell();
@@ -1307,8 +1306,7 @@ private void selectWidget(Widget control) {
13071306
* @return created StatusAdapter
13081307
*/
13091308
private StatusAdapter createStatusAdapter(String message) {
1310-
return new StatusAdapter(new Status(IStatus.ERROR,
1311-
"org.eclipse.ui.tests", message));
1309+
return new StatusAdapter(Status.error(message));
13121310
}
13131311

13141312
/**
@@ -1322,8 +1320,7 @@ private StatusAdapter createStatusAdapter(String message) {
13221320
*/
13231321
private StatusAdapter createStatusAdapter(String message,
13241322
Throwable throwable) {
1325-
return new StatusAdapter(new Status(IStatus.ERROR,
1326-
"org.eclipse.ui.tests", message, throwable));
1323+
return new StatusAdapter(Status.error(message, throwable));
13271324
}
13281325

13291326
/**

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/statushandlers/SupportTrayTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2018 IBM Corporation and others.
2+
* Copyright (c) 2009, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -69,8 +69,7 @@ public void handleEvent(Event event) {
6969
@Test
7070
public void testDefaultSupportProviderEnablement(){
7171
Map<Object, Object> dialogState = new HashMap<>();
72-
Status status = new Status(IStatus.ERROR, "org.eclipse.ui.test",
73-
"Message.", new NullPointerException());
72+
IStatus status = Status.error("Message.", new NullPointerException());
7473
StatusAdapter sa = new StatusAdapter(status);
7574
dialogState.put(IStatusDialogConstants.CURRENT_STATUS_ADAPTER, sa);
7675
SupportTray st = new SupportTray(dialogState, new NullListener());

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/statushandlers/WorkbenchStatusDialogManagerImplTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009 IBM Corporation and others.
2+
* Copyright (c) 2009, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -18,7 +18,6 @@
1818
import static org.junit.Assert.assertFalse;
1919
import static org.junit.Assert.assertTrue;
2020

21-
import org.eclipse.core.runtime.IStatus;
2221
import org.eclipse.core.runtime.Status;
2322
import org.eclipse.jface.resource.JFaceResources;
2423
import org.eclipse.ui.internal.statushandlers.IStatusDialogConstants;
@@ -80,21 +79,21 @@ public void testCheckMasking(){
8079
@Test
8180
public void testCheckRecognizingImmediatePrompting1(){
8281
//no property
83-
StatusAdapter sa = new StatusAdapter(new Status(IStatus.ERROR, "org.eclipse.ui.tests", "message"));
82+
StatusAdapter sa = new StatusAdapter(Status.error("message"));
8483
assertTrue(mgr.shouldPrompt(sa));
8584
}
8685

8786
@Test
8887
public void testCheckRecognizingImmediatePrompting2(){
8988
//property set to false
90-
StatusAdapter sa = new StatusAdapter(new Status(IStatus.ERROR, "org.eclipse.ui.tests", "message"));
89+
StatusAdapter sa = new StatusAdapter(Status.error("message"));
9190
sa.setProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY, Boolean.FALSE);
9291
assertTrue(mgr.shouldPrompt(sa));
9392
}
9493

9594
@Test
9695
public void testCheckRecognizingNonImmediatePrompting(){
97-
StatusAdapter sa = new StatusAdapter(new Status(IStatus.ERROR, "org.eclipse.ui.tests", "message"));
96+
StatusAdapter sa = new StatusAdapter(Status.error("message"));
9897
sa.setProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY, Boolean.TRUE);
9998
assertFalse(mgr.shouldPrompt(sa));
10099
}

0 commit comments

Comments
 (0)