Skip to content
Merged
Show file tree
Hide file tree
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, 2024 Emmanuel Chebbi and others.
* Copyright (c) 2019, 2026 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,17 +14,17 @@
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 static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
Expand All @@ -41,9 +41,9 @@
import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
import org.eclipse.ui.internal.decorators.DecoratorManager;
import org.eclipse.ui.tests.harness.util.DisplayHelper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Tests that FilteredResourcesSelectionDialog selects its initial selection
Expand All @@ -64,7 +64,7 @@ public class ResourceInitialSelectionTest {
private IProject project;


@Before
@BeforeEach
public void doSetUp() throws Exception {
FILES.clear();
createProject();
Expand All @@ -87,7 +87,7 @@ public void testSingleSelectionAndNoInitialSelectionWithInitialPattern() {

List<Object> selected = getSelectedItems(dialog);

assertFalse("One file should be selected by default", selected.isEmpty());
assertFalse(selected.isEmpty(), "One file should be selected by default");
}

/**
Expand All @@ -108,7 +108,7 @@ public void testSingleSelectionAndOneInitialSelectionWithInitialPattern() {

List<Object> selected = getSelectedItems(dialog);

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

/**
Expand All @@ -130,7 +130,7 @@ public void testSingleSelectionAndOneInitialNonExistingSelectionWithInitialPatte

List<Object> selected = getSelectedItems(dialog);

assertTrue("No file should be selected by default", selected.isEmpty());
assertTrue(selected.isEmpty(), "No file should be selected by default");
}

/**
Expand All @@ -150,7 +150,7 @@ public void testSingleSelectionAndOneInitialSelectionWithoutInitialPattern() {

List<Object> selected = getSelectedItems(dialog);

assertTrue("No file should be selected by default", selected.isEmpty());
assertTrue(selected.isEmpty(), "No file should be selected by default");
}

/**
Expand All @@ -172,7 +172,7 @@ public void testSingleSelectionAndOneFilteredSelection() {

List<Object> selected = getSelectedItems(dialog);

assertTrue("No file should be selected by default", selected.isEmpty());
assertTrue(selected.isEmpty(), "No file should be selected by default");
}

/**
Expand All @@ -194,7 +194,7 @@ public void testSingleSelectionAndTwoInitialSelectionsWithInitialPattern() {

List<Object> selected = getSelectedItems(dialog);

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

/**
Expand All @@ -215,7 +215,7 @@ public void testMultiSelectionAndNoInitialSelectionWithInitialPattern() {

List<Object> selected = getSelectedItems(dialog);

assertFalse("One file should be selected by default", selected.isEmpty());
assertFalse(selected.isEmpty(), "One file should be selected by default");
}

/**
Expand All @@ -237,7 +237,7 @@ public void testMultiSelectionAndOneInitialSelectionWithInitialPattern() {

List<Object> selected = getSelectedItems(dialog);

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

/**
Expand All @@ -257,7 +257,7 @@ public void testMultiSelectionAndOneInitialSelectionWithoutInitialPattern() {

List<Object> selected = getSelectedItems(dialog);

assertTrue("No file should be selected by default", selected.isEmpty());
assertTrue(selected.isEmpty(), "No file should be selected by default");
}

/**
Expand All @@ -279,7 +279,7 @@ public void testMultiSelectionAndTwoInitialNonExistingSelectionWithInitialPatter

List<Object> selected = getSelectedItems(dialog);

assertTrue("No file should be selected by default", selected.isEmpty());
assertTrue(selected.isEmpty(), "No file should be selected by default");
}

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

assertTrue("Two files should be selected by default", allInitialElementsAreSelected);
assertTrue(allInitialElementsAreSelected, "Two files should be selected by default");
}

/**
Expand All @@ -328,7 +328,7 @@ public void testMultiSelectionAndTwoInitialSelectionsWithInitialPattern() {
boolean initialElementsAreSelected = selected.containsAll(initialSelection)
&& initialSelection.containsAll(selected);

assertTrue("Two files should be selected by default", initialElementsAreSelected);
assertTrue(initialElementsAreSelected, "Two files should be selected by default");
}

/**
Expand All @@ -354,7 +354,7 @@ public void testMultiSelectionAndTwoInitialFilteredSelections() {
boolean initialElementsAreSelected = selected.containsAll(expectedSelection)
&& expectedSelection.containsAll(selected);

assertTrue("Two files should be selected by default", initialElementsAreSelected);
assertTrue(initialElementsAreSelected, "Two files should be selected by default");
}

private FilteredResourcesSelectionDialog createDialog(boolean multiSelection) {
Expand Down Expand Up @@ -394,34 +394,34 @@ private void createProject() throws CoreException {

for (String fileName : FILE_NAMES) {
DisplayHelper.waitForCondition(display, 1000, () -> project.getFile(fileName).exists());
assertTrue("File was not created", project.getFile(fileName).exists());
assertTrue(project.getFile(fileName).exists(), "File was not created");
}
}

@After
@AfterEach
public void doTearDown() throws Exception {
if (dialog != null) {
dialog.close();
}
if (project != null) {
// Process any pending UI events before cleanup
processUIEvents();

try {
// Wait for decorator jobs to finish
Job.getJobManager().wakeUp(DecoratorManager.FAMILY_DECORATE);
Job.getJobManager().join(DecoratorManager.FAMILY_DECORATE, null);

// Wait for any resource jobs that might be running
Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_REFRESH, null);
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, null);

// Process UI events again after joining jobs
processUIEvents();

// Try to delete with proper progress monitor and retry mechanism
deleteProjectWithRetry(project);

} catch (Exception e) {
// try to get a stacktrace which jobs still has project open so that it can not
// be deleted:
Expand Down Expand Up @@ -495,7 +495,7 @@ private void waitForDialogRefresh() {
private void deleteProjectWithRetry(IProject projectToDelete) throws CoreException {
final int MAX_RETRY = 5;
CoreException lastException = null;

for (int i = 0; i < MAX_RETRY; i++) {
try {
projectToDelete.delete(true, true, new NullProgressMonitor());
Expand All @@ -514,7 +514,7 @@ private void deleteProjectWithRetry(IProject projectToDelete) throws CoreExcepti
}
}
}

// If we get here, all retries failed
if (lastException != null) {
throw lastException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2018 Red Hat Inc. and others.
* Copyright (c) 2017, 2026 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,9 +13,10 @@
*******************************************************************************/
package org.eclipse.ui.tests.dialogs;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand All @@ -35,9 +36,9 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
import org.eclipse.ui.tests.harness.util.DisplayHelper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

private IProject project;

@Before
@BeforeEach
public void doSetUp() throws Exception {
project = ResourcesPlugin.getWorkspace().getRoot()
.getProject(getClass().getName() + "_" + System.currentTimeMillis());
Expand Down Expand Up @@ -269,16 +270,16 @@ public void testBug566858_leadingWhitespace() throws Exception {
}

private void compareStyleRanges(Position[] expected, StyleRange[] actual, String fileName, String fileParentPath) {
assertEquals("Length of StyleRanges is incorrect: " + printStyleRanges(actual), expected.length + 1,
actual.length);
assertEquals(expected.length + 1, actual.length,
"Length of StyleRanges is incorrect: " + printStyleRanges(actual));
int i;
for (i = 0; i < actual.length - 1; i++) {
assertEquals("Start of StyleRange at index " + i + " is incorrect.", expected[i].offset, actual[i].start);
assertEquals("Length of StyleRange at index " + i + " is incorrect.", expected[i].length, actual[i].length);
assertEquals(expected[i].offset, actual[i].start, "Start of StyleRange at index " + i + " is incorrect.");
assertEquals(expected[i].length, actual[i].length, "Length of StyleRange at index " + i + " is incorrect.");
}
assertEquals("Start of file path StyleRange is incorrect.", fileName.length(), actual[i].start);
assertEquals("Length of file path StyleRange at index is incorrect.",
3 + project.getName().length() + fileParentPath.length(), actual[i].length);
assertEquals(fileName.length(), actual[i].start, "Start of file path StyleRange is incorrect.");
assertEquals(3 + project.getName().length() + fileParentPath.length(), actual[i].length,
"Length of file path StyleRange at index is incorrect.");
}

private FilteredResourcesSelectionDialog dialog;
Expand All @@ -304,7 +305,7 @@ protected boolean condition() {
}
}.waitForCondition(shell.getDisplay(), 1000);

assertTrue("File was not created", project.getFile(fileName).exists());
assertTrue(project.getFile(fileName).exists(), "File was not created");
dialog.reloadCache(true, new NullProgressMonitor());

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

@After
@AfterEach
public void doTearDown() throws Exception {
if (dialog != null) {
dialog.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others.
* Copyright (c) 2019, 2026 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.ui.tests.dialogs;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.File;

Expand All @@ -24,10 +26,9 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
import org.eclipse.ui.tests.harness.util.DisplayHelper;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class ResourceSelectionFilteringDialogTest {

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

private IProject project;

@Before
@BeforeEach
public void doSetUp() throws Exception {
project = ResourcesPlugin.getWorkspace().getRoot()
.getProject(getClass().getSimpleName() + System.currentTimeMillis());
Expand All @@ -61,15 +62,15 @@ public void testMatch() throws CoreException {
dialog.setInitialPattern("c/f");
dialog.open();
dialog.refresh();
Assert.assertTrue(DisplayHelper.waitForCondition(dialog.getShell().getDisplay(), 3000,
assertTrue(DisplayHelper.waitForCondition(dialog.getShell().getDisplay(), 3000,
() -> file.equals(dialog.getSelectedItems().getFirstElement())
));
} finally {
dialog.close();
}
}

@After
@AfterEach
public void doTearDown() throws Exception {
project.delete(true, null);
}
Expand Down
Loading