diff --git a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/FirstClassM1Tests.java b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/FirstClassM1Tests.java index f75c295a267..4fc07e41da6 100644 --- a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/FirstClassM1Tests.java +++ b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/FirstClassM1Tests.java @@ -15,7 +15,7 @@ package org.eclipse.ui.tests.navigator; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.eclipse.swt.widgets.TreeItem; import org.eclipse.ui.tests.navigator.m12.model.M1Project; @@ -51,13 +51,13 @@ public void testM1ProjectHasChildren() throws Exception { TreeItem[] rootItems = _viewer.getTree().getItems(); TreeItem p1Item = rootItems[_p1Ind]; - assertEquals("P1 tree item should be an M1Project", M1Project.class, - p1Item.getData().getClass()); + assertEquals(M1Project.class, p1Item.getData().getClass(), + "P1 tree item should be an M1Project"); _expand(rootItems); TreeItem[] p1Children = p1Item.getItems(); - assertEquals("Project should have 3 children", 3, p1Children.length); + assertEquals(3, p1Children.length, "Project should have 3 children"); } diff --git a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/GoBackForwardsTest.java b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/GoBackForwardsTest.java index 3b8dfaff2ef..10eea8ff7e5 100644 --- a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/GoBackForwardsTest.java +++ b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/GoBackForwardsTest.java @@ -15,20 +15,26 @@ import static org.eclipse.ui.tests.harness.util.UITestUtil.processEvents; import static org.eclipse.ui.tests.harness.util.UITestUtil.processEventsUntil; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorReference; import org.eclipse.ui.INavigationLocation; +import org.eclipse.ui.IWindowListener; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PartInitException; @@ -36,16 +42,14 @@ import org.eclipse.ui.internal.NavigationHistoryAction; import org.eclipse.ui.intro.IIntroPart; import org.eclipse.ui.part.FileEditorInput; -import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule; import org.eclipse.ui.tests.harness.util.EditorTestHelper; import org.eclipse.ui.tests.harness.util.FileUtil; import org.eclipse.ui.tests.harness.util.UITestUtil.Condition; import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.ui.texteditor.TextSelectionNavigationLocation; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @since 3.3 @@ -64,19 +68,84 @@ public class GoBackForwardsTest { private IProject project; private IFile file; + private final List testWindows = new ArrayList<>(); + private IWindowListener windowListener; + private Set initialShells; - @Rule - public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule(); - - @Before + @BeforeEach public void setUp() throws CoreException, IOException { + addWindowListener(); + storeInitialShells(); + project = FileUtil.createProject(PROJECT_NAME); file = FileUtil.createFile(FILE_NAME, project); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(FILE_CONTENTS); Files.writeString(Paths.get(file.getLocation().toOSString()), stringBuilder); project.refreshLocal(IResource.DEPTH_INFINITE, null); + } + + @AfterEach + public void tearDown() { + removeWindowListener(); + processEvents(); + closeAllTestWindows(); + processEvents(); + checkForLeakedShells(); + } + private void addWindowListener() { + windowListener = new IWindowListener() { + @Override + public void windowActivated(IWorkbenchWindow window) { + } + + @Override + public void windowDeactivated(IWorkbenchWindow window) { + } + + @Override + public void windowClosed(IWorkbenchWindow window) { + testWindows.remove(window); + } + + @Override + public void windowOpened(IWorkbenchWindow window) { + testWindows.add(window); + } + }; + PlatformUI.getWorkbench().addWindowListener(windowListener); + } + + private void removeWindowListener() { + if (windowListener != null) { + PlatformUI.getWorkbench().removeWindowListener(windowListener); + } + } + + private void closeAllTestWindows() { + List testWindowsCopy = new ArrayList<>(testWindows); + for (IWorkbenchWindow testWindow : testWindowsCopy) { + testWindow.close(); + } + testWindows.clear(); + } + + private void storeInitialShells() { + this.initialShells = Set.of(PlatformUI.getWorkbench().getDisplay().getShells()); + } + + private void checkForLeakedShells() { + List leakedModalShellTitles = new ArrayList<>(); + Shell[] shells = PlatformUI.getWorkbench().getDisplay().getShells(); + for (Shell shell : shells) { + if (!shell.isDisposed() && !initialShells.contains(shell)) { + leakedModalShellTitles.add(shell.getText()); + shell.close(); + } + } + assertEquals(0, leakedModalShellTitles.size(), + "Test leaked modal shell: [" + String.join(", ", leakedModalShellTitles) + "]"); } @Test @@ -95,79 +164,75 @@ public void testNavigationHistoryNavigation() throws PartInitException { openGenericEditor(editorInput); - assertTrue("Timeout during navigation." + getStateDetails(), - processEventsUntil(genericEditorNoSelection, 1000)); + assertTrue(processEventsUntil(genericEditorNoSelection, 1000), + "Timeout during navigation." + getStateDetails()); selectInGenericEditor(editorInput); - assertTrue("Timeout during navigation." + getStateDetails(), - processEventsUntil(genericEditorSelection, 1000)); + assertTrue(processEventsUntil(genericEditorSelection, 1000), + "Timeout during navigation." + getStateDetails()); openTextEditor(editorInput); - assertTrue("Timeout during navigation." + getStateDetails(), - processEventsUntil(textEditorNoSelection, 1000)); + assertTrue(processEventsUntil(textEditorNoSelection, 1000), + "Timeout during navigation." + getStateDetails()); selectInTextEditor(editorInput); - assertTrue("Timeout during navigation." + getStateDetails(), - processEventsUntil(textEditorSelection, 1000)); + assertTrue(processEventsUntil(textEditorSelection, 1000), + "Timeout during navigation." + getStateDetails()); openGenericEditor(editorInput); - assertTrue("Timeout during navigation." + getStateDetails(), - processEventsUntil(genericEditorSelection, 1000)); + assertTrue(processEventsUntil(genericEditorSelection, 1000), + "Timeout during navigation." + getStateDetails()); openTextEditor(editorInput); - assertTrue("Timeout during navigation." + getStateDetails(), - processEventsUntil(textEditorSelection, 1000)); + assertTrue(processEventsUntil(textEditorSelection, 1000), + "Timeout during navigation." + getStateDetails()); // Navigate backward from text editor to editor goBackward(EditorTestHelper.getActiveWorkbenchWindow(), genericEditorSelection); - Assert.assertEquals( - "Failed to correctly navigate backward from text editor to java editor." + getStateDetails(), - GENERIC_EDITOR_ID, getActiveEditorId()); + assertEquals(GENERIC_EDITOR_ID, getActiveEditorId(), + "Failed to correctly navigate backward from text editor to java editor." + getStateDetails()); // Navigate backward from java editor to text editor goBackward(EditorTestHelper.getActiveWorkbenchWindow(), textEditorSelection); - Assert.assertEquals( - "Failed to correctly navigate backward from java editor to test editor." + getStateDetails(), - TEXT_EDITOR_ID, getActiveEditorId()); + assertEquals(TEXT_EDITOR_ID, getActiveEditorId(), + "Failed to correctly navigate backward from java editor to test editor." + getStateDetails()); // Navigate backward from text editor to text editor goBackward(EditorTestHelper.getActiveWorkbenchWindow(), textEditorNoSelection); - Assert.assertEquals( - "Failed to correctly navigate backward from text editor to text editor." + getStateDetails(), - TEXT_EDITOR_ID, getActiveEditorId()); + assertEquals(TEXT_EDITOR_ID, getActiveEditorId(), + "Failed to correctly navigate backward from text editor to text editor." + getStateDetails()); // Navigate backward from java editor to java editor goBackward(EditorTestHelper.getActiveWorkbenchWindow(), genericEditorSelection); goBackward(EditorTestHelper.getActiveWorkbenchWindow(), genericEditorNoSelection); - Assert.assertEquals( - "Failed to correctly navigate backward from java editor to java editor." + getStateDetails(), - GENERIC_EDITOR_ID, getActiveEditorId()); + assertEquals(GENERIC_EDITOR_ID, getActiveEditorId(), + "Failed to correctly navigate backward from java editor to java editor." + getStateDetails()); // Navigate forward from java editor to java editor goForward(EditorTestHelper.getActiveWorkbenchWindow(), genericEditorSelection); - Assert.assertEquals("Failed to correctly navigate forward from java editor to java editor." + getStateDetails(), - GENERIC_EDITOR_ID, getActiveEditorId()); + assertEquals(GENERIC_EDITOR_ID, getActiveEditorId(), + "Failed to correctly navigate forward from java editor to java editor." + getStateDetails()); // Navigate forward from text editor to text editor goForward(EditorTestHelper.getActiveWorkbenchWindow(), textEditorNoSelection); goForward(EditorTestHelper.getActiveWorkbenchWindow(), textEditorSelection); - Assert.assertEquals("Failed to correctly navigate forward from java editor to java editor." + getStateDetails(), - TEXT_EDITOR_ID, getActiveEditorId()); + assertEquals(TEXT_EDITOR_ID, getActiveEditorId(), + "Failed to correctly navigate forward from java editor to java editor." + getStateDetails()); // Navigate forward from text editor to java editor goForward(EditorTestHelper.getActiveWorkbenchWindow(), genericEditorSelection); - Assert.assertEquals("Failed to correctly navigate forward from text editor to java editor." + getStateDetails(), - GENERIC_EDITOR_ID, getActiveEditorId()); + assertEquals(GENERIC_EDITOR_ID, getActiveEditorId(), + "Failed to correctly navigate forward from text editor to java editor." + getStateDetails()); // Navigate forward from java editor to text editor goForward(EditorTestHelper.getActiveWorkbenchWindow(), textEditorSelection); - Assert.assertEquals("Failed to correctly navigate forward from java editor to text editor." + getStateDetails(), - TEXT_EDITOR_ID, getActiveEditorId()); + assertEquals(TEXT_EDITOR_ID, getActiveEditorId(), + "Failed to correctly navigate forward from java editor to text editor." + getStateDetails()); } private Condition currentNavigationHistoryLocationCondition(String editorId, boolean selection) { @@ -207,13 +272,13 @@ private void openTextEditor(IEditorInput editorInput) throws PartInitException { private void goForward(IWorkbenchWindow window, Condition condition) { NavigationHistoryAction action = new NavigationHistoryAction(window, true); action.run(); - assertTrue("Timeout during navigation.", processEventsUntil(condition, 1000)); + assertTrue(processEventsUntil(condition, 1000), "Timeout during navigation."); } private void goBackward(IWorkbenchWindow window, Condition condition) { NavigationHistoryAction action = new NavigationHistoryAction(window, false); action.run(); - assertTrue("Timeout during navigation.", processEventsUntil(condition, 1000)); + assertTrue(processEventsUntil(condition, 1000), "Timeout during navigation."); } private String getActiveEditorId() { diff --git a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/INavigatorContentServiceTests.java b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/INavigatorContentServiceTests.java index 01d98649c18..5a2b5efb856 100644 --- a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/INavigatorContentServiceTests.java +++ b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/INavigatorContentServiceTests.java @@ -14,9 +14,9 @@ *******************************************************************************/ package org.eclipse.ui.tests.navigator; -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.util.Iterator; import java.util.Set; @@ -60,14 +60,14 @@ public void testFindValidExtensions() { .findRootContentProviders(ResourcesPlugin.getWorkspace() .getRoot()); - assertEquals("Ensure there is only one root content provider.", 1, - rootContentProviders.length); + assertEquals(1, rootContentProviders.length, + "Ensure there is only one root content provider."); Set projectContentExtensions = _contentService .findContentExtensionsByTriggerPoint(_project); - assertEquals("Ensure there are two content providers for an IProject.", - 2, projectContentExtensions.size()); + assertEquals(2, projectContentExtensions.size(), + "Ensure there are two content providers for an IProject."); boolean found = false; INavigatorContentExtension ext; @@ -79,21 +79,19 @@ public void testFindValidExtensions() { .getContentProvider(); Object[] projectChildren = testContentProvider .getChildren(_project); - assertEquals( - "There should be one test-type child of the project.", - 1, projectChildren.length); + assertEquals(1, projectChildren.length, + "There should be one test-type child of the project."); assertEquals("BlueParent", contentServiceLabelProvider .getText(projectChildren[0])); Object[] testRootChildren = contentServiceContentProvider .getChildren(projectChildren[0]); - assertEquals( - "There should be one test-type child of the root test-type item.", - 3, testRootChildren.length); + assertEquals(3, testRootChildren.length, + "There should be one test-type child of the root test-type item."); found = true; } } - assertTrue("The test content provider was not found.", found); + assertTrue(found, "The test content provider was not found."); } @@ -111,14 +109,14 @@ public void testDeactivateTestExtension() { .findRootContentExtensions(ResourcesPlugin.getWorkspace() .getRoot()); - assertEquals("Ensure there is only one root content provider.", 1, - rootContentProviders.size()); + assertEquals(1, rootContentProviders.size(), + "Ensure there is only one root content provider."); Set projectContentExtensions = _contentService .findContentExtensionsByTriggerPoint(_project); - assertEquals("Ensure there is one content provider for an IProject.", - 1, projectContentExtensions.size()); + assertEquals(1, projectContentExtensions.size(), + "Ensure there is one content provider for an IProject."); } @@ -135,13 +133,12 @@ public void testBindTestExtension() { new String[] { COMMON_NAVIGATOR_RESOURCE_EXT, TEST_CONTENT, TEST_CONTENT2 }, false); - assertEquals("One descriptor should have been returned.", 1, - boundDescriptors.length); + assertEquals(1, boundDescriptors.length, + "One descriptor should have been returned."); - assertEquals( - "The declarative content service should have one fewer visible extension ids than the one created programmatically.", - _contentService.getVisibleExtensionIds().length + 1, - contentServiceWithProgrammaticBindings.getVisibleExtensionIds().length); + assertEquals(_contentService.getVisibleExtensionIds().length + 1, + contentServiceWithProgrammaticBindings.getVisibleExtensionIds().length, + "The declarative content service should have one fewer visible extension ids than the one created programmatically."); INavigatorContentDescriptor[] visibleDescriptors = contentServiceWithProgrammaticBindings .getVisibleExtensions(); @@ -151,37 +148,35 @@ public void testBindTestExtension() { found = true; } } - assertTrue("The programmatically bound extension should be bound.", - found); + assertTrue(found, + "The programmatically bound extension should be bound."); Set enabledDescriptors = contentServiceWithProgrammaticBindings .findContentExtensionsByTriggerPoint(_project); - assertEquals("There should be a three extensions.", 3, - enabledDescriptors.size()); + assertEquals(3, enabledDescriptors.size(), + "There should be a three extensions."); } @Test public void testTestExtensionVisibility() { - assertTrue("The test extension should be visible.", _contentService - .getViewerDescriptor().isVisibleContentExtension( - TEST_CONTENT)); + assertTrue(_contentService.getViewerDescriptor().isVisibleContentExtension(TEST_CONTENT), + "The test extension should be visible."); } @Test public void testResourceExtensionVisibility() { - assertTrue("The test extension should be visible.", _contentService - .getViewerDescriptor().isVisibleContentExtension( - COMMON_NAVIGATOR_RESOURCE_EXT)); + assertTrue(_contentService.getViewerDescriptor().isVisibleContentExtension(COMMON_NAVIGATOR_RESOURCE_EXT), + "The test extension should be visible."); } @Test public void testVisibleExtensionIds() { String[] visibleIds = _contentService.getVisibleExtensionIds(); - assertEquals("There should be three visible extensions.", 3, - visibleIds.length); + assertEquals(3, visibleIds.length, + "There should be three visible extensions."); for (String visibleId : visibleIds) { if (!TEST_CONTENT.equals(visibleId) && !COMMON_NAVIGATOR_RESOURCE_EXT.equals(visibleId) diff --git a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/SorterTest.java b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/SorterTest.java index 8762f43048d..0388a5f25b5 100644 --- a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/SorterTest.java +++ b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/SorterTest.java @@ -15,10 +15,10 @@ *******************************************************************************/ package org.eclipse.ui.tests.navigator; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.ByteArrayInputStream; import java.util.Arrays; @@ -75,7 +75,7 @@ public void testSorterMissing() throws Exception { // We should not get any notification because of the way that // sorters are found - assertEquals("Status Count: " + _statusCount, 0, _statusCount); + assertEquals(0, _statusCount, "Status Count: " + _statusCount); } // bug 231855 [CommonNavigator] CommonViewerSorter does not support diff --git a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/WorkingSetTest.java b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/WorkingSetTest.java index 5c032dcfa27..4af2f8c940b 100644 --- a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/WorkingSetTest.java +++ b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/WorkingSetTest.java @@ -14,8 +14,8 @@ *******************************************************************************/ package org.eclipse.ui.tests.navigator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IAdaptable; @@ -76,7 +76,7 @@ public void testEmptyWindowWorkingSet() throws Exception { l.propertyChange(event); TreeItem[] items = _viewer.getTree().getItems(); - assertTrue("There should be some items.", items.length > 0); + assertTrue(items.length > 0, "There should be some items."); assertEquals(null, _commonNavigator.getWorkingSetLabel()); } @@ -107,7 +107,7 @@ public void testMissingProjectsInWorkingSet() throws Exception { TreeItem[] items = _viewer.getTree().getItems(); // The bug is here where the first item is a IFile, not the enclosing // project - assertEquals("First item needs to be project", _p1, items[0].getData()); + assertEquals(_p1, items[0].getData(), "First item needs to be project"); assertEquals("ws1", _commonNavigator.getWorkingSetLabel()); } @@ -138,7 +138,7 @@ public void testTopLevelWorkingSet() throws Exception { TreeItem[] items = _viewer.getTree().getItems(); // The bug is here where the first item is a IFile, not the enclosing // project - assertEquals("First item needs to be working set", workingSet, items[0].getData()); + assertEquals(workingSet, items[0].getData(), "First item needs to be working set"); assertEquals("ws1", _commonNavigator.getWorkingSetLabel()); // bug 268250 [CommonNavigator] Project labels missing in Project @@ -181,19 +181,19 @@ public void testTopLevelChange() throws Exception { TreeItem[] items = _viewer.getTree().getItems(); - assertEquals("First item needs to be working set", workingSet, items[0].getData()); + assertEquals(workingSet, items[0].getData(), "First item needs to be working set"); extensionStateModel.setBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS, false); refreshViewer(); items = _viewer.getTree().getItems(); - assertEquals("First item needs to be project", _p1, items[0].getData()); + assertEquals(_p1, items[0].getData(), "First item needs to be project"); extensionStateModel.setBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS, true); refreshViewer(); items = _viewer.getTree().getItems(); - assertEquals("First item needs to be working set", workingSet, items[0].getData()); + assertEquals(workingSet, items[0].getData(), "First item needs to be working set"); // Restore active working sets activePage.setWorkingSets(activeWorkingSets); @@ -265,7 +265,7 @@ public void testWorkingSetFilter() throws Exception { break; } } - assertTrue("Working set filter is gone, oh my!", found); + assertTrue(found, "Working set filter is gone, oh my!"); } // Bug 224703 - Project explorer doesn't show recreated working set @@ -343,14 +343,14 @@ public void testOtherProjectWorkingSet() throws Exception { _viewer.expandAll(); TreeItem[] items = _viewer.getTree().getItems(); - assertEquals("Missing working set or 'other projects'", 2, items.length); + assertEquals(2, items.length, "Missing working set or 'other projects'"); - assertEquals("First item needs to be working set", workingSet, items[0].getData()); + assertEquals(workingSet, items[0].getData(), "First item needs to be working set"); assertEquals(workingSet, items[0].getData()); assertEquals(_p1, items[0].getItem(0).getData()); - assertEquals("Last item needs to be 'other project'", WorkingSetsContentProvider.OTHERS_WORKING_SET, - items[1].getData()); + assertEquals(WorkingSetsContentProvider.OTHERS_WORKING_SET, items[1].getData(), + "Last item needs to be 'other project'"); assertEquals(_p1.getWorkspace().getRoot().getProjects().length - 1, items[1].getItemCount()); // Put all projects in same working set to disable "others" @@ -361,7 +361,7 @@ public void testOtherProjectWorkingSet() throws Exception { _viewer.expandAll(); items = _viewer.getTree().getItems(); - assertEquals("Should be the single working set", 1, items.length); + assertEquals(1, items.length, "Should be the single working set"); assertEquals(workingSet, items[0].getData()); // Remove project from ws to make "other projects" reappear @@ -372,14 +372,14 @@ public void testOtherProjectWorkingSet() throws Exception { _viewer.expandAll(); items = _viewer.getTree().getItems(); - assertEquals("Missing working set or 'other projects'", 2, items.length); + assertEquals(2, items.length, "Missing working set or 'other projects'"); - assertEquals("First item needs to be working set", workingSet, items[0].getData()); + assertEquals(workingSet, items[0].getData(), "First item needs to be working set"); assertEquals(workingSet, items[0].getData()); assertEquals(_p1, items[0].getItem(0).getData()); - assertEquals("Last item needs to be 'other project'", WorkingSetsContentProvider.OTHERS_WORKING_SET, - items[1].getData()); + assertEquals(WorkingSetsContentProvider.OTHERS_WORKING_SET, items[1].getData(), + "Last item needs to be 'other project'"); assertEquals(_p1.getWorkspace().getRoot().getProjects().length - 1, items[1].getItemCount()); } diff --git a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/jst/JstPipelineTest.java b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/jst/JstPipelineTest.java index b3c6276eb85..e5b13afde96 100644 --- a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/jst/JstPipelineTest.java +++ b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/jst/JstPipelineTest.java @@ -15,9 +15,9 @@ *******************************************************************************/ package org.eclipse.ui.tests.navigator.jst; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.function.Predicate; @@ -65,8 +65,8 @@ public void testJstPipeline() throws Exception { // Note this test will fail showing only one if the JDT stuff // is not included in the executing bundles (which it normally is) - assertEquals("There should be 3 visible extensions for the pipeline viewer.", 3, - _contentService.getVisibleExtensionIds().length); + assertEquals(3, _contentService.getVisibleExtensionIds().length, + "There should be 3 visible extensions for the pipeline viewer."); _contentService.getActivationService().activateExtensions( new String[] { COMMON_NAVIGATOR_RESOURCE_EXT, COMMON_NAVIGATOR_JAVA_EXT, TEST_CONTENT_JST }, true); @@ -78,10 +78,10 @@ public void testJstPipeline() throws Exception { TreeItem[] rootItems = _viewer.getTree().getItems(); - assertEquals("There should be " + _projectCount + " item(s).", _projectCount, rootItems.length); //$NON-NLS-1$ + assertEquals(_projectCount, rootItems.length, "There should be " + _projectCount + " item(s)."); //$NON-NLS-1$ - assertTrue("The root object should be an IJavaProject, which is IAdaptable.", //$NON-NLS-1$ - rootItems[0].getData() instanceof IAdaptable); + assertTrue(rootItems[0].getData() instanceof IAdaptable, //$NON-NLS-1$ + "The root object should be an IJavaProject, which is IAdaptable."); IProject adaptedProject = ((IAdaptable) rootItems[_projectInd].getData()).getAdapter(IProject.class); assertEquals(_project, adaptedProject); diff --git a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/FoldersAsProjectsContributionTest.java b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/FoldersAsProjectsContributionTest.java index f2ef09ce573..154f5fcca9d 100644 --- a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/FoldersAsProjectsContributionTest.java +++ b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/FoldersAsProjectsContributionTest.java @@ -13,8 +13,8 @@ ******************************************************************************/ package org.eclipse.ui.tests.navigator.resources; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -62,10 +62,10 @@ public void notAFolder() { String notAFolder = "Some string"; IMenuManager manager = menuManager(); provider(new StructuredSelection(notAFolder)).fillContextMenu(manager); - assertFalse("SelectProjectForFolderAction contributions were added on not an adaptable-to-IFolder selection", - contributionAdded(manager, SelectProjectForFolderAction.class)); - assertFalse("OpenFolderAsProjectAction contributions were added on not an adaptable-to-IFolder selection", - contributionAdded(manager, OpenFolderAsProjectAction.class)); + assertFalse(contributionAdded(manager, SelectProjectForFolderAction.class), + "SelectProjectForFolderAction contributions were added on not an adaptable-to-IFolder selection"); + assertFalse(contributionAdded(manager, OpenFolderAsProjectAction.class), + "OpenFolderAsProjectAction contributions were added on not an adaptable-to-IFolder selection"); } @Test @@ -73,10 +73,10 @@ public void noDescription() { IFolder justAFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(new Path("some/folder")); IMenuManager manager = menuManager(); provider(new StructuredSelection(justAFolder)).fillContextMenu(manager); - assertFalse("SelectProjectForFolderAction contributions were added on an IFolder without project description", - contributionAdded(manager, SelectProjectForFolderAction.class)); - assertFalse("OpenFolderAsProjectAction contributions were added on an IFolder without project description", - contributionAdded(manager, OpenFolderAsProjectAction.class)); + assertFalse(contributionAdded(manager, SelectProjectForFolderAction.class), + "SelectProjectForFolderAction contributions were added on an IFolder without project description"); + assertFalse(contributionAdded(manager, OpenFolderAsProjectAction.class), + "OpenFolderAsProjectAction contributions were added on an IFolder without project description"); } @Test @@ -103,10 +103,9 @@ public void alreadyAdded() throws IOException, CoreException { provider(new StructuredSelection( Arrays.asList(outer.getFolder(inner1.getName()), outer.getFolder(inner2.getName())))) .fillContextMenu(manager); - assertTrue( + assertTrue(contributionAdded(manager, SelectProjectForFolderAction.class), NLS.bind("A SelectProjectForFolderAction contribution was not added. Contribution List is: {0}", - contributionsList(manager)), - contributionAdded(manager, SelectProjectForFolderAction.class)); + contributionsList(manager))); } finally { clear(projects); } @@ -139,8 +138,9 @@ public void notYetImported() throws IOException, CoreException { provider(new StructuredSelection( Arrays.asList(outer.getFolder(inner1.getName()), outer.getFolder(inner2.getName())))) .fillContextMenu(manager); - assertTrue(NLS.bind("A OpenFolderAsProjectAction contribution was not added. Contribution List is: {0}", - contributionsList(manager)), contributionAdded(manager, OpenFolderAsProjectAction.class)); + assertTrue(contributionAdded(manager, OpenFolderAsProjectAction.class), + NLS.bind("A OpenFolderAsProjectAction contribution was not added. Contribution List is: {0}", + contributionsList(manager))); } finally { clear(projects); } @@ -168,12 +168,10 @@ public void ambiguity() throws CoreException, IOException { provider(new StructuredSelection( Arrays.asList(outer.getFolder(inner1.getName()), outer.getFolder(inner2.getName())))) .fillContextMenu(manager); - assertFalse( - "There were both imported and not-imported projects in selection, but SelectProjectForFolderAction contributions were added", - contributionAdded(manager, SelectProjectForFolderAction.class)); - assertFalse( - "There were both imported and not-imported projects in selection, but OpenFolderAsProjectAction contributions were added", - contributionAdded(manager, OpenFolderAsProjectAction.class)); + assertFalse(contributionAdded(manager, SelectProjectForFolderAction.class), + "There were both imported and not-imported projects in selection, but SelectProjectForFolderAction contributions were added"); + assertFalse(contributionAdded(manager, OpenFolderAsProjectAction.class), + "There were both imported and not-imported projects in selection, but OpenFolderAsProjectAction contributions were added"); } finally { clear(projects); } @@ -239,7 +237,7 @@ private void ensureFileExists(IFile description, String name) throws IOException // If project description does not exist after creation (for whatever reason), // create it explicitly with empty content Files.createFile(Paths.get(description.getLocationURI())); - assertTrue(String.format("Project description for %s does not exist", name), description.exists()); + assertTrue(description.exists(), String.format("Project description for %s does not exist", name)); } } \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/NestedResourcesTests.java b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/NestedResourcesTests.java index 2dfd54cdcf7..f37fa08e65e 100644 --- a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/NestedResourcesTests.java +++ b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/NestedResourcesTests.java @@ -13,8 +13,8 @@ ******************************************************************************/ package org.eclipse.ui.tests.navigator.resources; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.HashSet; import java.util.Set; @@ -32,9 +32,9 @@ import org.eclipse.ui.internal.navigator.resources.nested.NestedProjectManager; import org.eclipse.ui.internal.navigator.resources.nested.NestedProjectsLabelProvider; import org.eclipse.ui.tests.harness.util.DisplayHelper; -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * @since 3.5 @@ -82,28 +82,28 @@ public void testProjectHierarchy() throws Exception { testProjects.add(projectABB); // Wait for NestedProjectManager to process all resource changes - assertTrue("NestedProjectManager did not update children for projectA", - DisplayHelper.waitForCondition(Display.getDefault(), TIMEOUT, - () -> NestedProjectManager.getInstance().getDirectChildrenProjects(projectA).length == 1)); + assertTrue(DisplayHelper.waitForCondition(Display.getDefault(), TIMEOUT, + () -> NestedProjectManager.getInstance().getDirectChildrenProjects(projectA).length == 1), + "NestedProjectManager did not update children for projectA"); IProject[] childrenOfProjectA = NestedProjectManager.getInstance().getDirectChildrenProjects(projectA); - Assert.assertEquals(projectAB, childrenOfProjectA[0]); - Assert.assertNull(NestedProjectManager.getInstance().getMostDirectOpenContainer(projectA)); + Assertions.assertEquals(projectAB, childrenOfProjectA[0]); + Assertions.assertNull(NestedProjectManager.getInstance().getMostDirectOpenContainer(projectA)); // Wait for NestedProjectManager to process projectAAA - assertTrue("NestedProjectManager did not update children for folderAA", - DisplayHelper.waitForCondition(Display.getDefault(), TIMEOUT, - () -> NestedProjectManager.getInstance().getDirectChildrenProjects(folderAA).length == 1)); + assertTrue(DisplayHelper.waitForCondition(Display.getDefault(), TIMEOUT, + () -> NestedProjectManager.getInstance().getDirectChildrenProjects(folderAA).length == 1), + "NestedProjectManager did not update children for folderAA"); IProject[] childrenOfFolderAA = NestedProjectManager.getInstance().getDirectChildrenProjects(folderAA); - Assert.assertEquals("aaa", childrenOfFolderAA[0].getName()); - Assert.assertEquals(folderAA, + Assertions.assertEquals("aaa", childrenOfFolderAA[0].getName()); + Assertions.assertEquals(folderAA, NestedProjectManager.getInstance().getMostDirectOpenContainer(childrenOfFolderAA[0])); // Wait for NestedProjectManager to process both projectABA and projectABB - assertTrue("NestedProjectManager did not update children for projectAB", - DisplayHelper.waitForCondition(Display.getDefault(), TIMEOUT, - () -> NestedProjectManager.getInstance().getDirectChildrenProjects(projectAB).length == 2)); + assertTrue(DisplayHelper.waitForCondition(Display.getDefault(), TIMEOUT, + () -> NestedProjectManager.getInstance().getDirectChildrenProjects(projectAB).length == 2), + "NestedProjectManager did not update children for projectAB"); } @Test @@ -129,8 +129,8 @@ public void testDashInProject() throws Exception { testProjects.add(projectAChild); testProjects.add(projectA_A); - Assert.assertTrue(NestedProjectManager.getInstance().hasDirectChildrenProjects(projectA)); - Assert.assertEquals(projectAChild, NestedProjectManager.getInstance().getDirectChildrenProjects(projectA)[0]); + assertTrue(NestedProjectManager.getInstance().hasDirectChildrenProjects(projectA)); + assertEquals(projectAChild, NestedProjectManager.getInstance().getDirectChildrenProjects(projectA)[0]); } private class NestedProjectsLabelProviderAccessor extends NestedProjectsLabelProvider { @@ -206,7 +206,7 @@ public void testProblemDecoration() throws Exception { () -> IMarker.SEVERITY_ERROR == labelProvider.getHighestProblemSeverity(parentProject))); } - @After + @AfterEach public void deleteProjects() throws Exception { IProgressMonitor monitor = new NullProgressMonitor(); for (IProject testProject : testProjects) { diff --git a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/PathComparatorTest.java b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/PathComparatorTest.java index c927e97fcaa..225fa5f6fbe 100644 --- a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/PathComparatorTest.java +++ b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/PathComparatorTest.java @@ -13,8 +13,8 @@ ******************************************************************************/ package org.eclipse.ui.tests.navigator.resources; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.Comparator; @@ -38,9 +38,9 @@ private static void assertConsistentWithEquals(IPath p1, IPath p2) { private static void assertLessThan(IPath p1, IPath p2) { int compare = COMPARATOR.compare(p1, p2); - assertTrue(PathComparator.class.getName() + ".compare() returned " + compare + assertTrue(compare < 0, PathComparator.class.getName() + ".compare() returned " + compare + " expected less than zero for paths '" + p1 + "' and '" - + p2 + "'", compare < 0); + + p2 + "'"); } @Test diff --git a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/ResourceMgmtActionProviderTests.java b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/ResourceMgmtActionProviderTests.java index d4090995865..35809ea38e6 100644 --- a/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/ResourceMgmtActionProviderTests.java +++ b/tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/ResourceMgmtActionProviderTests.java @@ -10,8 +10,8 @@ *******************************************************************************/ package org.eclipse.ui.tests.navigator.resources; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IFolder; @@ -188,8 +188,8 @@ private void checkMenuHasCorrectContributions(boolean... actions) { for (String thisAction : new String[] { "org.eclipse.ui.BuildAction", "org.eclipse.ui.RefreshAction", "org.eclipse.ui.OpenResourceAction", "org.eclipse.ui.CloseResourceAction", "org.eclipse.ui.CloseUnrelatedProjectsAction" }) { - assertTrue(String.format("Unexpected menu membership for %s (%b)", thisAction, !actions[index]), - actions[index] == menuHasContribution(thisAction)); + assertTrue(actions[index] == menuHasContribution(thisAction), + String.format("Unexpected menu membership for %s (%b)", thisAction, !actions[index])); index++; } }