diff options
| author | Rolf Theunissen | 2019-04-25 19:14:55 +0000 |
|---|---|---|
| committer | roltheun | 2019-04-28 17:07:16 +0000 |
| commit | 455d73468782b4a6d4d989cf76ead1a08f7a4f08 (patch) | |
| tree | 04a7aeeb838ed8777f8898619d1be0343a95228b | |
| parent | aee90db6478394e1f04d79728846696847e43794 (diff) | |
| download | eclipse.platform.ui-455d73468782b4a6d4d989cf76ead1a08f7a4f08.tar.gz eclipse.platform.ui-455d73468782b4a6d4d989cf76ead1a08f7a4f08.tar.xz eclipse.platform.ui-455d73468782b4a6d4d989cf76ead1a08f7a4f08.zip | |
Bug 546632 - Tests in UIAllTests are not independent
- Ensuring that the UIEventTopic provider instance
(UIEventObjectSupplier) is connected to the current context, by manually
injecting and uninjecting on the instance. Otherwise event-forwarding to
the UI-thread is not correctly configured in UIEventObjectSupplier. This
makes the test run independent.
- Introduce a JUnit rule for all common code in the affected tests.
Change-Id: I6d8f99305d871bc4d95826adc5c0a8dc2c77c83c
Signed-off-by: Rolf Theunissen <rolf.theunissen@gmail.com>
16 files changed, 403 insertions, 1092 deletions
diff --git a/bundles/org.eclipse.e4.ui.di/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.ui.di/META-INF/MANIFEST.MF index ae998f47256..78c66b4409a 100644 --- a/bundles/org.eclipse.e4.ui.di/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.ui.di/META-INF/MANIFEST.MF @@ -4,7 +4,7 @@ Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-SymbolicName: org.eclipse.e4.ui.di -Bundle-Version: 1.2.500.qualifier +Bundle-Version: 1.2.600.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Import-Package: javax.inject;version="1.0.0", diff --git a/bundles/org.eclipse.e4.ui.di/pom.xml b/bundles/org.eclipse.e4.ui.di/pom.xml index 72b74d555c8..8619e0a345c 100644 --- a/bundles/org.eclipse.e4.ui.di/pom.xml +++ b/bundles/org.eclipse.e4.ui.di/pom.xml @@ -19,6 +19,6 @@ </parent> <groupId>org.eclipse.e4</groupId> <artifactId>org.eclipse.e4.ui.di</artifactId> - <version>1.2.500-SNAPSHOT</version> + <version>1.2.600-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.e4.ui.di/src/org/eclipse/e4/ui/internal/di/UIEventObjectSupplier.java b/bundles/org.eclipse.e4.ui.di/src/org/eclipse/e4/ui/internal/di/UIEventObjectSupplier.java index e63f7a8ccdd..23dcb0050e7 100644 --- a/bundles/org.eclipse.e4.ui.di/src/org/eclipse/e4/ui/internal/di/UIEventObjectSupplier.java +++ b/bundles/org.eclipse.e4.ui.di/src/org/eclipse/e4/ui/internal/di/UIEventObjectSupplier.java @@ -78,6 +78,7 @@ public class UIEventObjectSupplier extends EventObjectSupplier { } @Inject + @Optional protected UISynchronize uiSync; @Inject @Optional diff --git a/tests/org.eclipse.e4.ui.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.e4.ui.tests/META-INF/MANIFEST.MF index a25b61f29f3..19458ab0293 100644 --- a/tests/org.eclipse.e4.ui.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.e4.ui.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Modelled UI tests bundle (Incubation) Bundle-SymbolicName: org.eclipse.e4.ui.tests; singleton:=true -Bundle-Version: 0.11.700.qualifier +Bundle-Version: 0.12.0.qualifier Bundle-Vendor: Eclipse.org Require-Bundle: org.eclipse.emf.ecore.xmi;bundle-version="2.4.0", org.eclipse.jface;bundle-version="3.4.0", diff --git a/tests/org.eclipse.e4.ui.tests/pom.xml b/tests/org.eclipse.e4.ui.tests/pom.xml index b0409cc1c10..a6c117fa54d 100644 --- a/tests/org.eclipse.e4.ui.tests/pom.xml +++ b/tests/org.eclipse.e4.ui.tests/pom.xml @@ -19,7 +19,7 @@ </parent> <groupId>org.eclipse.ui</groupId> <artifactId>org.eclipse.e4.ui.tests</artifactId> - <version>0.11.700-SNAPSHOT</version> + <version>0.12.0-SNAPSHOT</version> <packaging>eclipse-test-plugin</packaging> <build> diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java index 4a4ea60804c..7e1be8a8f7e 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java @@ -56,8 +56,6 @@ import org.junit.runners.Suite; */ @RunWith(Suite.class) @Suite.SuiteClasses({ - // Hack: bug 422676, run InjectionEventTest first - InjectionEventTest.class, StartupTestSuite.class, UIEventTypesTest.class, Bug299755Test.class, @@ -79,6 +77,7 @@ import org.junit.runners.Suite; Bug308317Test.class, ModelRobustnessTest.class, ResourceHandlerTest.class, + InjectionEventTest.class, // Commented out due the bug 505678 // PartFocusTest.class, ModelElementTest.class, diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/rules/WorkbenchContextRule.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/rules/WorkbenchContextRule.java new file mode 100644 index 00000000000..1ec5e0334cc --- /dev/null +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/rules/WorkbenchContextRule.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2019 Rolf Theunissen and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Rolf Theunissen <rolf.theunissen@gmail.com> - initial API and implementation + ******************************************************************************/ + +package org.eclipse.e4.ui.tests.rules; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.suppliers.ExtendedObjectSupplier; +import org.eclipse.e4.core.internal.di.osgi.ProviderHelper; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.di.UISynchronize; +import org.eclipse.e4.ui.internal.workbench.E4Workbench; +import org.eclipse.e4.ui.internal.workbench.swt.E4Application; +import org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.ui.basic.MWindow; +import org.eclipse.e4.ui.workbench.IWorkbench; +import org.eclipse.e4.ui.workbench.modeling.EModelService; +import org.eclipse.swt.widgets.Display; +import org.junit.rules.MethodRule; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.Statement; + +public class WorkbenchContextRule implements MethodRule { + + private IEclipseContext context; + private E4Workbench wb; + + public void createAndRunWorkbench(MWindow window) { + if (wb == null) { + wb = new E4Workbench(context.get(MApplication.class), context); + } + wb.createAndRunUI(window); + } + + public void spinEventLoop() { + while (Display.getDefault().readAndDispatch()) { + } + } + + @Override + public Statement apply(final Statement base, final FrameworkMethod method, final Object target) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + createContext(); + ContextInjectionFactory.inject(target, context); + try { + base.evaluate(); + } finally { + dispose(); + } + } + }; + } + + protected void createContext() throws Throwable { + context = E4Application.createDefaultContext(); + context.set(IWorkbench.PRESENTATION_URI_ARG, PartRenderingEngine.engineURI); + + final Display display = Display.getDefault(); + context.set(UISynchronize.class, new UISynchronize() { + @Override + public void syncExec(Runnable runnable) { + display.syncExec(runnable); + } + + @Override + public void asyncExec(Runnable runnable) { + display.asyncExec(runnable); + } + }); + + ContextInjectionFactory.setDefault(context); + + // Workaround, enforce injection on UIEventTopic provider with current context + ExtendedObjectSupplier supplier = ProviderHelper.findProvider(UIEventTopic.class.getName(), null); + ContextInjectionFactory.inject(supplier, context); + + EModelService ems = context.get(EModelService.class); + MApplication application = ems.createModelElement(MApplication.class); + application.setContext(context); + context.set(MApplication.class, application); + } + + protected void dispose() { + if (wb != null) { + wb.close(); + } + + ContextInjectionFactory.setDefault(null); + + // Workaround, enforce uninjection on the UIEventTopic provider from context + ExtendedObjectSupplier supplier = ProviderHelper.findProvider(UIEventTopic.class.getName(), null); + ContextInjectionFactory.uninject(supplier, context); + + context.dispose(); + } + +} diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/InjectionEventTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/InjectionEventTest.java index e9a1fc2c88c..f3c634610d7 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/InjectionEventTest.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/InjectionEventTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 IBM Corporation and others. + * Copyright (c) 2010, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Rolf Theunissen <rolf.theunissen@gmail.com> - Bug 546632 ******************************************************************************/ package org.eclipse.e4.ui.tests.workbench; @@ -20,7 +21,6 @@ import static org.junit.Assert.assertNull; import javax.inject.Inject; import javax.inject.Singleton; -import org.eclipse.core.databinding.observable.Realm; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -29,9 +29,10 @@ import org.eclipse.e4.core.di.InjectorFactory; import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.core.di.extensions.EventTopic; import org.eclipse.e4.core.di.internal.extensions.util.EventUtils; +import org.eclipse.e4.core.di.suppliers.ExtendedObjectSupplier; +import org.eclipse.e4.core.internal.di.osgi.ProviderHelper; import org.eclipse.e4.ui.di.UIEventTopic; import org.eclipse.e4.ui.di.UISynchronize; -import org.eclipse.jface.databinding.swt.DisplayRealm; import org.eclipse.swt.widgets.Display; import org.junit.Before; import org.junit.Test; @@ -135,9 +136,7 @@ public class InjectionEventTest { IEclipseContext context = EclipseContextFactory.create(); final Display d = Display.getDefault(); - context.set(Realm.class, DisplayRealm.getRealm(d)); context.set(UISynchronize.class, new UISynchronize() { - @Override public void syncExec(Runnable runnable) { d.syncExec(runnable); @@ -149,6 +148,11 @@ public class InjectionEventTest { } }); ContextInjectionFactory.setDefault(context); + + // Workaround, enforce injection on UIEventTopic provider with current context + ExtendedObjectSupplier supplier = ProviderHelper.findProvider(UIEventTopic.class.getName(), null); + ContextInjectionFactory.inject(supplier, context); + InjectTarget target = ContextInjectionFactory.make(InjectTarget.class, context); @@ -204,6 +208,11 @@ public class InjectionEventTest { assertEquals(2, target.counter3); assertEquals("event3data", target.string3); assertNotNull(target.myBinding); + + ContextInjectionFactory.setDefault(null); + // Workaround, enforce uninjection on the UIEventTopic provider from context + ContextInjectionFactory.uninject(supplier, context); + context.dispose(); } // NOTE: this test relies on GC being actually done on the test object. @@ -228,9 +237,7 @@ public class InjectionEventTest { IEclipseContext context = EclipseContextFactory.create(); final Display d = Display.getDefault(); - context.set(Realm.class, DisplayRealm.getRealm(d)); context.set(UISynchronize.class, new UISynchronize() { - @Override public void syncExec(Runnable runnable) { d.syncExec(runnable); @@ -241,6 +248,9 @@ public class InjectionEventTest { d.asyncExec(runnable); } }); + // Workaround, enforce injection on UIEventTopic provider with current context + ExtendedObjectSupplier supplier = ProviderHelper.findProvider(UIEventTopic.class.getName(), null); + ContextInjectionFactory.inject(supplier, context); InjectStarEvent target = ContextInjectionFactory.make( InjectStarEvent.class, context); @@ -254,6 +264,10 @@ public class InjectionEventTest { assertEquals(1, target.counter1); assertEquals("sample", target.data); + + // Workaround, enforce uninjection on the UIEventTopic provider from context + ContextInjectionFactory.uninject(supplier, context); + context.dispose(); } private void wrapSetup() { diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MMenuItemTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MMenuItemTest.java index d212182d37f..1d646955608 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MMenuItemTest.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MMenuItemTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 IBM Corporation and others. + * Copyright (c) 2009, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Rolf Theunissen <rolf.theunissen@gmail.com> - Bug 546632 ******************************************************************************/ package org.eclipse.e4.ui.tests.workbench; @@ -20,18 +21,16 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import javax.inject.Inject; import javax.inject.Named; import org.eclipse.e4.core.commands.CommandServiceAddon; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.ui.bindings.BindingServiceAddon; -import org.eclipse.e4.ui.internal.workbench.E4Workbench; import org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon; import org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon; import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer; -import org.eclipse.e4.ui.internal.workbench.swt.E4Application; -import org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.commands.MCommand; import org.eclipse.e4.ui.model.application.commands.MHandler; @@ -49,7 +48,7 @@ import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution; import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator; import org.eclipse.e4.ui.services.ContextServiceAddon; -import org.eclipse.e4.ui.workbench.IWorkbench; +import org.eclipse.e4.ui.tests.rules.WorkbenchContextRule; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.e4.ui.workbench.modeling.EPartService; import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer; @@ -61,31 +60,29 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Widget; -import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; public class MMenuItemTest { - protected IEclipseContext appContext; - protected E4Workbench wb; + + @Rule + public WorkbenchContextRule contextRule = new WorkbenchContextRule(); + + @Inject private EModelService ems; + @Inject + private IEclipseContext appContext; + + @Inject + private MApplication application; + @Before public void setUp() { - appContext = E4Application.createDefaultContext(); ContextInjectionFactory.make(CommandServiceAddon.class, appContext); ContextInjectionFactory.make(ContextServiceAddon.class, appContext); ContextInjectionFactory.make(BindingServiceAddon.class, appContext); - appContext.set(IWorkbench.PRESENTATION_URI_ARG, PartRenderingEngine.engineURI); - ems = appContext.get(EModelService.class); - } - - @After - public void tearDown() { - if (wb != null) { - wb.close(); - } - appContext.dispose(); } private void testMMenuItem_Text(String before, String beforeExpected, String after, String afterExpected) { @@ -98,13 +95,8 @@ public class MMenuItemTest { window.setMainMenu(menu); menu.getChildren().add(menuItem); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); ((MenuManager) ((Widget) menu.getWidget()).getData()).updateAll(true); @@ -185,13 +177,8 @@ public class MMenuItemTest { menu.getChildren().add(menuItem2); window.setMainMenu(menu); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); ((MenuManager) ((Widget) menu.getWidget()).getData()).updateAll(true); @@ -242,13 +229,8 @@ public class MMenuItemTest { menu.getChildren().add(menuItem); window.setMainMenu(menu); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); ((MenuManager) ((Widget) menu.getWidget()).getData()).updateAll(true); @@ -276,13 +258,8 @@ public class MMenuItemTest { menu.getChildren().add(menuItem); window.setMainMenu(menu); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MenuManager barManager = (MenuManager) ((Menu) menu.getWidget()).getData(); barManager.updateAll(true); @@ -313,13 +290,8 @@ public class MMenuItemTest { menu.getChildren().add(menuItem); window.setMainMenu(menu); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MenuManager barManager = (MenuManager) ((Menu) menu.getWidget()).getData(); barManager.updateAll(true); @@ -358,13 +330,8 @@ public class MMenuItemTest { item2.setLabel("item2"); fileMenu.getChildren().add(item2); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MenuManagerRenderer renderer = getRenderer(appContext, mainMenu); MenuManager manager = renderer.getManager(mainMenu); @@ -406,13 +373,8 @@ public class MMenuItemTest { fileMenu.getChildren().add(item2); item2.setToBeRendered(false); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MenuManagerRenderer renderer = getRenderer(appContext, mainMenu); MenuManager manager = renderer.getManager(mainMenu); @@ -454,13 +416,8 @@ public class MMenuItemTest { fileMenu.getChildren().add(item2); item2.setVisible(false); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MenuManagerRenderer renderer = getRenderer(appContext, mainMenu); MenuManager manager = renderer.getManager(mainMenu); @@ -503,14 +460,9 @@ public class MMenuItemTest { item2.setLabel("item2"); fileMenu.getChildren().add(item2); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); application.getMenuContributions().add(createContribution(false)); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MenuManagerRenderer renderer = getRenderer(appContext, mainMenu); @@ -548,14 +500,9 @@ public class MMenuItemTest { item2.setLabel("item2"); fileMenu.getChildren().add(item2); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); application.getMenuContributions().add(createContribution(true)); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MenuManagerRenderer renderer = getRenderer(appContext, mainMenu); @@ -633,14 +580,9 @@ public class MMenuItemTest { item2.setLabel("item2"); fileMenu.getChildren().add(item2); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); createMenuContributionWithCoreExpression(application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MenuManagerRenderer renderer = getRenderer(appContext, mainMenu); MenuManager manager = renderer.getManager(mainMenu); @@ -703,14 +645,9 @@ public class MMenuItemTest { item2.setLabel("item2"); fileMenu.getChildren().add(item2); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); createMenuContributionWithImperativeExpression(application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MenuManagerRenderer renderer = getRenderer(appContext, mainMenu); MenuManager manager = renderer.getManager(mainMenu); @@ -783,13 +720,8 @@ public class MMenuItemTest { menu.getChildren().add(menuItem); window.setMainMenu(menu); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); // force the part activation to ensure they have a context EPartService eps = window.getContext().get(EPartService.class); @@ -855,18 +787,14 @@ public class MMenuItemTest { menu.getChildren().add(menuItem); window.setMainMenu(menu); - MApplication application = ems.createModelElement(MApplication.class); application.getCommands().add(command); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); // The handler processing addon cannot run until the context // contains the MApplication ContextInjectionFactory.make(CommandProcessingAddon.class, appContext); ContextInjectionFactory.make(HandlerProcessingAddon.class, appContext); - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); // force the part activation to ensure they have a context EPartService eps = window.getContext().get(EPartService.class); diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MPartTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MPartTest.java index c63aa960f83..66b882a5713 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MPartTest.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MPartTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 IBM Corporation and others. + * Copyright (c) 2009, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Rolf Theunissen <rolf.theunissen@gmail.com> - Bug 546632 ******************************************************************************/ package org.eclipse.e4.ui.tests.workbench; @@ -19,55 +20,41 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import javax.inject.Inject; import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.ui.internal.workbench.E4Workbench; -import org.eclipse.e4.ui.internal.workbench.swt.E4Application; -import org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer; import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; import org.eclipse.e4.ui.model.application.ui.basic.MWindow; +import org.eclipse.e4.ui.tests.rules.WorkbenchContextRule; import org.eclipse.e4.ui.workbench.IPresentationEngine; -import org.eclipse.e4.ui.workbench.IWorkbench; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; public class MPartTest { - protected IEclipseContext appContext; - protected E4Workbench wb; - private EModelService ems; - @Before - public void setUp() throws Exception { - appContext = E4Application.createDefaultContext(); - appContext.set(IWorkbench.PRESENTATION_URI_ARG, PartRenderingEngine.engineURI); - ems = appContext.get(EModelService.class); - } + @Rule + public WorkbenchContextRule contextRule = new WorkbenchContextRule(); - @After - public void tearDown() throws Exception { - if (wb != null) { - wb.close(); - } - appContext.dispose(); - } + @Inject + private IEclipseContext appContext; + + @Inject + private EModelService ems; + + @Inject + private MApplication application; @Test public void testSetName() { final MWindow window = createWindowWithOneView("Part Name"); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MPartSashContainer container = (MPartSashContainer) window.getChildren().get(0); MPartStack stack = (MPartStack) container.getChildren().get(0); @@ -85,13 +72,8 @@ public class MPartTest { public void testCTabItem_GetImage() { final MWindow window = createWindowWithOneView("Part Name"); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MPartSashContainer container = (MPartSashContainer) window.getChildren().get(0); MPartStack stack = (MPartStack) container.getChildren().get(0); @@ -104,13 +86,8 @@ public class MPartTest { private void testDeclaredName(String declared, String expected) { final MWindow window = createWindowWithOneView(declared); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MPartSashContainer container = (MPartSashContainer) window.getChildren().get(0); MPartStack stack = (MPartStack) container.getChildren().get(0); @@ -137,13 +114,8 @@ public class MPartTest { private void testDeclaredTooltip(String partToolTip, String expectedToolTip) { final MWindow window = createWindowWithOneView("Part Name", partToolTip); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MPartSashContainer container = (MPartSashContainer) window.getChildren().get(0); MPartStack stack = (MPartStack) container.getChildren().get(0); @@ -171,13 +143,8 @@ public class MPartTest { private void testMPart_setTooltip(String partToolTip, String expectedToolTip) { final MWindow window = createWindowWithOneView("Part Name"); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MPartSashContainer container = (MPartSashContainer) window.getChildren().get(0); MPartStack stack = (MPartStack) container.getChildren().get(0); @@ -210,13 +177,8 @@ public class MPartTest { public void testMPart_getContext() { final MWindow window = createWindowWithOneView("Part Name"); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MPartSashContainer container = (MPartSashContainer) window.getChildren().get(0); MPartStack stack = (MPartStack) container.getChildren().get(0); @@ -231,13 +193,8 @@ public class MPartTest { public void testMPartBug369866() { final MWindow window = createWindowWithOneView("Part"); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MPartSashContainer container = (MPartSashContainer) window.getChildren().get(0); MPartStack stack = (MPartStack) container.getChildren().get(0); diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MSaveablePartTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MSaveablePartTest.java index 94c55ccc5dd..36161f6b620 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MSaveablePartTest.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MSaveablePartTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 IBM Corporation and others. + * Copyright (c) 2009, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Rolf Theunissen <rolf.theunissen@gmail.com> - Bug 546632 ******************************************************************************/ package org.eclipse.e4.ui.tests.workbench; @@ -17,55 +18,36 @@ package org.eclipse.e4.ui.tests.workbench; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.ui.internal.workbench.E4Workbench; -import org.eclipse.e4.ui.internal.workbench.swt.E4Application; -import org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine; +import javax.inject.Inject; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer; import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; import org.eclipse.e4.ui.model.application.ui.basic.MWindow; -import org.eclipse.e4.ui.workbench.IWorkbench; +import org.eclipse.e4.ui.tests.rules.WorkbenchContextRule; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; public class MSaveablePartTest { - protected IEclipseContext appContext; - protected E4Workbench wb; - private EModelService ems; - @Before - public void setUp() throws Exception { - appContext = E4Application.createDefaultContext(); - appContext.set(IWorkbench.PRESENTATION_URI_ARG, - PartRenderingEngine.engineURI); - ems = appContext.get(EModelService.class); - } + @Rule + public WorkbenchContextRule contextRule = new WorkbenchContextRule(); - @After - public void tearDown() throws Exception { - if (wb != null) { - wb.close(); - } - appContext.dispose(); - } + @Inject + private EModelService ems; + + @Inject + private MApplication application; @Test public void testCreateView() { final MWindow window = createWindowWithOneView("Part Name"); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MPartSashContainer container = (MPartSashContainer) window .getChildren().get(0); diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MToolItemTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MToolItemTest.java index 140e8016fd2..8eba8de94e5 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MToolItemTest.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MToolItemTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 IBM Corporation and others. + * Copyright (c) 2009, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Rolf Theunissen <rolf.theunissen@gmail.com> - Bug 546632 ******************************************************************************/ package org.eclipse.e4.ui.tests.workbench; @@ -19,10 +20,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.ui.internal.workbench.E4Workbench; -import org.eclipse.e4.ui.internal.workbench.swt.E4Application; -import org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine; +import javax.inject.Inject; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar; import org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow; @@ -30,35 +28,24 @@ import org.eclipse.e4.ui.model.application.ui.menu.ItemType; import org.eclipse.e4.ui.model.application.ui.menu.MDirectToolItem; import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; import org.eclipse.e4.ui.model.application.ui.menu.MToolItem; -import org.eclipse.e4.ui.workbench.IWorkbench; +import org.eclipse.e4.ui.tests.rules.WorkbenchContextRule; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.ToolItem; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; public class MToolItemTest { - protected IEclipseContext appContext; - protected E4Workbench wb; - private EModelService ems; - @Before - public void setUp() throws Exception { - appContext = E4Application.createDefaultContext(); - appContext.set(IWorkbench.PRESENTATION_URI_ARG, - PartRenderingEngine.engineURI); - ems = appContext.get(EModelService.class); - } + @Rule + public WorkbenchContextRule contextRule = new WorkbenchContextRule(); - @After - public void tearDown() throws Exception { - if (wb != null) { - wb.close(); - } - appContext.dispose(); - } + @Inject + private EModelService ems; + + @Inject + private MApplication application; private void testMToolItem_Text(String before, String beforeExpected, String after, String afterExpected) { @@ -73,13 +60,8 @@ public class MToolItemTest { trimBar.getChildren().add(toolBar); toolBar.getChildren().add(toolItem); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Object widget = toolItem.getWidget(); assertNotNull(widget); @@ -157,13 +139,8 @@ public class MToolItemTest { trimBar.getChildren().add(toolBar); toolBar.getChildren().add(toolItem); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Object widget = toolItem.getWidget(); assertNotNull(widget); @@ -244,13 +221,8 @@ public class MToolItemTest { toolBar.getChildren().add(toolItem1); toolBar.getChildren().add(toolItem2); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(window, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Object widget1 = toolItem1.getWidget(); assertNotNull(widget1); diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MWindowTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MWindowTest.java index 2839098f5ae..564b984e0ce 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MWindowTest.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MWindowTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 IBM Corporation and others. + * Copyright (c) 2009, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Rolf Theunissen <rolf.theunissen@gmail.com> - Bug 546632 ******************************************************************************/ package org.eclipse.e4.ui.tests.workbench; @@ -22,14 +23,9 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import org.eclipse.e4.core.commands.CommandServiceAddon; -import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import javax.inject.Inject; import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.ui.di.UISynchronize; -import org.eclipse.e4.ui.internal.workbench.E4Workbench; import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer; -import org.eclipse.e4.ui.internal.workbench.swt.E4Application; -import org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer; @@ -39,7 +35,7 @@ import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem; import org.eclipse.e4.ui.model.application.ui.menu.MMenu; import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; import org.eclipse.e4.ui.services.IServiceConstants; -import org.eclipse.e4.ui.workbench.IWorkbench; +import org.eclipse.e4.ui.tests.rules.WorkbenchContextRule; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.jface.action.MenuManager; import org.eclipse.swt.SWT; @@ -52,60 +48,34 @@ import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.Widget; -import org.junit.After; -import org.junit.Before; import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; /** * */ public class MWindowTest { - protected IEclipseContext appContext; - protected E4Workbench wb; - private EModelService ems; - @Before - public void setUp() throws Exception { - appContext = E4Application.createDefaultContext(); - ContextInjectionFactory.make(CommandServiceAddon.class, appContext); - appContext.set(IWorkbench.PRESENTATION_URI_ARG, PartRenderingEngine.engineURI); - appContext.set(UISynchronize.class, new UISynchronize() { - @Override - public void syncExec(Runnable runnable) { - runnable.run(); - } + @Rule + public WorkbenchContextRule contextRule = new WorkbenchContextRule(); - @Override - public void asyncExec(final Runnable runnable) { - runnable.run(); - } - }); - ContextInjectionFactory.setDefault(appContext); - ems = appContext.get(EModelService.class); - } + @Inject + private IEclipseContext appContext; - @After - public void tearDown() throws Exception { - if (wb != null) { - wb.close(); - } - appContext.dispose(); - ContextInjectionFactory.setDefault(null); - } + @Inject + private EModelService ems; + + @Inject + private MApplication application; @Test public void testCreateWindow() { final MWindow window = ems.createModelElement(MWindow.class); window.setLabel("MyWindow"); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Widget topWidget = (Widget) window.getWidget(); assertNotNull(topWidget); @@ -120,13 +90,8 @@ public class MWindowTest { final MWindow window = ems.createModelElement(MWindow.class); window.setLabel("MyWindow"); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Widget topWidget = (Widget) window.getWidget(); assertNotNull(topWidget); @@ -148,13 +113,8 @@ public class MWindowTest { window.setLabel("MyWindow"); window.setVisible(false); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Widget topWidget = (Widget) window.getWidget(); assertNotNull(topWidget); @@ -168,13 +128,8 @@ public class MWindowTest { public void testCreateView() { final MWindow window = createWindowWithOneView(); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MPartSashContainer container = (MPartSashContainer) window.getChildren().get(0); MPartStack stack = (MPartStack) container.getChildren().get(0); @@ -192,13 +147,8 @@ public class MWindowTest { public void testContextChildren() { final MWindow window = createWindowWithOneView(); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Widget topWidget = (Widget) window.getWidget(); assertNotNull(topWidget); @@ -241,13 +191,9 @@ public class MWindowTest { public void testCreateMenu() { final MWindow window = createWindowWithOneViewAndMenu(); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); + contextRule.createAndRunWorkbench(window); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); ((MenuManager) ((Widget) window.getMainMenu().getWidget()).getData()).updateAll(true); Widget topWidget = (Widget) window.getWidget(); @@ -283,13 +229,8 @@ public class MWindowTest { final MWindow window = ems.createModelElement(MWindow.class); window.setLabel("windowName"); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Object widget = window.getWidget(); assertNotNull(widget); @@ -314,13 +255,8 @@ public class MWindowTest { window.setWidth(200); window.setHeight(200); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Object widget = window.getWidget(); assertTrue(widget instanceof Shell); @@ -352,13 +288,8 @@ public class MWindowTest { window.setWidth(200); window.setHeight(200); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Object widget = window.getWidget(); assertTrue(widget instanceof Shell); @@ -389,13 +320,8 @@ public class MWindowTest { window.setWidth(200); window.setHeight(200); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Object widget = window.getWidget(); assertTrue(widget instanceof Shell); @@ -423,13 +349,8 @@ public class MWindowTest { window.setWidth(200); window.setHeight(200); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Object widget = window.getWidget(); assertTrue(widget instanceof Shell); @@ -457,13 +378,8 @@ public class MWindowTest { detachedWindow.setLabel("DetachedWindow"); window.getWindows().add(detachedWindow); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertTrue(window.getWidget() instanceof Shell); assertTrue(detachedWindow.getWidget() instanceof Shell); diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartOnTopManagerTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartOnTopManagerTest.java index ef0947c5144..49ef0e88b25 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartOnTopManagerTest.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartOnTopManagerTest.java @@ -1,14 +1,16 @@ /******************************************************************************* - * Copyright (c) 2016 vogella GmbH and others. + * Copyright (c) 2016, 2019 vogella GmbH and others. * - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License 2.0 which accompanies this distribution, and is -t https://www.eclipse.org/legal/epl-2.0/ -t -t SPDX-License-Identifier: EPL-2.0 + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 * * Contributors: * Simon Scholz <simon.scholz@vogella.com> - initial API and implementation + * Rolf Theunissen <rolf.theunissen@gmail.com> - Bug 546632 ******************************************************************************/ package org.eclipse.e4.ui.tests.workbench; @@ -16,13 +18,8 @@ package org.eclipse.e4.ui.tests.workbench; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.ui.di.UISynchronize; -import org.eclipse.e4.ui.internal.workbench.E4Workbench; +import javax.inject.Inject; import org.eclipse.e4.ui.internal.workbench.PartOnTopManager; -import org.eclipse.e4.ui.internal.workbench.swt.E4Application; -import org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.ui.MContext; import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; @@ -32,18 +29,12 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer; import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; import org.eclipse.e4.ui.model.application.ui.basic.MWindow; +import org.eclipse.e4.ui.tests.rules.WorkbenchContextRule; import org.eclipse.e4.ui.workbench.IWorkbench; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.e4.ui.workbench.modeling.EPartService; -import org.eclipse.jface.databinding.swt.DisplayRealm; -import org.eclipse.swt.widgets.Display; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; -import org.osgi.service.log.LogEntry; -import org.osgi.service.log.LogListener; -import org.osgi.service.log.LogReaderService; -import org.osgi.service.log.LogService; /** * This test class is used to validate the correctness of the @@ -51,55 +42,14 @@ import org.osgi.service.log.LogService; */ public class PartOnTopManagerTest { - protected IEclipseContext appContext; - protected E4Workbench wb; - private EModelService ems; - - private boolean logged = false; + @Rule + public WorkbenchContextRule contextRule = new WorkbenchContextRule(); - private LogListener listener = new LogListener() { - @Override - public void logged(LogEntry entry) { - if (!logged) { - logged = entry.getLevel() == LogService.LOG_ERROR; - } - } - }; - - @Before - public void setUp() { - logged = false; - appContext = E4Application.createDefaultContext(); - appContext.set(IWorkbench.PRESENTATION_URI_ARG, PartRenderingEngine.engineURI); - - final Display d = Display.getDefault(); - appContext.set(Realm.class, DisplayRealm.getRealm(d)); - appContext.set(UISynchronize.class, new UISynchronize() { - @Override - public void syncExec(Runnable runnable) { - d.syncExec(runnable); - } - - @Override - public void asyncExec(Runnable runnable) { - d.asyncExec(runnable); - } - }); - - LogReaderService logReaderService = appContext.get(LogReaderService.class); - logReaderService.addLogListener(listener); - ems = appContext.get(EModelService.class); - } + @Inject + private EModelService ems; - @After - public void tearDown() { - LogReaderService logReaderService = appContext.get(LogReaderService.class); - logReaderService.removeLogListener(listener); - if (wb != null) { - wb.close(); - } - appContext.dispose(); - } + @Inject + private MApplication application; private boolean isPartOnTop(MContext context) { if (context.getContext() != null) { @@ -112,7 +62,6 @@ public class PartOnTopManagerTest { @Test public void test_PartOnTop() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -122,18 +71,13 @@ public class PartOnTopManagerTest { window.getChildren().add(part); window.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertTrue(isPartOnTop(part)); } @Test public void test_PlaceholderOnTop() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -155,18 +99,13 @@ public class PartOnTopManagerTest { perspective.getChildren().add(placeholder); perspective.setSelectedElement(placeholder); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertTrue(isPartOnTop(part)); } @Test public void test_PartOnTopStackSwitch() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -184,11 +123,7 @@ public class PartOnTopManagerTest { "bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView"); partStack.getChildren().add(secondPart); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertTrue(isPartOnTop(part)); assertFalse(isPartOnTop(secondPart)); @@ -201,7 +136,6 @@ public class PartOnTopManagerTest { @Test public void test_PlaceholderOnTopStackSwitch() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -231,11 +165,7 @@ public class PartOnTopManagerTest { "bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView"); partStack.getChildren().add(secondPart); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertTrue(isPartOnTop(part)); assertFalse(isPartOnTop(secondPart)); @@ -254,7 +184,6 @@ public class PartOnTopManagerTest { @Test public void test_PartOnTopPerspectiveSwitch() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -287,11 +216,7 @@ public class PartOnTopManagerTest { "bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView"); secondPerspective.getChildren().add(secondPerspectivePart); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertTrue(isPartOnTop(part)); assertFalse(isPartOnTop(secondPart)); @@ -307,7 +232,6 @@ public class PartOnTopManagerTest { @Test public void test_PlaceholderOnTopPerspectiveSwitch() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -361,11 +285,7 @@ public class PartOnTopManagerTest { "bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView"); secondPerspectiveSash.getChildren().add(secondPerspectiveOnTopPart); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertTrue(isPartOnTop(sharedPart)); assertFalse(isPartOnTop(secondPart)); diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java index 41bf9ec039a..950f14bbf82 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 IBM Corporation and others. + * Copyright (c) 2009, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -11,6 +11,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Sopot Cela <scela@redhat.com> - Bug 474183 + * Rolf Theunissen <rolf.theunissen@gmail.com> - Bug 546632 ******************************************************************************/ package org.eclipse.e4.ui.tests.workbench; @@ -23,15 +24,11 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.util.function.Consumer; -import org.eclipse.core.databinding.observable.Realm; +import javax.inject.Inject; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.services.statusreporter.StatusReporter; -import org.eclipse.e4.ui.di.UISynchronize; -import org.eclipse.e4.ui.internal.workbench.E4Workbench; -import org.eclipse.e4.ui.internal.workbench.swt.E4Application; import org.eclipse.e4.ui.internal.workbench.swt.IEventLoopAdvisor; -import org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor; import org.eclipse.e4.ui.model.application.ui.advanced.MArea; @@ -48,14 +45,13 @@ import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem; import org.eclipse.e4.ui.model.application.ui.menu.MMenu; import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; import org.eclipse.e4.ui.model.application.ui.menu.MToolControl; +import org.eclipse.e4.ui.tests.rules.WorkbenchContextRule; import org.eclipse.e4.ui.workbench.IPresentationEngine; -import org.eclipse.e4.ui.workbench.IWorkbench; import org.eclipse.e4.ui.workbench.addons.cleanupaddon.CleanupAddon; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.e4.ui.workbench.modeling.EPartService; import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState; import org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer; -import org.eclipse.jface.databinding.swt.DisplayRealm; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; @@ -78,8 +74,18 @@ import org.osgi.service.log.LogReaderService; import org.osgi.service.log.LogService; public class PartRenderingEngineTests { - protected IEclipseContext appContext; - protected E4Workbench wb; + + @Rule + public WorkbenchContextRule contextRule = new WorkbenchContextRule(); + + @Inject + private IEclipseContext appContext; + + @Inject + private EModelService ems; + + @Inject + private MApplication application; private LogListener listener = new LogListener() { @Override @@ -90,7 +96,6 @@ public class PartRenderingEngineTests { } }; private boolean logged = false; - private EModelService ems; private Consumer<RuntimeException> runtimeExceptionHandler; @Rule @@ -110,36 +115,15 @@ public class PartRenderingEngineTests { @Before public void setUp() throws Exception { logged = false; - appContext = E4Application.createDefaultContext(); - appContext.set(IWorkbench.PRESENTATION_URI_ARG, PartRenderingEngine.engineURI); - - final Display d = Display.getDefault(); - appContext.set(Realm.class, DisplayRealm.getRealm(d)); - appContext.set(UISynchronize.class, new UISynchronize() { - @Override - public void syncExec(Runnable runnable) { - d.syncExec(runnable); - } - - @Override - public void asyncExec(Runnable runnable) { - d.asyncExec(runnable); - } - }); LogReaderService logReaderService = appContext.get(LogReaderService.class); logReaderService.addLogListener(listener); - ems = appContext.get(EModelService.class); } @After public void tearDown() throws Exception { LogReaderService logReaderService = appContext.get(LogReaderService.class); logReaderService.removeLogListener(listener); - if (wb != null) { - wb.close(); - } - appContext.dispose(); } private void checkLog() { @@ -152,12 +136,6 @@ public class PartRenderingEngineTests { assertFalse(logged); } - private void spinEventLoop() { - while (Display.getCurrent().readAndDispatch()) { - // spin the event loop - } - } - /** * Sets a temporary RuntimeException handler, that doesn't show an error dialog * when an exception occurs. The handler is reset by calling @@ -204,14 +182,9 @@ public class PartRenderingEngineTests { @Test public void ensureRemovalOfWindowDoesNotResultInExceptionBug298415() { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); MWindow window = createWindowWithOneView("Part Name"); application.getChildren().add(window); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MPartSashContainer container = (MPartSashContainer) window.getChildren().get(0); MPartStack stack = (MPartStack) container.getChildren().get(0); @@ -221,21 +194,14 @@ public class PartRenderingEngineTests { renderer.removeGui(part); renderer.removeGui(window); - spinEventLoop(); + contextRule.spinEventLoop(); } @Test public void testAddWindowBug299219() throws Exception { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); - - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(window.getWidget()); @@ -247,10 +213,6 @@ public class PartRenderingEngineTests { @Test public void testPartStack_SetActiveChildBug299379() throws Exception { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); @@ -268,8 +230,7 @@ public class PartRenderingEngineTests { stack.getChildren().add(partA); stack.getChildren().add(partB); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder tabFolder = (CTabFolder) stack.getWidget(); assertEquals(0, tabFolder.getSelectionIndex()); @@ -284,10 +245,6 @@ public class PartRenderingEngineTests { @Test public void testPartStack_SetActiveChild2Bug299379() throws Exception { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); @@ -306,8 +263,7 @@ public class PartRenderingEngineTests { stack.getChildren().add(partB); stack.setSelectedElement(partA); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder tabFolder = (CTabFolder) stack.getWidget(); assertEquals(0, tabFolder.getSelectionIndex()); @@ -321,10 +277,6 @@ public class PartRenderingEngineTests { @Test public void testPartStack_SetActiveChild3Bug299379() throws Exception { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MPartDescriptor descriptor = ems.createModelElement(MPartDescriptor.class); descriptor .setContributionURI("bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView"); @@ -339,8 +291,7 @@ public class PartRenderingEngineTests { stack.getTags().add("aStack"); window.getChildren().add(stack); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder tabFolder = (CTabFolder) stack.getWidget(); assertEquals(0, tabFolder.getItemCount()); @@ -357,10 +308,6 @@ public class PartRenderingEngineTests { @Test public void testPartStack_SetActiveChild4Bug299379() throws Exception { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); @@ -378,8 +325,7 @@ public class PartRenderingEngineTests { stack.getChildren().add(partA); stack.getChildren().add(partB); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder tabFolder = (CTabFolder) stack.getWidget(); assertEquals(0, tabFolder.getSelectionIndex()); @@ -392,10 +338,6 @@ public class PartRenderingEngineTests { @Test public void testPartStack_SetActiveChild5Bug295250() throws Exception { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); @@ -406,8 +348,7 @@ public class PartRenderingEngineTests { partA.setContributionURI("bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView"); stack.getChildren().add(partA); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertEquals(partA, stack.getSelectedElement()); @@ -424,10 +365,6 @@ public class PartRenderingEngineTests { @Test public void testPartStack_SetActiveChild6Bug298797() throws Exception { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); @@ -438,8 +375,7 @@ public class PartRenderingEngineTests { partA.setContributionURI("bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView"); stack.getChildren().add(partA); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder tabFolder = (CTabFolder) stack.getWidget(); assertEquals(0, tabFolder.getSelectionIndex()); @@ -459,10 +395,6 @@ public class PartRenderingEngineTests { @Test public void testPartStack_ViewMenuHidenWhenPartsClosed_Bug377228() throws Exception { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); @@ -480,8 +412,7 @@ public class PartRenderingEngineTests { MDirectMenuItem item = ems.createModelElement(MDirectMenuItem.class); menu.getChildren().add(item); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder folder = (CTabFolder) stack.getWidget(); Composite compA = (Composite) folder.getTopRight(); @@ -497,17 +428,13 @@ public class PartRenderingEngineTests { EPartService partService = window.getContext().get(EPartService.class); partService.hidePart(part, true); - spinEventLoop(); + contextRule.spinEventLoop(); assertFalse(toolbar.getVisible()); } @Test public void testPartStack_ViewMenuShowWhenItemsAdded_Bug385083() throws Exception { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); @@ -522,8 +449,7 @@ public class PartRenderingEngineTests { menu.getTags().add(StackRenderer.TAG_VIEW_MENU); part.getMenus().add(menu); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder folder = (CTabFolder) stack.getWidget(); Composite compA = (Composite) folder.getTopRight(); @@ -539,23 +465,19 @@ public class PartRenderingEngineTests { MDirectMenuItem item = ems.createModelElement(MDirectMenuItem.class); menu.getChildren().add(item); - spinEventLoop(); + contextRule.spinEventLoop(); assertTrue(toolbar.getVisible()); // TODO disabled due to bug 461655/498320 // menu.getChildren().remove(item); - // spinEventLoop(); + // contextRule.spinEventLoop(); // // assertFalse(toolbar.getVisible()); } @Test public void testCreateGuiBug301021() throws Exception { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - // create two descriptors MPartDescriptor descriptor = ems.createModelElement(MPartDescriptor.class); descriptor @@ -586,8 +508,8 @@ public class PartRenderingEngineTests { MWindow window2 = ems.createModelElement(MWindow.class); application.getChildren().add(window2); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); + IPresentationEngine engine = appContext.get(IPresentationEngine.class); engine.createGui(window2); @@ -601,16 +523,11 @@ public class PartRenderingEngineTests { service.showPart("part2", EPartService.PartState.CREATE); - while (Display.getDefault().readAndDispatch()) { - } + contextRule.spinEventLoop(); } @Test public void testPart_ToBeRendered() { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); @@ -628,8 +545,7 @@ public class PartRenderingEngineTests { stack.getChildren().add(partA); stack.getChildren().add(partB); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder tabFolder = (CTabFolder) stack.getWidget(); assertEquals(0, tabFolder.getSelectionIndex()); @@ -648,10 +564,6 @@ public class PartRenderingEngineTests { @Test public void testPart_ToBeRendered2() throws Exception { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); @@ -671,8 +583,7 @@ public class PartRenderingEngineTests { stack.getChildren().add(partB); stack.setSelectedElement(partA); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder tabFolder = (CTabFolder) stack.getWidget(); assertEquals(1, tabFolder.getItemCount()); @@ -690,13 +601,8 @@ public class PartRenderingEngineTests { @Test public void testClientObjectUnsetWhenNotRenderedBug301439() { final MWindow window = createWindowWithOneView(""); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MPartSashContainer container = (MPartSashContainer) window .getChildren().get(0); @@ -719,10 +625,6 @@ public class PartRenderingEngineTests { @Test public void testCTabItem_SetControl_Bug304211() { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); @@ -736,8 +638,8 @@ public class PartRenderingEngineTests { stack.getChildren().add(partA); stack.setSelectedElement(partA); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); + IPresentationEngine engine = appContext.get(IPresentationEngine.class); CTabFolder folder = (CTabFolder) stack.getWidget(); @@ -774,10 +676,6 @@ public class PartRenderingEngineTests { @Test public void testToBeRenderedCausesSelectionChanges() { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); @@ -795,8 +693,7 @@ public class PartRenderingEngineTests { stack.getChildren().add(partA); stack.getChildren().add(partB); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder tabFolder = (CTabFolder) stack.getWidget(); assertEquals(0, tabFolder.getSelectionIndex()); @@ -854,10 +751,6 @@ public class PartRenderingEngineTests { @Test public void testSelectedElementNullingTBR() { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); @@ -880,8 +773,7 @@ public class PartRenderingEngineTests { container.getChildren().add(partB); container.getChildren().add(partC); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); // Ensure that changing the state of an element that is *not* // the selected element doesn't change its value @@ -918,10 +810,6 @@ public class PartRenderingEngineTests { @Test public void testSelectedElementNullingParentChange() { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - appContext.set(MApplication.class, application); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); @@ -944,8 +832,7 @@ public class PartRenderingEngineTests { container.getChildren().add(partB); container.getChildren().add(partC); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); // Ensure that changing the state of an element that is *not* // the selected element doesn't change its value @@ -966,15 +853,10 @@ public class PartRenderingEngineTests { @Test public void testCreateGuiBug301950() { - MApplication application = ems.createModelElement(MApplication.class); final MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MPart part = ems.createModelElement(MPart.class); part.setContributionURI("bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView"); @@ -984,14 +866,11 @@ public class PartRenderingEngineTests { renderer.createGui(part); renderer.removeGui(part); - while (Display.getCurrent().readAndDispatch()) { - // spin the event loop - } + contextRule.spinEventLoop(); } @Test public void testRemoveGuiBug307578() { - MApplication application = ems.createModelElement(MApplication.class); final MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1011,11 +890,7 @@ public class PartRenderingEngineTests { partB.setContributionURI("bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView"); stack.getChildren().add(partB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder folder = (CTabFolder) stack.getWidget(); // two parts, two items @@ -1037,9 +912,6 @@ public class PartRenderingEngineTests { @Test public void testRemoveGuiBug324033() throws Exception { - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1062,10 +934,7 @@ public class PartRenderingEngineTests { MPart partC = ems.createModelElement(MPart.class); partC.setContributionURI("bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView"); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(partA.getObject()); assertNull(partB.getObject()); @@ -1082,7 +951,6 @@ public class PartRenderingEngineTests { @Test public void testRemoveGuiBug323496() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1105,11 +973,7 @@ public class PartRenderingEngineTests { perspective.getChildren().add(placeholder); perspective.setSelectedElement(placeholder); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(part.getObject()); @@ -1123,9 +987,6 @@ public class PartRenderingEngineTests { // if (checkMacBug466636()) // return; - MApplication application = ems.createModelElement(MApplication.class); - application.setContext(appContext); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1144,10 +1005,7 @@ public class PartRenderingEngineTests { partB.setContributionURI("bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView"); partStack.getChildren().add(partB); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(partA.getObject()); assertNull(partB.getObject()); @@ -1161,7 +1019,6 @@ public class PartRenderingEngineTests { @Test public void testBug317591_NonSharedPart() { - MApplication application = ems.createModelElement(MApplication.class); final MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1175,11 +1032,7 @@ public class PartRenderingEngineTests { stack.getChildren().add(partA); stack.setSelectedElement(partA); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(partA.getObject()); @@ -1190,7 +1043,6 @@ public class PartRenderingEngineTests { @Test public void testBug317591_SharedPart() { - MApplication application = ems.createModelElement(MApplication.class); MPartDescriptor descriptorA = ems.createModelElement(MPartDescriptor.class); descriptorA.setElementId("sharedA"); descriptorA @@ -1210,11 +1062,7 @@ public class PartRenderingEngineTests { window.getChildren().add(stack); window.setSelectedElement(stack); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); EPartService partService = window.getContext().get(EPartService.class); @@ -1233,7 +1081,6 @@ public class PartRenderingEngineTests { @Test public void testRemoveGuiBug324228_1() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1266,11 +1113,7 @@ public class PartRenderingEngineTests { perspectiveB.getChildren().add(placeholderB); perspectiveB.setSelectedElement(placeholderB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); SampleView view = (SampleView) part.getObject(); assertFalse(view.isDestroyed()); @@ -1285,7 +1128,6 @@ public class PartRenderingEngineTests { @Test public void testRemoveGuiBug324228_2() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1318,11 +1160,7 @@ public class PartRenderingEngineTests { perspectiveB.getChildren().add(placeholderB); perspectiveB.setSelectedElement(placeholderB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); SampleView view = (SampleView) part.getObject(); assertFalse(view.isDestroyed()); @@ -1336,7 +1174,6 @@ public class PartRenderingEngineTests { @Test public void testRemoveGuiBug324228_3() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1372,11 +1209,7 @@ public class PartRenderingEngineTests { perspectiveB.getChildren().add(placeholderB); perspectiveB.setSelectedElement(placeholderB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); SampleView view = (SampleView) part.getObject(); assertFalse(view.isDestroyed()); @@ -1390,7 +1223,6 @@ public class PartRenderingEngineTests { @Test public void testRemoveGuiBug324228_4() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1426,11 +1258,7 @@ public class PartRenderingEngineTests { perspectiveB.getChildren().add(placeholderB); perspectiveB.setSelectedElement(placeholderB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); SampleView view = (SampleView) part.getObject(); assertFalse(view.isDestroyed()); @@ -1445,7 +1273,6 @@ public class PartRenderingEngineTests { @Test public void testRemoveGuiBug324230() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1459,11 +1286,7 @@ public class PartRenderingEngineTests { // add an element into the container that's not being rendered sashContainer.getChildren().add(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(sashContainer.getWidget()); @@ -1474,7 +1297,6 @@ public class PartRenderingEngineTests { @Test public void testBug317849() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1496,11 +1318,7 @@ public class PartRenderingEngineTests { sharedSashContainer.getChildren().add(partStack); sharedSashContainer.setSelectedElement(partStack); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(partStack.getWidget()); assertNotNull(sharedSashContainer.getWidget()); @@ -1509,7 +1327,6 @@ public class PartRenderingEngineTests { @Test public void testBug326087() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1529,11 +1346,7 @@ public class PartRenderingEngineTests { MPart partB = ems.createModelElement(MPart.class); partStack.getChildren().add(partB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(partA.getWidget()); assertNull(partB.getWidget()); @@ -1550,7 +1363,6 @@ public class PartRenderingEngineTests { @Test public void testBug327701() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1587,11 +1399,7 @@ public class PartRenderingEngineTests { perspectiveB.getChildren().add(placeholderB); perspectiveB.setSelectedElement(placeholderB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); // select and activate the other perspective so that it is rendered and // appropriate references are generated and instantiated @@ -1607,7 +1415,6 @@ public class PartRenderingEngineTests { @Test public void testBug326699() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1646,11 +1453,7 @@ public class PartRenderingEngineTests { part2.setContributionURI("bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView"); partStack.getChildren().add(part2); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); EPartService partService = window.getContext().get(EPartService.class); partService.activate(part1); @@ -1669,7 +1472,6 @@ public class PartRenderingEngineTests { @Test public void testBug327807() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1685,11 +1487,7 @@ public class PartRenderingEngineTests { MPart part2 = ems.createModelElement(MPart.class); partStack.getChildren().add(part2); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertEquals(part1, partStack.getSelectedElement()); @@ -1699,7 +1497,6 @@ public class PartRenderingEngineTests { @Test public void testBug328629() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1708,18 +1505,13 @@ public class PartRenderingEngineTests { partSashContainer.setToBeRendered(false); window.getChildren().add(partSashContainer); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); partSashContainer.setToBeRendered(true); } @Test public void test331685() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1728,11 +1520,7 @@ public class PartRenderingEngineTests { window.getChildren().add(part); window.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); IPresentationEngine engine = appContext.get(IPresentationEngine.class); engine.removeGui(part); @@ -1744,7 +1532,6 @@ public class PartRenderingEngineTests { @Test public void testBug331795_1() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1754,11 +1541,7 @@ public class PartRenderingEngineTests { window.getChildren().add(part); window.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(part.getObject()); assertNotNull(part.getContext()); @@ -1775,7 +1558,6 @@ public class PartRenderingEngineTests { @Test public void testBug331795_2() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1785,11 +1567,7 @@ public class PartRenderingEngineTests { window.getChildren().add(part); window.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(part.getObject()); assertNotNull(part.getContext()); @@ -1806,7 +1584,6 @@ public class PartRenderingEngineTests { @Test public void testBug329079() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1815,17 +1592,11 @@ public class PartRenderingEngineTests { part.setVisible(false); window.getChildren().add(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); } @Test public void testRemoveGui_Bug332163() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1855,11 +1626,7 @@ public class PartRenderingEngineTests { perspective2.getChildren().add(partPlaceholder2); perspective2.setSelectedElement(partPlaceholder2); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); IEclipseContext perspectiveContext1 = perspective1.getContext(); IEclipseContext partContext = part.getContext(); @@ -1887,19 +1654,13 @@ public class PartRenderingEngineTests { @Test public void testBug334644_01() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - window.setToBeRendered(false); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(application); + contextRule.createAndRunWorkbench(window); assertNull("No widget for an unrendered window", window.getWidget()); assertNull("No context for an unrendered window", window.getContext()); @@ -1914,19 +1675,13 @@ public class PartRenderingEngineTests { @Test public void testBug334644_02() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - window.setToBeRendered(true); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull("Rendered window should have a widget", window.getWidget()); @@ -1941,8 +1696,6 @@ public class PartRenderingEngineTests { @Test public void testRemoveGui_Bug334577_01() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1958,11 +1711,7 @@ public class PartRenderingEngineTests { MWindow detachedWindow = ems.createModelElement(MWindow.class); perspective.getWindows().add(detachedWindow); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(detachedWindow.getContext()); assertNotNull(detachedWindow.getWidget()); @@ -1975,8 +1724,6 @@ public class PartRenderingEngineTests { @Test public void testRemoveGui_Bug334577_02() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -1984,11 +1731,7 @@ public class PartRenderingEngineTests { MWindow detachedWindow = ems.createModelElement(MWindow.class); window.getWindows().add(detachedWindow); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(detachedWindow.getContext()); assertNotNull(detachedWindow.getWidget()); @@ -2005,8 +1748,6 @@ public class PartRenderingEngineTests { */ @Test public void testBug336139() { - MApplication application = ems.createModelElement(MApplication.class); - MTrimmedWindow window = ems.createModelElement(MTrimmedWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2017,17 +1758,11 @@ public class PartRenderingEngineTests { MToolControl toolControl = ems.createModelElement(MToolControl.class); trimBar.getChildren().add(toolControl); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); } @Test public void testBut336225() { - MApplication application = ems.createModelElement(MApplication.class); - MTrimmedWindow window = ems.createModelElement(MTrimmedWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2039,11 +1774,7 @@ public class PartRenderingEngineTests { toolControl.setContributionURI(SampleToolControl.CONTRIBUTION_URI); trimBar.getChildren().add(toolControl); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); SampleToolControl impl = (SampleToolControl) toolControl.getObject(); @@ -2054,7 +1785,6 @@ public class PartRenderingEngineTests { @Test public void testBug330662() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2097,11 +1827,7 @@ public class PartRenderingEngineTests { perspectiveB.getChildren().add(placeholderB); perspectiveB.setSelectedElement(placeholderB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); EPartService partService = window.getContext().get(EPartService.class); partService.showPart(partB, PartState.ACTIVATE); @@ -2121,16 +1847,11 @@ public class PartRenderingEngineTests { */ @Test public void testBug335444_A() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MWindow detachedWindow = ems.createModelElement(MWindow.class); window.getWindows().add(detachedWindow); @@ -2146,7 +1867,6 @@ public class PartRenderingEngineTests { */ @Test public void testBug335444_B() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2159,11 +1879,7 @@ public class PartRenderingEngineTests { perspectiveStack.getChildren().add(perspective); perspectiveStack.setSelectedElement(perspective); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MWindow detachedWindow = ems.createModelElement(MWindow.class); perspective.getWindows().add(detachedWindow); @@ -2179,7 +1895,6 @@ public class PartRenderingEngineTests { */ @Test public void testBug335444_C() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2188,11 +1903,7 @@ public class PartRenderingEngineTests { detachedWindow.setToBeRendered(false); window.getWindows().add(detachedWindow); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); detachedWindow.setToBeRendered(true); @@ -2207,7 +1918,6 @@ public class PartRenderingEngineTests { */ @Test public void testBug335444_D() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2224,11 +1934,7 @@ public class PartRenderingEngineTests { detachedWindow.setToBeRendered(false); perspective.getWindows().add(detachedWindow); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); detachedWindow.setToBeRendered(true); @@ -2238,7 +1944,6 @@ public class PartRenderingEngineTests { } private void testBug326175(boolean visible) { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2247,11 +1952,7 @@ public class PartRenderingEngineTests { window.getChildren().add(part); window.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MWindow detachedWindow = ems.createModelElement(MWindow.class); detachedWindow.setVisible(visible); @@ -2282,7 +1983,6 @@ public class PartRenderingEngineTests { @Test public void testCreateGui_Bug319004() { - MApplication application = ems.createModelElement(MApplication.class); final MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2291,11 +1991,7 @@ public class PartRenderingEngineTests { window.getChildren().add(part); window.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MToolBar toolBar = ems.createModelElement(MToolBar.class); part.setToolbar(toolBar); @@ -2306,7 +2002,6 @@ public class PartRenderingEngineTests { @Test public void testBug339286() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2332,11 +2027,7 @@ public class PartRenderingEngineTests { MToolBar toolBarB = ems.createModelElement(MToolBar.class); partB.setToolbar(toolBarB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Widget widgetA = (Widget) toolBarA.getWidget(); Widget widgetB = (Widget) toolBarB.getWidget(); @@ -2357,7 +2048,6 @@ public class PartRenderingEngineTests { @Test public void testBug334580_01() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2402,11 +2092,7 @@ public class PartRenderingEngineTests { partStackB.getChildren().add(placeholderB); partStackB.setSelectedElement(placeholderB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Shell limboShell = (Shell) appContext.get("limbo"); assertNotNull(limboShell); @@ -2433,7 +2119,6 @@ public class PartRenderingEngineTests { @Test public void testBug334580_02() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2459,11 +2144,7 @@ public class PartRenderingEngineTests { MToolBar toolBarB = ems.createModelElement(MToolBar.class); partB.setToolbar(toolBarB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Shell limboShell = (Shell) appContext.get("limbo"); assertNotNull(limboShell); @@ -2494,7 +2175,6 @@ public class PartRenderingEngineTests { @Test public void testBug334580_03() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2510,11 +2190,7 @@ public class PartRenderingEngineTests { MPart partB = ems.createModelElement(MPart.class); partStack.getChildren().add(partB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Shell limboShell = (Shell) appContext.get("limbo"); assertNotNull(limboShell); @@ -2529,7 +2205,6 @@ public class PartRenderingEngineTests { @Test public void testBug342439_01() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2546,11 +2221,7 @@ public class PartRenderingEngineTests { partStack.getChildren().add(partB); partStack.setSelectedElement(partB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder folder = (CTabFolder) partStack.getWidget(); assertEquals(1, folder.getItemCount()); @@ -2569,7 +2240,6 @@ public class PartRenderingEngineTests { @Test public void testBug342439_02() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2586,11 +2256,7 @@ public class PartRenderingEngineTests { partStack.getChildren().add(partB); partStack.setSelectedElement(partB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder folder = (CTabFolder) partStack.getWidget(); assertEquals(1, folder.getItemCount()); @@ -2607,7 +2273,6 @@ public class PartRenderingEngineTests { @Test public void testBug342366() throws Exception { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2623,11 +2288,7 @@ public class PartRenderingEngineTests { partStack.getChildren().add(partB); partStack.setSelectedElement(partB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); CTabFolder folder = (CTabFolder) partStack.getWidget(); assertEquals(2, folder.getItemCount()); @@ -2643,8 +2304,6 @@ public class PartRenderingEngineTests { @Test public void testBug343305() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2686,11 +2345,7 @@ public class PartRenderingEngineTests { placeholderB.setRef(part); partStackB.getChildren().add(placeholderB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); EPartService partService = window.getContext().get(EPartService.class); partService.switchPerspective(perspectiveB); @@ -2708,8 +2363,6 @@ public class PartRenderingEngineTests { @Test public void testBug343442() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2739,11 +2392,7 @@ public class PartRenderingEngineTests { partStack.getChildren().add(placeholder); partStack.setSelectedElement(placeholder); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); partStack.getChildren().remove(placeholder); partStack.getChildren().add(placeholder); @@ -2756,8 +2405,6 @@ public class PartRenderingEngineTests { @Test public void testBug343524() { - MApplication application = ems.createModelElement(MApplication.class); - MTrimmedWindow window = ems.createModelElement(MTrimmedWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2765,11 +2412,7 @@ public class PartRenderingEngineTests { MTrimBar trimBar = ems.createModelElement(MTrimBar.class); window.getTrimBars().add(trimBar); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(trimBar.getWidget()); @@ -2782,8 +2425,6 @@ public class PartRenderingEngineTests { @Test public void ensureCleanUpAddonCleansUp() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2823,29 +2464,25 @@ public class PartRenderingEngineTests { partStackForEditor.getChildren().add(editor); partStackForEditor.setSelectedElement(editor); - application.setContext(appContext); - appContext.set(MApplication.class, application); - ContextInjectionFactory.make(CleanupAddon.class, appContext); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); EPartService partService = window.getContext().get(EPartService.class); partService.hidePart(partA); - spinEventLoop(); + contextRule.spinEventLoop(); assertTrue(" PartStack with children should be rendered", partStackForPartBPartC.isToBeRendered()); partService.hidePart(partB); partService.hidePart(partC); - spinEventLoop(); + contextRule.spinEventLoop(); assertTrue("CleanupAddon should ensure that partStack is not rendered anymore, as all childs have been removed", !partStackForPartBPartC.isToBeRendered()); assertTrue("Part stack should be removed", !partStackForPartBPartC.isToBeRendered()); // PartStack with IPresentationEngine.NO_AUTO_COLLAPSE should not be removed // even if children are removed partService.hidePart(editor, true); - spinEventLoop(); + contextRule.spinEventLoop(); assertTrue("PartStack with IPresentationEngine.NO_AUTO_COLLAPSE should not be closed if children are removed", partStackForEditor.isToBeRendered()); @@ -2853,8 +2490,6 @@ public class PartRenderingEngineTests { @Test public void testBug332463() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2887,23 +2522,19 @@ public class PartRenderingEngineTests { partStackB.getChildren().add(partC); partStackB.setSelectedElement(partC); - application.setContext(appContext); - appContext.set(MApplication.class, application); - ContextInjectionFactory.make(CleanupAddon.class, appContext); - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); EPartService partService = window.getContext().get(EPartService.class); partService.hidePart(partB); - spinEventLoop(); + contextRule.spinEventLoop(); partService.hidePart(partA, true); - spinEventLoop(); + contextRule.spinEventLoop(); partService.hidePart(partC, true); - spinEventLoop(); + contextRule.spinEventLoop(); assertNotNull(area.getWidget()); assertTrue(area.isToBeRendered()); @@ -2911,8 +2542,6 @@ public class PartRenderingEngineTests { @Test public void testBug348215_PartOnlyContextReparent() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2925,11 +2554,7 @@ public class PartRenderingEngineTests { detachedWindow.getChildren().add(part); detachedWindow.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertTrue(part.getContext() != null); assertTrue(part.getContext().getParent() == detachedWindow.getContext()); @@ -2943,8 +2568,6 @@ public class PartRenderingEngineTests { @Test public void testBug348215_PartContextReparent() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -2961,11 +2584,7 @@ public class PartRenderingEngineTests { stack.getChildren().add(part); stack.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertTrue(part.getContext() != null); assertTrue(part.getContext().getParent() == detachedWindow.getContext()); @@ -2979,8 +2598,6 @@ public class PartRenderingEngineTests { @Test public void testBug348215_PartPlaceholderContextReparent() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -3001,11 +2618,7 @@ public class PartRenderingEngineTests { stack.getChildren().add(ph); stack.setSelectedElement(ph); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertTrue(part.getContext() != null); assertTrue(part.getContext().getParent() == detachedWindow.getContext()); @@ -3019,8 +2632,6 @@ public class PartRenderingEngineTests { @Test public void testBug349076() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -3046,11 +2657,7 @@ public class PartRenderingEngineTests { detachedWindow.getChildren().add(detachedStack); detachedWindow.setSelectedElement(detachedStack); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertTrue(part.getContext() != null); assertTrue(part.getContext().getParent() == window.getContext()); @@ -3083,13 +2690,8 @@ public class PartRenderingEngineTests { partB.setContributionURI(LayoutView.CONTRIBUTION_URI); innerContainer.getChildren().add(partB); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(partA.getWidget()); assertNotNull(partB.getWidget()); @@ -3097,8 +2699,6 @@ public class PartRenderingEngineTests { @Test public void testBug348069_01() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -3108,11 +2708,7 @@ public class PartRenderingEngineTests { window.getChildren().add(part); window.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); SampleView view = (SampleView) part.getObject(); assertFalse(view.isDestroyed()); @@ -3124,8 +2720,6 @@ public class PartRenderingEngineTests { @Test public void testBug348069_02() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow windowA = ems.createModelElement(MWindow.class); application.getChildren().add(windowA); application.setSelectedElement(windowA); @@ -3143,12 +2737,8 @@ public class PartRenderingEngineTests { windowB.getChildren().add(partB); windowB.setSelectedElement(partB); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(windowA); - wb.createAndRunUI(windowB); + contextRule.createAndRunWorkbench(windowA); + contextRule.createAndRunWorkbench(windowB); SampleView viewA = (SampleView) partA.getObject(); assertFalse(viewA.isDestroyed()); @@ -3168,8 +2758,6 @@ public class PartRenderingEngineTests { @Test public void testBug348069_DetachedWindow_01() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -3182,11 +2770,7 @@ public class PartRenderingEngineTests { detachedWindow.getChildren().add(part); detachedWindow.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); SampleView view = (SampleView) part.getObject(); assertFalse(view.isDestroyed()); @@ -3198,8 +2782,6 @@ public class PartRenderingEngineTests { @Test public void testBug348069_DetachedWindow_02() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -3212,11 +2794,7 @@ public class PartRenderingEngineTests { detachedWindow.getChildren().add(part); detachedWindow.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); SampleView view = (SampleView) part.getObject(); assertFalse(view.isDestroyed()); @@ -3232,8 +2810,6 @@ public class PartRenderingEngineTests { @Test public void testBug348069_DetachedWindow_03() { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -3246,11 +2822,7 @@ public class PartRenderingEngineTests { detachedWindow.getChildren().add(part); detachedWindow.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); SampleView view = (SampleView) part.getObject(); assertFalse(view.isDestroyed()); @@ -3262,8 +2834,6 @@ public class PartRenderingEngineTests { private void testBug348069_DetachedPerspectiveWindow_01( boolean createPlaceholder) { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -3300,11 +2870,7 @@ public class PartRenderingEngineTests { partStack.setSelectedElement(part); } - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); SampleView view = (SampleView) part.getObject(); assertFalse(view.isDestroyed()); @@ -3326,8 +2892,6 @@ public class PartRenderingEngineTests { private void testBug348069_DetachedPerspectiveWindow_02( boolean createPlaceholder) { - MApplication application = ems.createModelElement(MApplication.class); - MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -3365,11 +2929,7 @@ public class PartRenderingEngineTests { partStack.setSelectedElement(part); } - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); SampleView view = (SampleView) part.getObject(); assertFalse(view.isDestroyed()); @@ -3411,13 +2971,8 @@ public class PartRenderingEngineTests { part.setVisible(false); stack.getChildren().add(part); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); stack.setSelectedElement(part); assertFalse(logged); @@ -3427,13 +2982,8 @@ public class PartRenderingEngineTests { public void testBug372226() { MWindow window = ems.createModelElement(MWindow.class); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Shell subShell = new Shell((Shell) window.getWidget()); @@ -3464,13 +3014,8 @@ public class PartRenderingEngineTests { MToolControl dummyToolControl = ems.createModelElement(MToolControl.class); toolBar.getChildren().add(dummyToolControl); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); MToolControl toolControl = ems.createModelElement(MToolControl.class); toolControl.setVisible(false); @@ -3516,20 +3061,14 @@ public class PartRenderingEngineTests { perspectiveStack.getChildren().add(perspective); perspectiveStack.setSelectedElement(perspective); - MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertFalse(logged); } @Test public void test_persistState_371087() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -3539,11 +3078,7 @@ public class PartRenderingEngineTests { window.getChildren().add(part); window.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(part.getObject()); assertNotNull(part.getContext()); @@ -3561,7 +3096,6 @@ public class PartRenderingEngineTests { @Test public void test_persistState_371087_1() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -3571,11 +3105,7 @@ public class PartRenderingEngineTests { window.getChildren().add(part); window.setSelectedElement(part); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); assertNotNull(part.getObject()); assertNotNull(part.getContext()); @@ -3593,7 +3123,6 @@ public class PartRenderingEngineTests { @Test public void testCurSharedRefBug457939() { - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); application.getChildren().add(window); application.setSelectedElement(window); @@ -3641,11 +3170,7 @@ public class PartRenderingEngineTests { assertEquals(placeholderA, part.getCurSharedRef()); - application.setContext(appContext); - appContext.set(MApplication.class, application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); + contextRule.createAndRunWorkbench(window); Shell limboShell = (Shell) appContext.get("limbo"); assertNotNull(limboShell); diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererTest.java index 3c5cc165a7e..b448fb16a60 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererTest.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2017 IBM Corporation and others. + * Copyright (c) 2013, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Rolf Theunissen <rolf.theunissen@gmail.com> - Bug 546632 ******************************************************************************/ package org.eclipse.e4.ui.workbench.renderers.swt; @@ -23,11 +24,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import javax.inject.Inject; import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.ui.internal.workbench.E4Workbench; import org.eclipse.e4.ui.internal.workbench.swt.CSSConstants; -import org.eclipse.e4.ui.internal.workbench.swt.E4Application; -import org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder; import org.eclipse.e4.ui.model.application.ui.basic.MPart; @@ -35,29 +34,34 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; import org.eclipse.e4.ui.model.application.ui.basic.MWindow; import org.eclipse.e4.ui.services.IStylingEngine; import org.eclipse.e4.ui.services.internal.events.EventBroker; -import org.eclipse.e4.ui.workbench.IWorkbench; +import org.eclipse.e4.ui.tests.rules.WorkbenchContextRule; import org.eclipse.e4.ui.workbench.UIEvents; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.swt.custom.CTabItem; -import org.eclipse.swt.widgets.Display; -import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; public class StackRendererTest { + + @Rule + public WorkbenchContextRule contextRule = new WorkbenchContextRule(); + + @Inject private IEclipseContext context; - private E4Workbench wb; + + @Inject + private EModelService ems; + + @Inject + private MApplication application; + private MPart part; private CTabItemStylingMethodsListener executedMethodsListener; private MPartStack partStack; - private EModelService ems; @Before public void setUp() throws Exception { - context = E4Application.createDefaultContext(); - context.set(IWorkbench.PRESENTATION_URI_ARG, PartRenderingEngine.engineURI); - ems = context.get(EModelService.class); - MApplication application = ems.createModelElement(MApplication.class); MWindow window = ems.createModelElement(MWindow.class); partStack = ems.createModelElement(MPartStack.class); part = ems.createModelElement(MPart.class); @@ -69,30 +73,12 @@ public class StackRendererTest { window.getChildren().add(partStack); partStack.getChildren().add(part); - application.setContext(context); - context.set(MApplication.class, application); - executedMethodsListener = new CTabItemStylingMethodsListener(part); - wb = new E4Workbench(application, context); - wb.getContext().set( - IStylingEngine.class, - (IStylingEngine) Proxy.newProxyInstance(getClass() - .getClassLoader(), - new Class<?>[] { IStylingEngine.class }, - executedMethodsListener)); - - wb.createAndRunUI(window); - while (Display.getDefault().readAndDispatch()) { - } - } + context.set(IStylingEngine.class, (IStylingEngine) Proxy.newProxyInstance(getClass().getClassLoader(), + new Class<?>[] { IStylingEngine.class }, executedMethodsListener)); - @After - public void tearDown() throws Exception { - if (wb != null) { - wb.close(); - } - context.dispose(); + contextRule.createAndRunWorkbench(window); } @Test |
