Skip to content

Commit e75fad0

Browse files
committed
Convert genericeditor tests to JUnit 5
1 parent 632ccf5 commit e75fad0

16 files changed

+123
-144
lines changed

tests/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Bundle-Localization: plugin
88
Export-Package: org.eclipse.ui.genericeditor.tests,
99
org.eclipse.ui.genericeditor.tests.contributions
1010
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
11-
org.junit;bundle-version="4.12.0",
1211
org.eclipse.jface;bundle-version="[3.5.0,4.0.0)",
1312
org.eclipse.text;bundle-version="[3.5.0,4.0.0)",
1413
org.eclipse.ui.genericeditor,
@@ -22,7 +21,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
2221
org.eclipse.core.expressions,
2322
org.eclipse.ui.tests.harness;bundle-version="1.4.500",
2423
org.eclipse.test,
25-
junit-jupiter-api
24+
junit-jupiter-api,
25+
org.hamcrest
2626
Bundle-RequiredExecutionEnvironment: JavaSE-17
2727
Eclipse-BundleShape: dir
2828
Bundle-ActivationPolicy: lazy

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AbstratGenericEditorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import java.nio.charset.StandardCharsets;
2121
import java.util.function.Supplier;
2222

23-
import org.junit.After;
24-
import org.junit.Before;
23+
import org.junit.jupiter.api.AfterEach;
24+
import org.junit.jupiter.api.BeforeEach;
2525

2626
import org.eclipse.core.runtime.NullProgressMonitor;
2727

