diff options
| author | Thibault Le Ouay | 2014-11-05 22:17:52 +0000 |
|---|---|---|
| committer | Lars Vogel | 2014-11-11 09:02:08 +0000 |
| commit | f7fe273e71f9d6cfff95140e445fc763dacaf1ec (patch) | |
| tree | 323a507118fb8f09c48c511e99f790a67329a6ad | |
| parent | 79a9f3167b96c259f9efc41c4e2409f9fce2def1 (diff) | |
| download | eclipse.platform.ui-f7fe273e71f9d6cfff95140e445fc763dacaf1ec.tar.gz eclipse.platform.ui-f7fe273e71f9d6cfff95140e445fc763dacaf1ec.tar.xz eclipse.platform.ui-f7fe273e71f9d6cfff95140e445fc763dacaf1ec.zip | |
Bug 450209 - [Tests] Migrate org.eclipse.e4.core.commands.tests to
JUnit4
Change-Id: I649242d8a0838ecda478398183fc91fca685f156
Signed-off-by: Thibault Le Ouay <thibaultleouay@gmail.com>
6 files changed, 210 insertions, 159 deletions
diff --git a/tests/org.eclipse.e4.core.commands.tests/E4Command Tests Suite.launch b/tests/org.eclipse.e4.core.commands.tests/E4Command Tests Suite.launch new file mode 100644 index 00000000000..fcbdd460400 --- /dev/null +++ b/tests/org.eclipse.e4.core.commands.tests/E4Command Tests Suite.launch @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig"> +<stringAttribute key="application" value="org.eclipse.pde.junit.runtime.coretestapplication"/> +<booleanAttribute key="askclear" value="false"/> +<booleanAttribute key="automaticAdd" value="true"/> +<booleanAttribute key="automaticValidate" value="false"/> +<stringAttribute key="bootstrap" value=""/> +<stringAttribute key="checked" value="[NONE]"/> +<booleanAttribute key="clearConfig" value="true"/> +<booleanAttribute key="clearws" value="true"/> +<booleanAttribute key="clearwslog" value="false"/> +<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/> +<booleanAttribute key="default" value="true"/> +<booleanAttribute key="includeOptional" value="true"/> +<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> +<listEntry value="/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/CommandTestSuite.java"/> +</listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> +<listEntry value="1"/> +</listAttribute> +<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> +<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> +<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> +<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/> +<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> +<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> +<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.e4.core.commands.tests.CommandTestSuite"/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.e4.core.commands.tests"/> +<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> +<stringAttribute key="pde.version" value="3.3"/> +<booleanAttribute key="run_in_ui_thread" value="true"/> +<booleanAttribute key="show_selected_only" value="false"/> +<stringAttribute key="templateConfig" value=""/> +<booleanAttribute key="tracing" value="false"/> +<booleanAttribute key="useCustomFeatures" value="false"/> +<booleanAttribute key="useDefaultConfig" value="true"/> +<booleanAttribute key="useDefaultConfigArea" value="false"/> +<booleanAttribute key="useProduct" value="false"/> +</launchConfiguration> diff --git a/tests/org.eclipse.e4.core.commands.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.e4.core.commands.tests/META-INF/MANIFEST.MF index ba435ed94fa..e3e9423f338 100644 --- a/tests/org.eclipse.e4.core.commands.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.e4.core.commands.tests/META-INF/MANIFEST.MF @@ -4,11 +4,11 @@ Bundle-Name: Core commands Tests (Incubation) Bundle-SymbolicName: org.eclipse.e4.core.commands.tests;singleton:=true Bundle-Version: 0.10.100.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.eclipse.core.commands;bundle-version="3.5.0", - org.eclipse.e4.core.commands;bundle-version="0.9.0", - org.eclipse.core.runtime;bundle-version="3.4.0", +Require-Bundle: org.eclipse.core.commands, + org.eclipse.e4.core.commands, + org.eclipse.core.runtime, org.junit, - org.eclipse.e4.core.di;bundle-version="0.9.0" + org.eclipse.e4.core.di Import-Package: javax.inject;version="1.0.0", org.eclipse.e4.core.contexts, org.osgi.framework;version="1.5.0", diff --git a/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/CommandTestSuite.java b/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/CommandTestSuite.java index 7c9e89cdb91..9e7b1c99a83 100644 --- a/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/CommandTestSuite.java +++ b/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/CommandTestSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 IBM Corporation and others. + * Copyright (c) 2013, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,19 +7,18 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 450209 *******************************************************************************/ package org.eclipse.e4.core.commands.tests; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ DefineCommandsTest.class, HandlerTest.class }) +public class CommandTestSuite { -public class CommandTestSuite extends TestSuite { - public static Test suite() { - return new CommandTestSuite(); - } - public CommandTestSuite() { - addTestSuite(DefineCommandsTest.class); - addTestSuite(HandlerTest.class); } } diff --git a/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/DefineCommandsTest.java b/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/DefineCommandsTest.java index c49ae59346e..be2ac24911b 100644 --- a/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/DefineCommandsTest.java +++ b/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/DefineCommandsTest.java @@ -8,94 +8,105 @@ * Contributors: * IBM Corporation - initial API and implementation * Lars Vogel <Lars.Vogel@gmail.com> - Bug 431667, 440893 + * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 450209 *******************************************************************************/ package org.eclipse.e4.core.commands.tests; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; import org.eclipse.core.commands.Category; import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.e4.core.commands.CommandServiceAddon; import org.eclipse.e4.core.commands.ECommandService; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.IEclipseContext; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; -public class DefineCommandsTest extends TestCase { +public class DefineCommandsTest { private static final String TEST_ID2 = "test.id2"; private static final String TEST_ID1 = "test.id1"; private static final String TEST_CAT1 = "test.cat1"; - public void testCreateCommands() throws Exception { + private IEclipseContext workbenchContext; + + @Before + public void setUp() { + IEclipseContext globalContext = TestActivator.getDefault().getGlobalContext(); + workbenchContext = globalContext.createChild("workbenchContext"); + ContextInjectionFactory.make(CommandServiceAddon.class, workbenchContext); + } + + @After + public void tearDown() { + workbenchContext.dispose(); + } + + @Test + public void testCreateCommands() { ECommandService cs = workbenchContext.get(ECommandService.class); assertNotNull(cs); assertNotNull(cs.defineCategory(TEST_CAT1, "CAT1", null)); Category category = cs.getCategory(TEST_CAT1); assertNotNull("need category", category); - assertNotNull("command1", cs.defineCommand(TEST_ID1, "ID1", null, - category, null)); - assertNotNull("command2", cs.defineCommand(TEST_ID2, "ID2", null, - category, null)); - + assertNotNull("command1", cs.defineCommand(TEST_ID1, "ID1", null, category, null)); + assertNotNull("command2", cs.defineCommand(TEST_ID2, "ID2", null, category, null)); Command cmd1 = cs.getCommand(TEST_ID1); assertNotNull("get command1", cmd1); - assertEquals("ID1", cmd1.getName()); + try { + assertEquals("ID1", cmd1.getName()); + } catch (NotDefinedException e) { + fail(e.getMessage()); + } assertNotNull("get command2", cs.getCommand(TEST_ID2)); - assertNotNull("parameterized command", cs.createCommand(TEST_ID1, null)); } - public void testCreateWithSecondContexts() throws Exception { + @Test + public void testCreateWithSecondContexts() { IEclipseContext localContext = workbenchContext.createChild(); - ECommandService cs = localContext - .get(ECommandService.class); + ECommandService cs = localContext.get(ECommandService.class); assertNotNull(cs); assertNotNull(cs.defineCategory(TEST_CAT1, "CAT1", null)); Category category = cs.getCategory(TEST_CAT1); assertNotNull("need category", category); - assertNotNull("command1", cs.defineCommand(TEST_ID1, "ID1", null, - category, null)); - assertNotNull("command2", cs.defineCommand(TEST_ID2, "ID2", null, - category, null)); + assertNotNull("command1", cs.defineCommand(TEST_ID1, "ID1", null, category, null)); + assertNotNull("command2", cs.defineCommand(TEST_ID2, "ID2", null, category, null)); Command cmd1 = cs.getCommand(TEST_ID1); assertNotNull("get command1", cmd1); - assertEquals("ID1", cmd1.getName()); + try { + assertEquals("ID1", cmd1.getName()); + } catch (NotDefinedException e) { + fail(e.getMessage()); + } assertNotNull("get command2", cs.getCommand(TEST_ID2)); } - public void testCreateWithTwoContexts() throws Exception { + @Test + public void testCreateWithTwoContexts() { IEclipseContext localContext = workbenchContext.createChild("Level1"); - ECommandService cs = localContext - .get(ECommandService.class); + ECommandService cs = localContext.get(ECommandService.class); assertNotNull(cs); assertNotNull(cs.defineCategory(TEST_CAT1, "CAT1", null)); Category category = cs.getCategory(TEST_CAT1); assertNotNull("need category", category); - assertNotNull("command1", cs.defineCommand(TEST_ID1, "ID1", null, - category, null)); - assertNotNull("command2", cs.defineCommand(TEST_ID2, "ID2", null, - category, null)); + assertNotNull("command1", cs.defineCommand(TEST_ID1, "ID1", null, category, null)); + assertNotNull("command2", cs.defineCommand(TEST_ID2, "ID2", null, category, null)); - cs = (ECommandService) workbenchContext.get(ECommandService.class - .getName()); + cs = (ECommandService) workbenchContext.get(ECommandService.class.getName()); Command cmd1 = cs.getCommand(TEST_ID1); assertNotNull("get command1", cmd1); - assertEquals("ID1", cmd1.getName()); + try { + assertEquals("ID1", cmd1.getName()); + } catch (NotDefinedException e) { + fail(e.getMessage()); + } assertNotNull("get command2", cs.getCommand(TEST_ID2)); } - - private IEclipseContext workbenchContext; - - @Override - protected void setUp() throws Exception { - IEclipseContext globalContext = TestActivator.getDefault().getGlobalContext(); - workbenchContext = globalContext.createChild("workbenchContext"); - ContextInjectionFactory.make(CommandServiceAddon.class, workbenchContext); - } - - @Override - protected void tearDown() throws Exception { - workbenchContext.dispose(); - } } diff --git a/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/HandlerTest.java b/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/HandlerTest.java index ebbb59c9635..ee9997a3ae4 100644 --- a/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/HandlerTest.java +++ b/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/HandlerTest.java @@ -8,16 +8,20 @@ * Contributors: * IBM Corporation - initial API and implementation * Lars Vogel <Lars.Vogel@gmail.com> - Bug 431667, 440893 + * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 450209 ******************************************************************************/ package org.eclipse.e4.core.commands.tests; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.util.Collections; import java.util.Map; import javax.inject.Named; -import junit.framework.TestCase; - import org.eclipse.core.commands.Category; import org.eclipse.core.commands.IParameter; import org.eclipse.core.commands.IParameterValues; @@ -31,8 +35,11 @@ import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.annotations.CanExecute; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.core.di.annotations.Optional; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; -public class HandlerTest extends TestCase { +public class HandlerTest { private static final String ACTIVE_INFO_ID = "activeInfo"; private static final String TEST_ID3 = "test.id3"; @@ -40,35 +47,29 @@ public class HandlerTest extends TestCase { private static final String TEST_ID1 = "test.id1"; private static final String TEST_CAT1 = "test.cat1"; - static class CallHandler { - public boolean q1; - public boolean q2; + private IEclipseContext workbenchContext; - @CanExecute - public boolean canExecute() { - q1 = true; - return true; - } + @Before + public void setUp() { + IEclipseContext globalContext = TestActivator.getDefault().getGlobalContext(); + workbenchContext = globalContext.createChild("workbenchContext"); + ContextInjectionFactory.make(CommandServiceAddon.class, workbenchContext); + defineCommands(workbenchContext); + } - @Execute - public Object execute() { - q2 = true; - if (q1) { - return Boolean.TRUE; - } - return Boolean.FALSE; - } + @After + public void tearDown() { + workbenchContext.dispose(); } + @Test public void testCallHandler() throws Exception { - EHandlerService hs = workbenchContext - .get(EHandlerService.class); + EHandlerService hs = workbenchContext.get(EHandlerService.class); CallHandler handler = new CallHandler(); hs.activateHandler(TEST_ID1, handler); assertFalse(handler.q1); assertFalse(handler.q2); - ECommandService cs = workbenchContext - .get(ECommandService.class); + ECommandService cs = workbenchContext.get(ECommandService.class); ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null); assertTrue(hs.canExecute(cmd)); assertFalse(handler.q2); @@ -77,15 +78,14 @@ public class HandlerTest extends TestCase { assertTrue(handler.q2); } + @Test public void testDeactivateHandler() throws Exception { - EHandlerService hs = workbenchContext - .get(EHandlerService.class); + EHandlerService hs = workbenchContext.get(EHandlerService.class); CallHandler handler = new CallHandler(); hs.activateHandler(TEST_ID1, handler); assertFalse(handler.q1); assertFalse(handler.q2); - ECommandService cs = workbenchContext - .get(ECommandService.class); + ECommandService cs = workbenchContext.get(ECommandService.class); ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null); assertTrue(hs.canExecute(cmd)); assertFalse(handler.q2); @@ -95,39 +95,34 @@ public class HandlerTest extends TestCase { assertFalse(handler.q2); } + @Test public void testActiveHandlerExecuteWorkbench() throws Exception { IEclipseContext c1 = workbenchContext.createChild("c1"); c1.activate(); - EHandlerService h1 = c1.get(EHandlerService.class - ); + EHandlerService h1 = c1.get(EHandlerService.class); CallHandler handler1 = new CallHandler(); h1.activateHandler(TEST_ID1, handler1); - ECommandService cs = c1.get(ECommandService.class - ); + ECommandService cs = c1.get(ECommandService.class); ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null); assertTrue(h1.canExecute(cmd)); - EHandlerService wHS = workbenchContext - .get(EHandlerService.class); + EHandlerService wHS = workbenchContext.get(EHandlerService.class); assertTrue(wHS.canExecute(cmd)); } + @Test public void testQueryTwoHandlers() throws Exception { - ECommandService cs = workbenchContext - .get(ECommandService.class); + ECommandService cs = workbenchContext.get(ECommandService.class); ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null); - EHandlerService wHS = workbenchContext - .get(EHandlerService.class); + EHandlerService wHS = workbenchContext.get(EHandlerService.class); IEclipseContext c1 = workbenchContext.createChild("c1"); c1.activate(); - EHandlerService h1 = c1.get(EHandlerService.class - ); + EHandlerService h1 = c1.get(EHandlerService.class); CallHandler handler1 = new CallHandler(); h1.activateHandler(TEST_ID1, handler1); IEclipseContext c2 = workbenchContext.createChild("c2"); - EHandlerService h2 = c2.get(EHandlerService.class - ); + EHandlerService h2 = c2.get(EHandlerService.class); CallHandler handler2 = new CallHandler(); h2.activateHandler(TEST_ID1, handler2); @@ -140,23 +135,20 @@ public class HandlerTest extends TestCase { assertFalse(handler2.q2); } + @Test public void testExecuteTwoActiveHandlers() throws Exception { - ECommandService cs = workbenchContext - .get(ECommandService.class); + ECommandService cs = workbenchContext.get(ECommandService.class); ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null); - EHandlerService wHS = workbenchContext - .get(EHandlerService.class); + EHandlerService wHS = workbenchContext.get(EHandlerService.class); IEclipseContext c1 = workbenchContext.createChild("c1"); c1.activate(); - EHandlerService h1 = c1.get(EHandlerService.class - ); + EHandlerService h1 = c1.get(EHandlerService.class); CallHandler handler1 = new CallHandler(); h1.activateHandler(TEST_ID1, handler1); IEclipseContext c2 = workbenchContext.createChild("c2"); - EHandlerService h2 = c2.get(EHandlerService.class - ); + EHandlerService h2 = c2.get(EHandlerService.class); CallHandler handler2 = new CallHandler(); h2.activateHandler(TEST_ID1, handler2); @@ -174,23 +166,20 @@ public class HandlerTest extends TestCase { assertFalse(handler2.q2); } + @Test public void testSwitchActivationTwoHandlers() throws Exception { - ECommandService cs = workbenchContext - .get(ECommandService.class); + ECommandService cs = workbenchContext.get(ECommandService.class); ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null); - EHandlerService wHS = workbenchContext - .get(EHandlerService.class); + EHandlerService wHS = workbenchContext.get(EHandlerService.class); IEclipseContext c1 = workbenchContext.createChild("c1"); c1.activate(); - EHandlerService h1 = c1.get(EHandlerService.class - ); + EHandlerService h1 = c1.get(EHandlerService.class); CallHandler handler1 = new CallHandler(); h1.activateHandler(TEST_ID1, handler1); IEclipseContext c2 = workbenchContext.createChild("c2"); - EHandlerService h2 = c2.get(EHandlerService.class - ); + EHandlerService h2 = c2.get(EHandlerService.class); CallHandler handler2 = new CallHandler(); h2.activateHandler(TEST_ID1, handler2); @@ -256,53 +245,50 @@ public class HandlerTest extends TestCase { } } + @Test public void testMethodInfo() throws Exception { Info helloInfo = new Info("Hello"); workbenchContext.set(Info.class, helloInfo); - ECommandService cs = workbenchContext - .get(ECommandService.class); + ECommandService cs = workbenchContext.get(ECommandService.class); ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null); - EHandlerService wHS = workbenchContext - .get(EHandlerService.class); + EHandlerService wHS = workbenchContext.get(EHandlerService.class); HandlerWithInfo handler = new HandlerWithInfo(); wHS.activateHandler(TEST_ID1, handler); assertEquals(helloInfo, wHS.executeHandler(cmd)); } + @Test public void testMethodWithAnnocation() throws Exception { Info helloInfo = new Info("Hello"); - ECommandService cs = workbenchContext - .get(ECommandService.class); + ECommandService cs = workbenchContext.get(ECommandService.class); ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null); - EHandlerService wHS = workbenchContext - .get(EHandlerService.class); + EHandlerService wHS = workbenchContext.get(EHandlerService.class); HandlerWithAnnotations handler = new HandlerWithAnnotations(); wHS.activateHandler(TEST_ID1, handler); workbenchContext.set(Info.class, helloInfo); assertNull(wHS.executeHandler(cmd)); - + workbenchContext.remove(Info.class); assertNull(wHS.executeHandler(cmd)); - + workbenchContext.set(ACTIVE_INFO_ID, helloInfo); assertEquals(helloInfo, wHS.executeHandler(cmd)); - + workbenchContext.remove(ACTIVE_INFO_ID); assertNull(wHS.executeHandler(cmd)); } + @Test public void testBug314847() { - ECommandService cs = workbenchContext - .get(ECommandService.class); - EHandlerService wHS = workbenchContext - .get(EHandlerService.class); + ECommandService cs = workbenchContext.get(ECommandService.class); + EHandlerService wHS = workbenchContext.get(EHandlerService.class); ParameterizedCommand nonparameterizedCmd = cs.createCommand(TEST_ID3, null); ParameterizedCommand parameterizedCmd = cs.createCommand(TEST_ID3, - Collections.singletonMap(ACTIVE_INFO_ID, (Object)"param")); - + Collections.singletonMap(ACTIVE_INFO_ID, (Object) "param")); + HandlerWithParams handler = new HandlerWithParams(); wHS.activateHandler(TEST_ID3, handler); @@ -315,49 +301,58 @@ public class HandlerTest extends TestCase { assertEquals(null, wHS.executeHandler(nonparameterizedCmd)); } - private IEclipseContext workbenchContext; - - @Override - protected void setUp() throws Exception { - IEclipseContext globalContext = TestActivator.getDefault().getGlobalContext(); - workbenchContext = globalContext.createChild("workbenchContext"); - ContextInjectionFactory.make(CommandServiceAddon.class, workbenchContext); - defineCommands(workbenchContext); - } - - @Override - protected void tearDown() throws Exception { - workbenchContext.dispose(); - } - private void defineCommands(IEclipseContext context) { - ECommandService cs = workbenchContext - .get(ECommandService.class); + ECommandService cs = workbenchContext.get(ECommandService.class); Category category = cs.defineCategory(TEST_CAT1, "CAT1", null); cs.defineCommand(TEST_ID1, "ID1", null, category, null); cs.defineCommand(TEST_ID2, "ID2", null, category, null); cs.defineCommand(TEST_ID3, "ID3", null, category, new IParameter[] { new IParameter() { - + + @Override public boolean isOptional() { return true; } - + + @Override public IParameterValues getValues() throws ParameterValuesException { return new IParameterValues() { - + + @Override public Map<?, ?> getParameterValues() { return Collections.EMPTY_MAP; } }; } - + + @Override public String getName() { return ACTIVE_INFO_ID; } - + + @Override public String getId() { return ACTIVE_INFO_ID; } - }}); + } }); + } + + static class CallHandler { + public boolean q1; + public boolean q2; + + @CanExecute + public boolean canExecute() { + q1 = true; + return true; + } + + @Execute + public Object execute() { + q2 = true; + if (q1) { + return Boolean.TRUE; + } + return Boolean.FALSE; + } } } diff --git a/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/TestActivator.java b/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/TestActivator.java index af69878c3f5..46e85370642 100644 --- a/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/TestActivator.java +++ b/tests/org.eclipse.e4.core.commands.tests/src/org/eclipse/e4/core/commands/tests/TestActivator.java @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Lars Vogel <Lars.Vogel@gmail.com> - Bug 431667, 440893 + * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 450209 *******************************************************************************/ package org.eclipse.e4.core.commands.tests; @@ -30,6 +31,7 @@ public class TestActivator implements BundleActivator { return plugin; } + @Override public void start(BundleContext context) throws Exception { plugin = this; serviceContext = EclipseContextFactory.getServiceContext(context); @@ -40,10 +42,12 @@ public class TestActivator implements BundleActivator { private void addLogService(IEclipseContext context) { context.set(LogService.class, new LogService() { + @Override public void log(int level, String message) { System.out.println(level + ": " + message); } + @Override public void log(int level, String message, Throwable exception) { System.out.println(level + ": " + message); if (exception != null) { @@ -51,19 +55,21 @@ public class TestActivator implements BundleActivator { } } + @SuppressWarnings("rawtypes") + @Override public void log(ServiceReference sr, int level, String message) { - // TODO Auto-generated method stub - + // Nothing } - public void log(ServiceReference sr, int level, String message, - Throwable exception) { - // TODO Auto-generated method stub - + @SuppressWarnings("rawtypes") + @Override + public void log(ServiceReference sr, int level, String message, Throwable exception) { + // Nothing } }); } + @Override public void stop(BundleContext context) throws Exception { serviceContext.dispose(); plugin = null; |
