Skip to content

Commit da48e88

Browse files
committed
Convert FilteredResourcesSelectionDialogTestSuite to JUnit 5
Unstable tests as seen in #3712
1 parent dcce9be commit da48e88

3 files changed

Lines changed: 58 additions & 56 deletions

File tree

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019, 2024 Emmanuel Chebbi and others.
2+
* Copyright (c) 2019, 2026 Emmanuel Chebbi and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,17 +14,17 @@
1414
package org.eclipse.ui.tests.dialogs;
1515

1616
import static java.util.Arrays.asList;
17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertFalse;
19-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertFalse;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import java.util.Arrays;
2222
import java.util.HashMap;
2323
import java.util.HashSet;
2424
import java.util.List;
2525
import java.util.Map;
26-
import java.util.Set;
2726
import java.util.Map.Entry;
27+
import java.util.Set;
2828

2929
import org.eclipse.core.resources.IFile;
3030
import org.eclipse.core.resources.IProject;
@@ -41,9 +41,9 @@
4141
import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
4242
import org.eclipse.ui.internal.decorators.DecoratorManager;
4343
import org.eclipse.ui.tests.harness.util.DisplayHelper;
44-
import org.junit.After;
45-
import org.junit.Before;
46-
import org.junit.Test;
44+
import org.junit.jupiter.api.AfterEach;
45+
import org.junit.jupiter.api.BeforeEach;
46+
import org.junit.jupiter.api.Test;
4747

