From 04c9a411cf528522d6517079ff00dedb9ef2b5b5 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Tue, 19 May 2026 10:07:05 +0200 Subject: [PATCH] Revert "Migrate QuickAccessDialogTest to JUnit 5" This reverts commit 92e6244ea8c076106de527b7d22e35575119b5d7. --- .../quickaccess/QuickAccessDialogTest.java | 127 +++++++++--------- 1 file changed, 64 insertions(+), 63 deletions(-) diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java index 7669a624305..a77b6c6d6a0 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java @@ -17,9 +17,9 @@ import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow; import static org.eclipse.ui.tests.harness.util.UITestUtil.processEventsUntil; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; import java.io.File; import java.util.Arrays; @@ -47,18 +47,17 @@ import org.eclipse.ui.ide.IDE; import org.eclipse.ui.internal.quickaccess.QuickAccessDialog; import org.eclipse.ui.internal.quickaccess.QuickAccessMessages; -import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension; +import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule; import org.eclipse.ui.tests.harness.util.DisplayHelper; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; /** * Tests the quick access UI * @since 3.4 */ -@ExtendWith(CloseTestWindowsExtension.class) public class QuickAccessDialogTest { private class TestQuickAccessDialog extends QuickAccessDialog { @@ -73,6 +72,9 @@ protected IDialogSettings getDialogSettings() { } } + @Rule + public CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule(); + private static final int TIMEOUT = 5000; // As defined in QuickAccessDialog and in SearchField private static final int MAXIMUM_NUMBER_OF_ELEMENTS = 60; @@ -82,7 +84,7 @@ protected IDialogSettings getDialogSettings() { private IWorkbenchWindow activeWorkbenchWindow; - @BeforeEach + @Before public void setUp() throws Exception { Arrays.stream(Display.getDefault().getShells()).filter(isQuickAccessShell).forEach(Shell::close); dialogSettings = new DialogSettings("QuickAccessDialogTest" + System.currentTimeMillis()); @@ -97,7 +99,7 @@ static Optional findQuickAccessDialog() { .map(QuickAccessDialog.class::cast); } - @AfterEach + @After public void tearDown() throws Exception { Arrays.stream(Display.getDefault().getShells()).filter(isQuickAccessShell) .forEach(Shell::close); @@ -128,24 +130,23 @@ public void testTextFilter(){ dialog.open(); Text text = dialog.getQuickAccessContents().getFilterText(); Table table = dialog.getQuickAccessContents().getTable(); - assertTrue(text.getText().isEmpty(), "Quick access filter should be empty"); - assertEquals(0, table.getItemCount(), "Quick access table should be empty"); + assertTrue("Quick access filter should be empty", text.getText().isEmpty()); + assertEquals("Quick access table should be empty", 0, table.getItemCount()); text.setText("T"); processEventsUntil(() -> table.getItemCount() > 1, TIMEOUT); int oldCount = table.getItemCount(); - assertTrue(oldCount > 3, "Not enough quick access items for simple filter"); - assertTrue(oldCount < MAXIMUM_NUMBER_OF_ELEMENTS, "Too many quick access items for size of table"); + assertTrue("Not enough quick access items for simple filter", oldCount > 3); + assertTrue("Too many quick access items for size of table", oldCount < MAXIMUM_NUMBER_OF_ELEMENTS); final String oldFirstItemText = table.getItem(0).getText(1); text.setText("B"); // The letter mustn't be part of the previous 1st proposal - assertTrue(DisplayHelper.waitForCondition(table.getDisplay(), + assertTrue("The quick access items should have changed", DisplayHelper.waitForCondition(table.getDisplay(), TIMEOUT, - () -> table.getItemCount() > 1 && !table.getItem(0).getText(1).equals(oldFirstItemText)), - "The quick access items should have changed"); + () -> table.getItemCount() > 1 && !table.getItem(0).getText(1).equals(oldFirstItemText))); int newCount = table.getItemCount(); - assertTrue(newCount > 3, "Not enough quick access items for simple filter"); - assertTrue(newCount < MAXIMUM_NUMBER_OF_ELEMENTS, "Too many quick access items for size of table"); + assertTrue("Not enough quick access items for simple filter", newCount > 3); + assertTrue("Too many quick access items for size of table", newCount < MAXIMUM_NUMBER_OF_ELEMENTS); } @Test @@ -154,13 +155,12 @@ public void testContributedElement() { dialog.open(); final Table table = dialog.getQuickAccessContents().getTable(); Text text = dialog.getQuickAccessContents().getFilterText(); - assertTrue(text.getText().isEmpty(), "Quick access filter should be empty"); - assertEquals(0, table.getItemCount(), "Quick access table should be empty"); + assertTrue("Quick access filter should be empty", text.getText().isEmpty()); + assertEquals("Quick access table should be empty", 0, table.getItemCount()); text.setText(TestQuickAccessComputer.TEST_QUICK_ACCESS_PROPOSAL_LABEL); - assertTrue(DisplayHelper.waitForCondition(dialog.getShell().getDisplay(), TIMEOUT, () -> - dialogContains(dialog, TestQuickAccessComputer.TEST_QUICK_ACCESS_PROPOSAL_LABEL)), - "Missing contributed element" + assertTrue("Missing contributed element", DisplayHelper.waitForCondition(dialog.getShell().getDisplay(), TIMEOUT, () -> + dialogContains(dialog, TestQuickAccessComputer.TEST_QUICK_ACCESS_PROPOSAL_LABEL)) ); } @@ -172,11 +172,11 @@ public void testLongRunningComputerDoesntFreezeUI() { Text text = dialog.getQuickAccessContents().getFilterText(); long duration = System.currentTimeMillis(); text.setText(TestLongRunningQuickAccessComputer.THE_ELEMENT.getId()); - assertTrue(System.currentTimeMillis() - duration < TestLongRunningQuickAccessComputer.DELAY, - "UI Frozen on text change"); - assertTrue(DisplayHelper.waitForCondition(dialog.getShell().getDisplay(), TestLongRunningQuickAccessComputer.DELAY + TIMEOUT, () -> + assertTrue("UI Frozen on text change", + System.currentTimeMillis() - duration < TestLongRunningQuickAccessComputer.DELAY); + assertTrue("Missing contributed element", DisplayHelper.waitForCondition(dialog.getShell().getDisplay(), TestLongRunningQuickAccessComputer.DELAY + TIMEOUT, () -> dialogContains(dialog, TestLongRunningQuickAccessComputer.THE_ELEMENT.getLabel()) - ), "Missing contributed element"); + )); table.select(0); activateCurrentElement(dialog); duration = System.currentTimeMillis(); @@ -185,7 +185,7 @@ public void testLongRunningComputerDoesntFreezeUI() { assertTrue(System.currentTimeMillis() - duration < TestLongRunningQuickAccessComputer.DELAY); AtomicLong tick = new AtomicLong(System.currentTimeMillis()); AtomicLong maxBlockedUIThread = new AtomicLong(); - assertTrue(DisplayHelper.waitForCondition( + assertTrue("Missing contributed element as previous pick", DisplayHelper.waitForCondition( secondDialog.getShell().getDisplay(), TestLongRunningQuickAccessComputer.DELAY + TIMEOUT, () -> { long currentTick = System.currentTimeMillis(); long previousTick = tick.getAndSet(currentTick); @@ -193,7 +193,7 @@ public void testLongRunningComputerDoesntFreezeUI() { maxBlockedUIThread.set(Math.max(maxBlockedUIThread.get(), currentDelayInUIThread)); return dialogContains(secondDialog, TestLongRunningQuickAccessComputer.THE_ELEMENT.getLabel()); - }), "Missing contributed element as previous pick"); + })); assertTrue(maxBlockedUIThread.get() < TestLongRunningQuickAccessComputer.DELAY); } @@ -208,15 +208,15 @@ public void testShowAll() throws Exception { dialog.open(); Text text = dialog.getQuickAccessContents().getFilterText(); final Table table = dialog.getQuickAccessContents().getTable(); - assertTrue(text.getText().isEmpty(), "Quick access filter should be empty"); - assertEquals(0, table.getItemCount(), "Quick access table should be empty"); + assertTrue("Quick access filter should be empty", text.getText().isEmpty()); + assertEquals("Quick access table should be empty", 0, table.getItemCount()); // Set a filter to get some items text.setText("T"); processEventsUntil(() -> table.getItemCount() > 1, TIMEOUT); final int defaultCount = table.getItemCount(); - assertTrue(defaultCount > 3, "Not enough quick access items for simple filter"); - assertTrue(defaultCount < MAXIMUM_NUMBER_OF_ELEMENTS, "Too many quick access items for size of table"); + assertTrue("Not enough quick access items for simple filter", defaultCount > 3); + assertTrue("Too many quick access items for size of table", defaultCount < MAXIMUM_NUMBER_OF_ELEMENTS); final String oldFirstItemText = table.getItem(0).getText(1); IHandlerService handlerService = PlatformUI.getWorkbench().getActiveWorkbenchWindow() @@ -225,21 +225,21 @@ public void testShowAll() throws Exception { handlerService.executeCommand("org.eclipse.ui.window.quickAccess", null); //$NON-NLS-1$ processEventsUntil(() -> table.getItemCount() != defaultCount, TIMEOUT); final int allCount = table.getItemCount(); - assertTrue(allCount > defaultCount, "Turning on show all should display more items"); - assertEquals(oldFirstItemText, table.getItem(0).getText(1), "Turning on show all should not change the top item"); + assertTrue("Turning on show all should display more items", allCount > defaultCount); + assertEquals("Turning on show all should not change the top item", oldFirstItemText, table.getItem(0).getText(1)); // Run the handler to turn off show all handlerService.executeCommand("org.eclipse.ui.window.quickAccess", null); //$NON-NLS-1$ processEventsUntil(() -> table.getItemCount() != allCount, TIMEOUT); // Note: The table count may one off from the old count because of shell resizing (scroll bars being added then removed) - assertTrue(table.getItemCount() < allCount, "Turning off show all should limit items shown"); - assertEquals(oldFirstItemText, table.getItem(0).getText(1), "Turning off show all should not change the top item"); + assertTrue("Turning off show all should limit items shown", table.getItemCount() < allCount); + assertEquals("Turning off show all should not change the top item", oldFirstItemText, table.getItem(0).getText(1)); // Run the handler to turn on show all handlerService.executeCommand("org.eclipse.ui.window.quickAccess", null); //$NON-NLS-1$ processEventsUntil(() -> table.getItemCount() == allCount, TIMEOUT); - assertEquals(allCount, table.getItemCount(), "Turning on show all twice shouldn't change the items"); - assertEquals(oldFirstItemText, table.getItem(0).getText(1), "Turning on show all twice shouldn't change the top item"); + assertEquals("Turning on show all twice shouldn't change the items", allCount, table.getItemCount()); + assertEquals("Turning on show all twice shouldn't change the top item", oldFirstItemText, table.getItem(0).getText(1)); // Close and reopen the shell dialog.close(); @@ -250,8 +250,8 @@ public void testShowAll() throws Exception { text.setText("T"); processEventsUntil(() -> newTable.getItemCount() > 1, TIMEOUT); // Note: The table count may one off from the old count because of shell resizing (scroll bars being added then removed) - assertTrue(newTable.getItemCount() < allCount, - "Show all should be turned off when the shell is closed and reopened"); + assertTrue("Show all should be turned off when the shell is closed and reopened", + newTable.getItemCount() < allCount); } @Test @@ -263,9 +263,9 @@ public void testPreviousChoicesAvailable() { Table firstTable = dialog.getQuickAccessContents().getTable(); String quickAccessElementText = "Project Explorer"; text.setText(quickAccessElementText); - assertTrue(DisplayHelper.waitForCondition(firstTable.getDisplay(), + assertTrue("Missing entry", DisplayHelper.waitForCondition(firstTable.getDisplay(), TIMEOUT, - () -> dialogContains(dialog, quickAccessElementText)), "Missing entry"); + () -> dialogContains(dialog, quickAccessElementText))); firstTable.select(0); activateCurrentElement(dialog); assertNotEquals(0, dialogSettings.getArray("orderedElements").length); @@ -278,9 +278,9 @@ public void testPreviousChoicesAvailable() { // then try in a new SearchField QuickAccessDialog secondDialog = new TestQuickAccessDialog(activeWorkbenchWindow, null); secondDialog.open(); - assertTrue(DisplayHelper.waitForCondition(secondDialog.getShell().getDisplay(), TIMEOUT, - () -> dialogContains(secondDialog, quickAccessElementText)), - "Missing entry in previous pick"); + assertTrue("Missing entry in previous pick", + DisplayHelper.waitForCondition(secondDialog.getShell().getDisplay(), TIMEOUT, + () -> dialogContains(secondDialog, quickAccessElementText))); } private void activateCurrentElement(QuickAccessDialog dialog) { @@ -299,18 +299,18 @@ public void testPreviousChoicesAvailableForExtension() { Text text = dialog.getQuickAccessContents().getFilterText(); text.setText(TestQuickAccessComputer.TEST_QUICK_ACCESS_PROPOSAL_LABEL); final Table firstTable = dialog.getQuickAccessContents().getTable(); - assertTrue(DisplayHelper.waitForCondition(text.getDisplay(), TIMEOUT, - () -> dialogContains(dialog, TestQuickAccessComputer.TEST_QUICK_ACCESS_PROPOSAL_LABEL)), - "Unexpected dialog contents: " + getAllEntries(dialog.getQuickAccessContents().getTable())); + assertTrue("Unexpected dialog contents: " + getAllEntries(dialog.getQuickAccessContents().getTable()), + DisplayHelper.waitForCondition(text.getDisplay(), TIMEOUT, + () -> dialogContains(dialog, TestQuickAccessComputer.TEST_QUICK_ACCESS_PROPOSAL_LABEL))); firstTable.select(0); activateCurrentElement(dialog); // then try in a new SearchField QuickAccessDialog secondDialog = new TestQuickAccessDialog(activeWorkbenchWindow, null); secondDialog.open(); - assertTrue(DisplayHelper.waitForCondition(secondDialog.getShell().getDisplay(), TIMEOUT, + assertTrue("Contributed item not found in previous choices", + DisplayHelper.waitForCondition(secondDialog.getShell().getDisplay(), TIMEOUT, () -> getAllEntries(secondDialog.getQuickAccessContents().getTable()).stream() - .anyMatch(TestQuickAccessComputer::isContributedItem)), - "Contributed item not found in previous choices"); + .anyMatch(TestQuickAccessComputer::isContributedItem))); } @Test @@ -331,10 +331,11 @@ public void testPreviousChoicesAvailableForIncrementalExtension() { dialog = new TestQuickAccessDialog(activeWorkbenchWindow, null); dialog.open(); final Table secondTable = dialog.getQuickAccessContents().getTable(); - assertTrue(DisplayHelper.waitForCondition(secondTable.getDisplay(), TIMEOUT, // + assertTrue("Contributed item not found in previous choices", + DisplayHelper.waitForCondition(secondTable.getDisplay(), TIMEOUT, // () -> getAllEntries(secondTable).stream() - .anyMatch(TestIncrementalQuickAccessComputer::isContributedItem)), - "Contributed item not found in previous choices"); + .anyMatch(TestIncrementalQuickAccessComputer::isContributedItem) + )); } @Test @@ -344,9 +345,9 @@ public void testPrefixMatchHavePriority() { Text text = dialog.getQuickAccessContents().getFilterText(); Table table = dialog.getQuickAccessContents().getTable(); text.setText("P"); - assertTrue(DisplayHelper.waitForCondition(table.getDisplay(), TIMEOUT, () -> table.getItemCount() > 3), - "Not enough quick access items for simple filter"); - assertTrue(table.getItem(0).getText(1).toLowerCase().startsWith("p"), "Non-prefix match first"); + assertTrue("Not enough quick access items for simple filter", + DisplayHelper.waitForCondition(table.getDisplay(), TIMEOUT, () -> table.getItemCount() > 3)); + assertTrue("Non-prefix match first", table.getItem(0).getText(1).toLowerCase().startsWith("p")); } @Test @@ -365,9 +366,9 @@ public void testCommandEnableContext() throws Exception { Text text = dialog.getQuickAccessContents().getFilterText(); Table table = dialog.getQuickAccessContents().getTable(); text.setText("Toggle Split"); - assertTrue(DisplayHelper.waitForCondition(table.getDisplay(), TIMEOUT, () -> table.getItemCount() > 1), - "Not enough quick access items for simple filter"); - assertTrue(table.getItem(0).getText(1).toLowerCase().startsWith("toggle split"), "Non-prefix match first"); + assertTrue("Not enough quick access items for simple filter", + DisplayHelper.waitForCondition(table.getDisplay(), TIMEOUT, () -> table.getItemCount() > 1)); + assertTrue("Non-prefix match first", table.getItem(0).getText(1).toLowerCase().startsWith("toggle split")); } private List getAllEntries(Table table) {