@@ -53,7 +53,7 @@ public class AbstratGenericEditorTest {
5353
* Closes intro, create {@link #project}, create {@link #file} and open {@link #editor}
5454
* @throws Exception ex
5555
*/
56-
@Before
56+
@BeforeEach
5757
public void setUp() throws Exception {
5858
closeIntro();
5959
project = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.currentTimeMillis());
@@ -114,7 +114,7 @@ protected void cleanFileAndEditor() throws Exception {
114114
}
115115
}
116116

117-
@After
117+
@AfterEach
118118
public void tearDown() throws Exception {
119119
cleanFileAndEditor();
120120
if (project != null) {

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AutoEditTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.genericeditor.tests;
1515

16-
import static org.junit.Assert.assertEquals;
1716

18-
import org.junit.Test;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
19+
import org.junit.jupiter.api.Test;
1920

2021
import org.eclipse.swt.custom.StyledText;
2122
import org.eclipse.swt.widgets.Control;

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/BasicEditionTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
*******************************************************************************/
1111
package org.eclipse.ui.genericeditor.tests;
1212

13-
import static org.junit.Assert.assertEquals;
1413

15-
import org.junit.Test;
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
16+
import org.junit.jupiter.api.Test;
1617

1718
import org.eclipse.jface.text.IDocument;
1819
import org.eclipse.jface.text.ITextViewer;

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
import static org.eclipse.ui.genericeditor.tests.contributions.LongRunningBarContentAssistProcessor.LONG_RUNNING_BAR_CONTENT_ASSIST_PROPOSAL;
1818
import static org.hamcrest.CoreMatchers.endsWith;
1919
import static org.hamcrest.MatcherAssert.assertThat;
20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertNotNull;
23-
import static org.junit.Assert.assertNull;
24-
import static org.junit.Assert.assertTrue;
25-
import static org.junit.Assert.fail;
26-
import static org.junit.Assume.assumeFalse;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.assertNull;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
import static org.junit.jupiter.api.Assertions.fail;
2726

2827
import java.util.ArrayList;
2928
import java.util.Arrays;
@@ -36,8 +35,10 @@
3635
import java.util.function.BooleanSupplier;
3736
import java.util.stream.Collectors;
3837

39-
import org.junit.After;
40-
import org.junit.Test;
38+
import org.junit.jupiter.api.AfterEach;
39+
import org.junit.jupiter.api.Test;
40+
import org.junit.jupiter.api.condition.DisabledOnOs;
41+
import org.junit.jupiter.api.condition.OS;
4142
import org.osgi.framework.Bundle;
4243
import org.osgi.framework.BundleContext;
4344
import org.osgi.framework.FrameworkUtil;
@@ -60,8 +61,6 @@
6061
import org.eclipse.core.runtime.IStatus;
6162
import org.eclipse.core.runtime.Platform;
6263

63-
import org.eclipse.jface.util.Util;
64-
6564
import org.eclipse.jface.text.ITextSelection;
6665
import org.eclipse.jface.text.ITextViewer;
6766
import org.eclipse.jface.text.contentassist.ICompletionProposal;
@@ -85,14 +84,16 @@ public class CompletionTest extends AbstratGenericEditorTest {
8584
private Shell completionShell;
8685

8786
@Test
87+
@DisabledOnOs(value = OS.MAC, disabledReason = "test fails on Mac, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/906")
8888
public void testCompletion() throws Exception {
89-
assumeFalse("test fails on Mac, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/906", Util.isMac());
9089
editor.selectAndReveal(3, 0);
91-
this.completionShell= openConentAssist();
90+
this.completionShell = openConentAssist();
9291
final Table completionProposalList = findCompletionSelectionControl(completionShell);
9392
checkCompletionContent(completionProposalList);
94-
// TODO find a way to actually trigger completion and verify result against Editor content
95-
// Assert.assertEquals("Completion didn't complete", "bars are good for a beer.", ((StyledText)editor.getAdapter(Control.class)).getText());
93+
// TODO find a way to actually trigger completion and verify result against
94+
// Editor content
95+
// Assert.assertEquals("Completion didn't complete", "bars are good for a
96+
// beer.", ((StyledText)editor.getAdapter(Control.class)).getText());
9697
}
9798

9899
@Test
@@ -103,13 +104,13 @@ public void testDefaultContentAssistBug570488() throws Exception {
103104
createAndOpenFile("Bug570488.txt", "bar 'bar'");
104105
openConentAssist(false);
105106
DisplayHelper.runEventLoop(Display.getCurrent(), 0);
106-
assertFalse("There are errors in the log", listener.messages.stream().anyMatch(s -> s.matches(IStatus.ERROR)));
107+
assertFalse(listener.messages.stream().anyMatch(s -> s.matches(IStatus.ERROR)), "There are errors in the log");
107108
log.removeLogListener(listener);
108109
}
109110

110111
@Test
112+
@DisabledOnOs(value = OS.MAC, disabledReason = "test fails on Mac, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/906")
111113
public void testCompletionService() throws Exception {
112-
assumeFalse("test fails on Mac, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/906", Util.isMac());
113114
Bundle bundle= FrameworkUtil.getBundle(CompletionTest.class);
114115
assertNotNull(bundle);
115116
BundleContext bundleContext= bundle.getBundleContext();
@@ -122,13 +123,13 @@ public void testCompletionService() throws Exception {
122123
this.completionShell= openConentAssist();
123124
final Table completionProposalList= findCompletionSelectionControl(completionShell);
124125
checkCompletionContent(completionProposalList);
125-
assertTrue("Service was not called!", service.called);
126+
assertTrue(service.called, "Service was not called!");
126127
registration.unregister();
127128
}
128129

129130
@Test
131+
@DisabledOnOs(value = OS.MAC, disabledReason = "test fails on Mac, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/906")
130132
public void testCompletionUsingViewerSelection() throws Exception {
131-
assumeFalse("test fails on Mac, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/906", Util.isMac());
132133
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("abc");
133134
editor.selectAndReveal(0, 3);
134135
this.completionShell= openConentAssist();
@@ -138,13 +139,10 @@ public void testCompletionUsingViewerSelection() throws Exception {
138139
}
139140

140141
private static void waitForProposalRelatedCondition(String errorMessage, Table completionProposalList, BooleanSupplier condition, int timeoutInMsec) {
141-
assertTrue(errorMessage, new DisplayHelper() {
142-
@Override
143-
protected boolean condition() {
144-
assertFalse("Completion proposal list was unexpectedly disposed", completionProposalList.isDisposed());
145-
return condition.getAsBoolean();
146-
}
147-
}.waitForCondition(completionProposalList.getDisplay(), timeoutInMsec));
142+
assertTrue(DisplayHelper.waitForCondition(completionProposalList.getDisplay(), timeoutInMsec, () -> {
143+
assertFalse(completionProposalList.isDisposed(), "Completion proposal list was unexpectedly disposed");
144+
return condition.getAsBoolean();
145+
}), errorMessage);
148146
}
149147

150148
@Test
@@ -153,7 +151,7 @@ public void testEnabledWhenCompletion() throws Exception {
153151
EnabledPropertyTester.setEnabled(false);
154152
createAndOpenFile("enabledWhen.txt", "bar 'bar'");
155153
editor.selectAndReveal(3, 0);
156-
assertNull("A new shell was found", openConentAssist(false));
154+
assertNull(openConentAssist(false), "A new shell was found");
157155
cleanFileAndEditor();
158156

159157
// Confirm that when enabled, a completion shell is present
@@ -187,8 +185,8 @@ private void checkCompletionContent(final Table completionProposalList) {
187185
// should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
188186
waitForProposalRelatedCondition("Proposal list did not show two initial items", completionProposalList,
189187
() -> completionProposalList.getItemCount() == 2, 200);
190-
assertTrue("Missing computing info entry", isComputingInfoEntry(completionProposalList.getItem(0)));
191-
assertTrue("Missing computing info entry in proposal list", isComputingInfoEntry(completionProposalList.getItem(0)));
188+
assertTrue(isComputingInfoEntry(completionProposalList.getItem(0)), "Missing computing info entry");
189+
assertTrue(isComputingInfoEntry(completionProposalList.getItem(0)), "Missing computing info entry in proposal list");
192190
final TableItem initialProposalItem = completionProposalList.getItem(1);
193191
final String initialProposalString = ((ICompletionProposal)initialProposalItem.getData()).getDisplayString();
194192
assertThat("Unexpected initial proposal item",
@@ -205,7 +203,7 @@ private void checkCompletionContent(final Table completionProposalList) {
205203
assertThat("Unexpected first proposal item", BAR_CONTENT_ASSIST_PROPOSAL, endsWith(firstCompletionProposalText));
206204
assertThat("Unexpected second proposal item", LONG_RUNNING_BAR_CONTENT_ASSIST_PROPOSAL, endsWith(secondCompletionProposalText));
207205
String selectedProposalString = ((ICompletionProposal)completionProposalList.getSelection()[0].getData()).getDisplayString();
208-
assertEquals("Addition of completion proposal should keep selection", initialProposalString, selectedProposalString);
206+
assertEquals(initialProposalString, selectedProposalString, "Addition of completion proposal should keep selection");
209207
}
210208

211209
private static boolean isComputingInfoEntry(TableItem item) {
@@ -218,33 +216,33 @@ public static Shell findNewShell(Set<Shell> beforeShells, Display display, boole
218216
.filter(shell -> !beforeShells.contains(shell))
219217
.toArray(Shell[]::new);
220218
if (expectShell) {
221-
assertEquals("No new shell found", 1, afterShells.length);
219+
assertEquals(1, afterShells.length, "No new shell found");
222220
}
223221
return afterShells.length > 0 ? afterShells[0] : null;
224222
}
225223

226224
@Test
225+
@DisabledOnOs(value = OS.MAC, disabledReason = "test fails on Mac, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/906")
227226
public void testCompletionFreeze_bug521484() throws Exception {
228-
assumeFalse("test fails on Mac, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/906", Util.isMac());
229227
editor.selectAndReveal(3, 0);
230228
this.completionShell=openConentAssist();
231229
final Table completionProposalList = findCompletionSelectionControl(this.completionShell);
232230
// should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
233231
waitForProposalRelatedCondition("Proposal list did not show two items", completionProposalList,
234232
() -> completionProposalList.getItemCount() == 2, 200);
235-
assertTrue("Missing computing info entry", isComputingInfoEntry(completionProposalList.getItem(0)));
233+
assertTrue(isComputingInfoEntry(completionProposalList.getItem(0)), "Missing computing info entry");
236234
// Some processors are long running, moving cursor can cause freeze (bug 521484)
237235
// asynchronous
238236
long timestamp = System.currentTimeMillis();
239237
emulatePressLeftArrowKey();
240238
DisplayHelper.sleep(editor.getSite().getShell().getDisplay(), 200); //give time to process events
241239
long processingDuration = System.currentTimeMillis() - timestamp;
242-
assertTrue("UI Thread frozen for " + processingDuration + "ms", processingDuration < LongRunningBarContentAssistProcessor.DELAY);
240+
assertTrue(processingDuration < LongRunningBarContentAssistProcessor.DELAY, "UI Thread frozen for " + processingDuration + "ms");
243241
}
244242

245243
@Test
244+
@DisabledOnOs(value = OS.MAC, disabledReason = "test fails on Mac, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/906")
246245
public void testMoveCaretBackUsesAllProcessors_bug522255() throws Exception {
247-
assumeFalse("test fails on Mac, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/906", Util.isMac());
248246
testCompletion();
249247
emulatePressLeftArrowKey();
250248
final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
@@ -280,7 +278,7 @@ public static Table findCompletionSelectionControl(Widget control) {
280278
return null;
281279
}
282280

283-
@After
281+
@AfterEach
284282
public void closeShell() {
285283
if (this.completionShell != null && !completionShell.isDisposed()) {
286284
completionShell.close();

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/ContextInfoTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
import static org.eclipse.ui.genericeditor.tests.contributions.BarContentAssistProcessor.BAR_CONTENT_ASSIST_PROPOSAL;
1717
import static org.eclipse.ui.tests.harness.util.DisplayHelper.runEventLoop;
18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import java.util.Arrays;
2222
import java.util.Set;
2323
import java.util.stream.Collectors;
2424

25-
import org.junit.After;
26-
import org.junit.Test;
25+
import org.junit.jupiter.api.AfterEach;
26+
import org.junit.jupiter.api.Test;
2727

2828
import org.eclipse.swt.custom.StyledText;
2929
import org.eclipse.swt.widgets.Control;
@@ -62,15 +62,15 @@ public void testContextInfo() throws Exception {
6262
action.update();
6363
action.run();
6464
this.completionShell= findNewShell(beforeShells);
65-
assertEquals("idx= 0", getInfoText(this.completionShell));
65+
assertEquals(getInfoText(this.completionShell), "idx= 0");
6666

6767
editor.selectAndReveal(8, 0);
6868
runEventLoop(PlatformUI.getWorkbench().getDisplay(),0);
6969

7070
action.update();
7171
action.run();
7272
this.completionShell= findNewShell(beforeShells);
73-
assertEquals("idx= 1", getInfoText(this.completionShell));
73+
assertEquals(getInfoText(this.completionShell), "idx= 1");
7474
}
7575

7676
@Test
@@ -110,7 +110,7 @@ private Shell findNewShell(Set<Shell> beforeShells) {
110110
runEventLoop(PlatformUI.getWorkbench().getDisplay(),1000);
111111
}
112112
afterShells= findNewShells(beforeShells);
113-
assertEquals("No new shell found", 1, afterShells.length);
113+
assertEquals(1, afterShells.length, "No new shell found");
114114
return afterShells[0];
115115
}
116116

@@ -136,7 +136,7 @@ private String getInfoText(final Shell shell) {
136136
return null;
137137
}
138138

139-
@After
139+
@AfterEach
140140
public void closeShell() {
141141
if (this.completionShell != null && !completionShell.isDisposed()) {
142142
completionShell.close();

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/DoubleClickTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
import static org.eclipse.ui.tests.harness.util.DisplayHelper.runEventLoop;
1616
import static org.eclipse.ui.tests.harness.util.DisplayHelper.waitForCondition;
17-
import static org.junit.Assert.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

2121
import org.eclipse.swt.SWT;
2222
import org.eclipse.swt.custom.StyledText;

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/EditorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.genericeditor.tests;
1515

16-
import static org.junit.Assert.assertFalse;
17-
import static org.junit.Assert.assertTrue;
16+
import static org.junit.jupiter.api.Assertions.assertFalse;
17+
import static org.junit.jupiter.api.Assertions.assertTrue;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

2121
import org.eclipse.swt.custom.StyledText;
2222
import org.eclipse.swt.widgets.Control;

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/FoldingTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
package org.eclipse.ui.genericeditor.tests;
1515

16-
import static org.junit.Assert.assertTrue;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
1717

1818
import java.util.ArrayList;
1919
import java.util.Arrays;
@@ -22,7 +22,7 @@
2222
import java.util.List;
2323
import java.util.Objects;
2424

25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

2727
import org.eclipse.core.commands.Command;
2828

@@ -32,10 +32,10 @@
3232
import org.eclipse.jface.text.source.IAnnotationModel;
3333
import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
3434
import org.eclipse.jface.text.source.projection.ProjectionViewer;
35-
import org.eclipse.ui.tests.harness.util.DisplayHelper;
3635

3736
import org.eclipse.ui.commands.ICommandService;
3837
import org.eclipse.ui.genericeditor.tests.contributions.EnabledPropertyTester;
38+
import org.eclipse.ui.tests.harness.util.DisplayHelper;
3939

4040
import org.eclipse.ui.editors.text.IFoldingCommandIds;
4141

0 commit comments

Comments
 (0)