4848
/**
4949
* Tests that FilteredResourcesSelectionDialog selects its initial selection
@@ -64,7 +64,7 @@ public class ResourceInitialSelectionTest {
6464
private IProject project;
6565

6666

67-
@Before
67+
@BeforeEach
6868
public void doSetUp() throws Exception {
6969
FILES.clear();
7070
createProject();
@@ -87,7 +87,7 @@ public void testSingleSelectionAndNoInitialSelectionWithInitialPattern() {
8787

8888
List<Object> selected = getSelectedItems(dialog);
8989

90-
assertFalse("One file should be selected by default", selected.isEmpty());
90+
assertFalse(selected.isEmpty(), "One file should be selected by default");
9191
}
9292

9393
/**
@@ -108,7 +108,7 @@ public void testSingleSelectionAndOneInitialSelectionWithInitialPattern() {
108108

109109
List<Object> selected = getSelectedItems(dialog);
110110

111-
assertEquals("One file should be selected by default", asList(FILES.get("foo.txt")), selected);
111+
assertEquals(asList(FILES.get("foo.txt")), selected, "One file should be selected by default");
112112
}
113113

114114
/**
@@ -130,7 +130,7 @@ public void testSingleSelectionAndOneInitialNonExistingSelectionWithInitialPatte
130130

131131
List<Object> selected = getSelectedItems(dialog);
132132

133-
assertTrue("No file should be selected by default", selected.isEmpty());
133+
assertTrue(selected.isEmpty(), "No file should be selected by default");
134134
}
135135

136136
/**
@@ -150,7 +150,7 @@ public void testSingleSelectionAndOneInitialSelectionWithoutInitialPattern() {
150150

151151
List<Object> selected = getSelectedItems(dialog);
152152

153-
assertTrue("No file should be selected by default", selected.isEmpty());
153+
assertTrue(selected.isEmpty(), "No file should be selected by default");
154154
}
155155

156156
/**
@@ -172,7 +172,7 @@ public void testSingleSelectionAndOneFilteredSelection() {
172172

173173
List<Object> selected = getSelectedItems(dialog);
174174

175-
assertTrue("No file should be selected by default", selected.isEmpty());
175+
assertTrue(selected.isEmpty(), "No file should be selected by default");
176176
}
177177

178178
/**
@@ -194,7 +194,7 @@ public void testSingleSelectionAndTwoInitialSelectionsWithInitialPattern() {
194194

195195
List<Object> selected = getSelectedItems(dialog);
196196

197-
assertEquals("The first file should be selected by default", asList(FILES.get("foo.txt")), selected);
197+
assertEquals(asList(FILES.get("foo.txt")), selected, "The first file should be selected by default");
198198
}
199199

200200
/**
@@ -215,7 +215,7 @@ public void testMultiSelectionAndNoInitialSelectionWithInitialPattern() {
215215

216216
List<Object> selected = getSelectedItems(dialog);
217217

218-
assertFalse("One file should be selected by default", selected.isEmpty());
218+
assertFalse(selected.isEmpty(), "One file should be selected by default");
219219
}
220220

221221
/**
@@ -237,7 +237,7 @@ public void testMultiSelectionAndOneInitialSelectionWithInitialPattern() {
237237

238238
List<Object> selected = getSelectedItems(dialog);
239239

240-
assertEquals("One file should be selected by default", asList(FILES.get("foo.txt")), selected);
240+
assertEquals(asList(FILES.get("foo.txt")), selected, "One file should be selected by default");
241241
}
242242

243243
/**
@@ -257,7 +257,7 @@ public void testMultiSelectionAndOneInitialSelectionWithoutInitialPattern() {
257257

258258
List<Object> selected = getSelectedItems(dialog);
259259

260-
assertTrue("No file should be selected by default", selected.isEmpty());
260+
assertTrue(selected.isEmpty(), "No file should be selected by default");
261261
}
262262

263263
/**
@@ -279,7 +279,7 @@ public void testMultiSelectionAndTwoInitialNonExistingSelectionWithInitialPatter
279279

280280
List<Object> selected = getSelectedItems(dialog);
281281

282-
assertTrue("No file should be selected by default", selected.isEmpty());
282+
assertTrue(selected.isEmpty(), "No file should be selected by default");
283283
}
284284

285285
/**
@@ -303,7 +303,7 @@ public void testMultiSelectionAndSomeInitialNonExistingSelectionWithInitialPatte
303303
Set<IFile> expectedSelection = new HashSet<>(asList(FILES.get("bar.txt"), FILES.get("foofoo")));
304304
boolean allInitialElementsAreSelected = expectedSelection.equals(new HashSet<>(selected));
305305

306-
assertTrue("Two files should be selected by default", allInitialElementsAreSelected);
306+
assertTrue(allInitialElementsAreSelected, "Two files should be selected by default");
307307
}
308308

309309
/**
@@ -328,7 +328,7 @@ public void testMultiSelectionAndTwoInitialSelectionsWithInitialPattern() {
328328
boolean initialElementsAreSelected = selected.containsAll(initialSelection)
329329
&& initialSelection.containsAll(selected);
330330

331-
assertTrue("Two files should be selected by default", initialElementsAreSelected);
331+
assertTrue(initialElementsAreSelected, "Two files should be selected by default");
332332
}
333333

334334
/**
@@ -354,7 +354,7 @@ public void testMultiSelectionAndTwoInitialFilteredSelections() {
354354
boolean initialElementsAreSelected = selected.containsAll(expectedSelection)
355355
&& expectedSelection.containsAll(selected);
356356

357-
assertTrue("Two files should be selected by default", initialElementsAreSelected);
357+
assertTrue(initialElementsAreSelected, "Two files should be selected by default");
358358
}
359359

360360
private FilteredResourcesSelectionDialog createDialog(boolean multiSelection) {
@@ -394,34 +394,34 @@ private void createProject() throws CoreException {
394394

395395
for (String fileName : FILE_NAMES) {
396396
DisplayHelper.waitForCondition(display, 1000, () -> project.getFile(fileName).exists());
397-
assertTrue("File was not created", project.getFile(fileName).exists());
397+
assertTrue(project.getFile(fileName).exists(), "File was not created");
398398
}
399399
}
400400

401-
@After
401+
@AfterEach
402402
public void doTearDown() throws Exception {
403403
if (dialog != null) {
404404
dialog.close();
405405
}
406406
if (project != null) {
407407
// Process any pending UI events before cleanup
408408
processUIEvents();
409-
409+
410410
try {
411411
// Wait for decorator jobs to finish
412412
Job.getJobManager().wakeUp(DecoratorManager.FAMILY_DECORATE);
413413
Job.getJobManager().join(DecoratorManager.FAMILY_DECORATE, null);
414-
414+
415415
// Wait for any resource jobs that might be running
416416
Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_REFRESH, null);
417417
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, null);
418-
418+
419419
// Process UI events again after joining jobs
420420
processUIEvents();
421-
421+
422422
// Try to delete with proper progress monitor and retry mechanism
423423
deleteProjectWithRetry(project);
424-
424+
425425
} catch (Exception e) {
426426
// try to get a stacktrace which jobs still has project open so that it can not
427427
// be deleted:
@@ -495,7 +495,7 @@ private void waitForDialogRefresh() {
495495
private void deleteProjectWithRetry(IProject projectToDelete) throws CoreException {
496496
final int MAX_RETRY = 5;
497497
CoreException lastException = null;
498-
498+
499499
for (int i = 0; i < MAX_RETRY; i++) {
500500
try {
501501
projectToDelete.delete(true, true, new NullProgressMonitor());
@@ -514,7 +514,7 @@ private void deleteProjectWithRetry(IProject projectToDelete) throws CoreExcepti
514514
}
515515
}
516516
}
517-
517+
518518
// If we get here, all retries failed
519519
if (lastException != null) {
520520
throw lastException;

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2018 Red Hat Inc. and others.
2+
* Copyright (c) 2017, 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
@@ -13,9 +13,10 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.tests.dialogs;
1515

16-
import static org.junit.Assert.assertEquals;
17-
import static org.junit.Assert.assertTrue;
18-
import static org.junit.Assert.fail;
16+
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.fail;
1920

2021
import java.io.ByteArrayInputStream;
2122
import java.io.InputStream;
@@ -35,9 +36,9 @@
3536
import org.eclipse.ui.PlatformUI;
3637
import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
3738
import org.eclipse.ui.tests.harness.util.DisplayHelper;
38-
import org.junit.After;
39-
import org.junit.Before;
40-
import org.junit.Test;
39+
import org.junit.jupiter.api.AfterEach;
40+
import org.junit.jupiter.api.BeforeEach;
41+
import org.junit.jupiter.api.Test;
4142

4243
/**
4344
* Tests that resources are highlighted to match user search input. See Bug
@@ -49,7 +50,7 @@ public class ResourceItemLabelTest {
4950

5051
private IProject project;
5152

52-
@Before
53+
@BeforeEach
5354
public void doSetUp() throws Exception {
5455
project = ResourcesPlugin.getWorkspace().getRoot()
5556
.getProject(getClass().getName() + "_" + System.currentTimeMillis());
@@ -269,16 +270,16 @@ public void testBug566858_leadingWhitespace() throws Exception {
269270
}
270271

271272
private void compareStyleRanges(Position[] expected, StyleRange[] actual, String fileName, String fileParentPath) {
272-
assertEquals("Length of StyleRanges is incorrect: " + printStyleRanges(actual), expected.length + 1,
273-
actual.length);
273+
assertEquals(expected.length + 1, actual.length,
274+
"Length of StyleRanges is incorrect: " + printStyleRanges(actual));
274275
int i;
275276
for (i = 0; i < actual.length - 1; i++) {
276-
assertEquals("Start of StyleRange at index " + i + " is incorrect.", expected[i].offset, actual[i].start);
277-
assertEquals("Length of StyleRange at index " + i + " is incorrect.", expected[i].length, actual[i].length);
277+
assertEquals(expected[i].offset, actual[i].start, "Start of StyleRange at index " + i + " is incorrect.");
278+
assertEquals(expected[i].length, actual[i].length, "Length of StyleRange at index " + i + " is incorrect.");
278279
}
279-
assertEquals("Start of file path StyleRange is incorrect.", fileName.length(), actual[i].start);
280-
assertEquals("Length of file path StyleRange at index is incorrect.",
281-
3 + project.getName().length() + fileParentPath.length(), actual[i].length);
280+
assertEquals(fileName.length(), actual[i].start, "Start of file path StyleRange is incorrect.");
281+
assertEquals(3 + project.getName().length() + fileParentPath.length(), actual[i].length,
282+
"Length of file path StyleRange at index is incorrect.");
282283
}
283284

284285
private FilteredResourcesSelectionDialog dialog;
@@ -304,7 +305,7 @@ protected boolean condition() {
304305
}
305306
}.waitForCondition(shell.getDisplay(), 1000);
306307

307-
assertTrue("File was not created", project.getFile(fileName).exists());
308+
assertTrue(project.getFile(fileName).exists(), "File was not created");
308309
dialog.reloadCache(true, new NullProgressMonitor());
309310

310311
((Text) dialog.getPatternControl()).setText(searchString);
@@ -350,7 +351,7 @@ private String printStyleRanges(StyleRange[] styleRanges) {
350351
return builder.toString();
351352
}
352353

353-
@After
354+
@AfterEach
354355
public void doTearDown() throws Exception {
355356
if (dialog != null) {
356357
dialog.close();

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 Red Hat Inc. and others.
2+
* Copyright (c) 2019, 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
@@ -10,6 +10,8 @@
1010
*******************************************************************************/
1111
package org.eclipse.ui.tests.dialogs;
1212

