Skip to content
Closed
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
Expand Up @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.ui.tests.activities;

import static org.eclipse.ui.PlatformUI.getWorkbench;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand All @@ -28,8 +29,6 @@
import org.eclipse.core.runtime.ContributorFactoryOSGi;
import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.RegistryFactory;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.activities.IActivity;
import org.eclipse.ui.activities.IActivityPatternBinding;
import org.eclipse.ui.activities.IActivityRequirementBinding;
Expand All @@ -41,6 +40,7 @@
import org.eclipse.ui.activities.WorkbenchTriggerPointAdvisor;
import org.eclipse.ui.internal.activities.MutableActivityManager;
import org.eclipse.ui.tests.TestPlugin;
import org.eclipse.ui.tests.harness.util.DisplayHelper;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -425,8 +425,8 @@ public void testCategoryListener() {
* Tests to ensure dynamism with regard to the extension registry.
*/
@Test
public void testDynamicRegistry() {
IWorkbenchActivitySupport was = PlatformUI.getWorkbench()
public void testDynamicRegistry() throws NotDefinedException {
IWorkbenchActivitySupport was = getWorkbench()
.getActivitySupport();
IActivity activity = was.getActivityManager().getActivity(
"dynamic.activity");
Expand Down Expand Up @@ -464,18 +464,8 @@ public void testDynamicRegistry() {

// spin the event loop and ensure that the changes come down the pipe.
// 20 seconds should be more than enough
long endTime = System.currentTimeMillis() + 20000;
while (!(registryChanged[0] && registryChanged[1])
&& System.currentTimeMillis() < endTime) {

Display display = PlatformUI.getWorkbench().getDisplay();
if (display != null && !display.isDisposed()) {
while (display.readAndDispatch()) {
}
}
display.sleep();

}
DisplayHelper.waitForCondition(getWorkbench().getDisplay(), 20000,
() -> registryChanged[0] == true && registryChanged[1]);

assertTrue("Activity Listener not called", registryChanged[0]);
assertTrue("Category Listener not called", registryChanged[1]);
Expand All @@ -490,11 +480,7 @@ public void testDynamicRegistry() {
.pattern());
assertEquals("dynamic.activity", patternBinding.getActivityId());

try {
assertTrue(activity.isDefaultEnabled());
} catch (NotDefinedException e) {
fail(e.getMessage());
}
assertTrue(activity.isDefaultEnabled());

Set<IActivityRequirementBinding> requirementBindings = activity.getActivityRequirementBindings();
assertEquals(1, requirementBindings.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
*******************************************************************************/
package org.eclipse.ui.tests.api;

import static org.eclipse.ui.tests.harness.util.UITestCase.processEvents;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
Expand All @@ -30,23 +37,13 @@
import org.eclipse.ui.tests.harness.util.CallHistory;
import org.eclipse.ui.tests.harness.util.FileUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
* This is a test for IEditorPart. Since IEditorPart is an interface this test
* verifies the IEditorPart lifecycle rather than the implementation.
*/
@RunWith(JUnit4.class)
public class IEditorPartTest extends IWorkbenchPartTest {

/**
* Constructor for IEditorPartTest
*/
public IEditorPartTest() {
super(IEditorPartTest.class.getSimpleName());
}

/**
* @see IWorkbenchPartTest#openPart(IWorkbenchPage)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,23 @@
*******************************************************************************/
package org.eclipse.ui.tests.api;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.eclipse.ui.ISaveablePart;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.tests.harness.util.CallHistory;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
* This is a test for IViewPart. Since IViewPart is an
* interface this test verifies the IViewPart lifecycle rather
* than the implementation.
*/
@RunWith(JUnit4.class)
public class IViewPartTest extends IWorkbenchPartTest {

/**
* Constructor for IEditorPartTest
*/
public IViewPartTest() {
super(IViewPartTest.class.getSimpleName());
}

/**
* @see IWorkbenchPartTest#openPart(IWorkbenchPage)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,29 @@
*******************************************************************************/
package org.eclipse.ui.tests.api;

import static org.junit.Assert.assertTrue;

import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.tests.harness.util.CallHistory;
import org.eclipse.ui.tests.harness.util.UITestCase;
import org.junit.Before;
import org.junit.Test;

/**
* This is a test for IWorkbenchPart. Since IWorkbenchPart is an
* interface this test verifies the IWorkbenchPart lifecycle rather
* than the implementation.
*/
public abstract class IWorkbenchPartTest extends UITestCase {
public abstract class IWorkbenchPartTest {

protected IWorkbenchWindow fWindow;

protected IWorkbenchPage fPage;

/**
* Constructor for IActionDelegateTest
*/
public IWorkbenchPartTest(String testName) {
super(testName);
}

@Override
protected void doSetUp() throws Exception {
super.doSetUp();
fWindow = openTestWindow();
@Before
public void doSetUp() throws Exception {
fWindow = UITestCase.openTestWindow();
fPage = fWindow.getActivePage();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
import org.eclipse.ui.handlers.IHandlerService;
import org.junit.Test;

/**
* @since 3.5
*/
public class Bug417762Test {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

package org.eclipse.ui.tests.commands;

import static org.eclipse.ui.PlatformUI.getWorkbench;
import static org.eclipse.ui.tests.harness.util.UITestCase.openTestWindow;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.util.HashMap;
import java.util.Map;

Expand All @@ -35,22 +40,21 @@
import org.eclipse.ui.menus.UIElement;
import org.eclipse.ui.services.IServiceLocator;
import org.eclipse.ui.services.IServiceScopes;
import org.eclipse.ui.tests.harness.util.UITestCase;
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
* @since 3.3
*/
@RunWith(JUnit4.class)
public class CommandCallbackTest extends UITestCase {
public class CommandCallbackTest {

private static final String HOST_PARAM_ID = "host";
private static final String PROT_PARAM_ID = "protocol";
private static final String PREFIX = "tests.commands.CCT.";
private static final String CMD1_ID = PREFIX + "cmd1";
private static final String CMD2_ID = PREFIX + "cmd2";
@Rule
public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();

private ICommandService commandService;
private Command cmd1;
Expand All @@ -61,27 +65,22 @@ public class CommandCallbackTest extends UITestCase {
private CallbackHandler cmd1Handler;
private CallbackHandler cmd2Handler;

public CommandCallbackTest() {
super(CommandCallbackTest.class.getSimpleName());
}

@Override
protected void doSetUp() throws Exception {
super.doSetUp();
commandService = fWorkbench
@Before
public void doSetUp() throws Exception {
commandService = getWorkbench()
.getService(ICommandService.class);
cmd1 = commandService.getCommand(CMD1_ID);
cmd2 = commandService.getCommand(CMD2_ID);
handlerService = fWorkbench
handlerService = getWorkbench()
.getService(IHandlerService.class);
cmd1Handler = new CallbackHandler();
cmd1Activation = handlerService.activateHandler(CMD1_ID, cmd1Handler);
cmd2Handler = new CallbackHandler();
cmd2Activation = handlerService.activateHandler(CMD2_ID, cmd2Handler);
}

@Override
protected void doTearDown() throws Exception {
@After
public void doTearDown() throws Exception {
if (cmd1Activation != null) {
handlerService.deactivateHandler(cmd1Activation);
cmd1Activation = null;
Expand All @@ -90,7 +89,6 @@ protected void doTearDown() throws Exception {
handlerService.deactivateHandler(cmd2Activation);
cmd2Activation = null;
}
super.doTearDown();
}

private static class CallbackHandler extends AbstractHandler implements
Expand Down Expand Up @@ -180,9 +178,9 @@ public void testNoParametersWithCallbacks() throws Exception {
ParameterizedCommand pc2 = new ParameterizedCommand(cmd1, null);

IElementReference cr1 = commandService.registerElementForCommand(pc1,
new MyElement(fWorkbench));
new MyElement(getWorkbench()));
IElementReference cr2 = commandService.registerElementForCommand(pc2,
new MyElement(fWorkbench));
new MyElement(getWorkbench()));

try {
assertEquals(2, cmd1Handler.callbacks);
Expand Down Expand Up @@ -213,9 +211,9 @@ public void testParametersWithCallbacks() throws Exception {
new Parameterization(parmProt, "http"),
new Parameterization(parmHost, "download.eclipse.org") });
IElementReference cr1 = commandService.registerElementForCommand(pc1,
new MyElement(fWorkbench));
new MyElement(getWorkbench()));
IElementReference cr2 = commandService.registerElementForCommand(pc2,
new MyElement(fWorkbench));
new MyElement(getWorkbench()));
try {

assertEquals(2, cmd2Handler.callbacks);
Expand Down Expand Up @@ -261,11 +259,11 @@ public void testParmsToSameCommand() throws Exception {
new Parameterization(parmProt, "http"),
new Parameterization(parmHost, "download.eclipse.org") });
IElementReference cr1 = commandService.registerElementForCommand(pc1,
new MyElement(fWorkbench));
new MyElement(getWorkbench()));
IElementReference cr2 = commandService.registerElementForCommand(pc2,
new MyElement(fWorkbench));
new MyElement(getWorkbench()));
IElementReference cr3 = commandService.registerElementForCommand(pc3,
new MyElement(fWorkbench));
new MyElement(getWorkbench()));
try {

assertEquals(3, cmd2Handler.callbacks);
Expand Down Expand Up @@ -323,15 +321,15 @@ public void testParmsToDifferentProtocol() throws Exception {
new Parameterization[] { new Parameterization(parmProt, "ftp"),
new Parameterization(parmHost, "download.eclipse.org") });
IElementReference cr1 = commandService.registerElementForCommand(pc1,
new MyElement(fWorkbench));
new MyElement(getWorkbench()));
IElementReference cr2 = commandService.registerElementForCommand(pc2,
new MyElement(fWorkbench));
new MyElement(getWorkbench()));
IElementReference cr3 = commandService.registerElementForCommand(pc3,
new MyElement(fWorkbench));
new MyElement(getWorkbench()));
IElementReference cr4 = commandService.registerElementForCommand(pc4,
new MyElement(fWorkbench));
new MyElement(getWorkbench()));
IElementReference cr5 = commandService.registerElementForCommand(pc5,
new MyElement(fWorkbench));
new MyElement(getWorkbench()));
try {
assertEquals(5, cmd2Handler.callbacks);
Map<String, String> filter = new HashMap<>();
Expand Down Expand Up @@ -420,7 +418,7 @@ public void testCallbackCleanup() throws Exception {
try {
assertEquals(2, cmd1Handler.callbacks);
cmd1Handler.callbacks = 0;
closeAllTestWindows();
closeTestWindows.closeAllTestWindows();
commandService.refreshElements(CMD1_ID, null);
assertEquals(1, cmd1Handler.callbacks);
} finally {
Expand Down
Loading
Loading