Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Emmanuel Chebbi
* Copyright (c) 2019, 2024 Emmanuel Chebbi and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,9 +14,10 @@
package org.eclipse.ui.tests.dialogs;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -40,43 +41,31 @@
import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
import org.eclipse.ui.internal.decorators.DecoratorManager;
import org.eclipse.ui.tests.harness.util.DisplayHelper;
import org.eclipse.ui.tests.harness.util.UITestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
* Tests that FilteredResourcesSelectionDialog selects its initial selection
* when opened. See also bug 214491.
*
* @since 3.14
*/
@RunWith(JUnit4.class)
public class ResourceInitialSelectionTest extends UITestCase {
public class ResourceInitialSelectionTest {

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

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

/** Used to fill created files with an empty content. */
private static InputStream stream = new ByteArrayInputStream(new byte[0]);

private FilteredResourcesSelectionDialog dialog;

private IProject project;

/**
* Constructs a new instance of <code>ResourceItemInitialSelectionTest</code>.
*/
public ResourceInitialSelectionTest() {
super(ResourceInitialSelectionTest.class.getSimpleName());
}

@Override
protected void doSetUp() throws Exception {
super.doSetUp();
@Before
public void doSetUp() throws Exception {
FILES.clear();
createProject();
}
Expand Down Expand Up @@ -355,7 +344,7 @@ private void createProject() throws CoreException {

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

for (String fileName : FILE_NAMES) {
new DisplayHelper() {
@Override
protected boolean condition() {
return project.getFile(fileName).exists();
}
}.waitForCondition(shell.getDisplay(), 1000);

DisplayHelper.waitForCondition(shell.getDisplay(), 1000, () -> project.getFile(fileName).exists());
assertTrue("File was not created", project.getFile(fileName).exists());
}
}

@Override
protected void doTearDown() throws Exception {
@After
public void doTearDown() throws Exception {
if (dialog != null) {
dialog.close();
}
Expand All @@ -397,6 +380,5 @@ protected void doTearDown() throws Exception {
throw e;
}
}
super.doTearDown();
}
}
Loading