13+
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
1315
import java.io.ByteArrayInputStream;
1416
import java.io.File;
1517

@@ -24,10 +26,9 @@
2426
import org.eclipse.ui.PlatformUI;
2527
import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
2628
import org.eclipse.ui.tests.harness.util.DisplayHelper;
27-
import org.junit.After;
28-
import org.junit.Assert;
29-
import org.junit.Before;
30-
import org.junit.Test;
29+
import org.junit.jupiter.api.AfterEach;
30+
import org.junit.jupiter.api.BeforeEach;
31+
import org.junit.jupiter.api.Test;
3132

3233
public class ResourceSelectionFilteringDialogTest {
3334

@@ -41,7 +42,7 @@ private static SeeThroughFilteredResourcesSelectionDialog createDialog() {
4142

4243
private IProject project;
4344

44-
@Before
45+
@BeforeEach
4546
public void doSetUp() throws Exception {
4647
project = ResourcesPlugin.getWorkspace().getRoot()
4748
.getProject(getClass().getSimpleName() + System.currentTimeMillis());
@@ -61,15 +62,15 @@ public void testMatch() throws CoreException {
6162
dialog.setInitialPattern("c/f");
6263
dialog.open();
6364
dialog.refresh();
64-
Assert.assertTrue(DisplayHelper.waitForCondition(dialog.getShell().getDisplay(), 3000,
65+
assertTrue(DisplayHelper.waitForCondition(dialog.getShell().getDisplay(), 3000,
6566
() -> file.equals(dialog.getSelectedItems().getFirstElement())
6667
));
6768
} finally {
6869
dialog.close();
6970
}
7071
}
7172

72-
@After
73+
@AfterEach
7374
public void doTearDown() throws Exception {
7475
project.delete(true, null);
7576
}

0 commit comments

Comments
 (0)