Skip to content

Commit 98da4d9

Browse files
committed
Simplify ResourceInitialSelectionTest
Make it plain JUnit test. Simplify DisplayHelper usage to remove one anonymous class file and have lambda instead.
1 parent ae9e870 commit 98da4d9

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

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

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 Emmanuel Chebbi
2+
* Copyright (c) 2019, 2024 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,9 +14,10 @@
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;
1720

18-
import java.io.ByteArrayInputStream;
19-
import java.io.InputStream;
2021
import java.util.Arrays;
2122
import java.util.HashMap;
2223
import java.util.HashSet;
@@ -40,43 +41,31 @@
4041
import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
4142
import org.eclipse.ui.internal.decorators.DecoratorManager;
4243
import org.eclipse.ui.tests.harness.util.DisplayHelper;
43-
import org.eclipse.ui.tests.harness.util.UITestCase;
44+
import org.junit.After;
45+
import org.junit.Before;
4446
import org.junit.Test;
45-
import org.junit.runner.RunWith;
46-
import org.junit.runners.JUnit4;
4747

4848
/**
4949
* Tests that FilteredResourcesSelectionDialog selects its initial selection
5050
* when opened. See also bug 214491.
5151
*
5252
* @since 3.14
5353
*/
54-
@RunWith(JUnit4.class)
55-
public class ResourceInitialSelectionTest extends UITestCase {
54+
public class ResourceInitialSelectionTest {
5655

5756
/** The names of the files created within the test project. */
5857
private final static List<String> FILE_NAMES = asList("foo.txt", "bar.txt", "foofoo");
5958

6059
/** The test files stored by name. */
6160
private final static Map<String, IFile> FILES = new HashMap<>();
6261

63-
/** Used to fill created files with an empty content. */
64-
private static InputStream stream = new ByteArrayInputStream(new byte[0]);
65-
6662
private FilteredResourcesSelectionDialog dialog;
6763

6864
private IProject project;
6965

70-
/**
71-
* Constructs a new instance of <code>ResourceItemInitialSelectionTest</code>.
72-
*/
73-
public ResourceInitialSelectionTest() {
74-
super(ResourceInitialSelectionTest.class.getSimpleName());
75-
}
7666

77-
@Override
78-
protected void doSetUp() throws Exception {
79-
super.doSetUp();
67+
@Before
68+
public void doSetUp() throws Exception {
8069
FILES.clear();
8170
createProject();
8271
}
@@ -355,7 +344,7 @@ private void createProject() throws CoreException {
355344

356345
for (String fileName : FILE_NAMES) {
357346
IFile file = project.getFile(fileName);
358-
file.create(stream, true, new NullProgressMonitor());
347+
file.create(new byte[0], true, false, new NullProgressMonitor());
359348
FILES.put(fileName, file);
360349
}
361350
project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
@@ -365,19 +354,13 @@ private void createProject() throws CoreException {
365354
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
366355

367356
for (String fileName : FILE_NAMES) {
368-
new DisplayHelper() {
369-
@Override
370-
protected boolean condition() {
371-
return project.getFile(fileName).exists();
372-
}
373-
}.waitForCondition(shell.getDisplay(), 1000);
374-
357+
DisplayHelper.waitForCondition(shell.getDisplay(), 1000, () -> project.getFile(fileName).exists());
375358
assertTrue("File was not created", project.getFile(fileName).exists());
376359
}
377360
}
378361

379-
@Override
380-
protected void doTearDown() throws Exception {
362+
@After
363+
public void doTearDown() throws Exception {
381364
if (dialog != null) {
382365
dialog.close();
383366
}
@@ -397,6 +380,5 @@ protected void doTearDown() throws Exception {
397380
throw e;
398381
}
399382
}
400-
super.doTearDown();
401383
}
402384
}

0 commit comments

Comments
 (0)