diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/.gitignore b/runtime/tests/org.eclipse.e4.core.javax.tests/.gitignore
deleted file mode 100644
index c59ea270aa5..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-OSGI-INF/*.xml
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/.project b/runtime/tests/org.eclipse.e4.core.javax.tests/.project
index bc2c0c6a994..f3421cb94f8 100644
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/.project
+++ b/runtime/tests/org.eclipse.e4.core.javax.tests/.project
@@ -20,11 +20,6 @@
-
- org.eclipse.pde.ds.core.builder
-
-
-
org.eclipse.pde.PluginNature
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.pde.ds.annotations.prefs b/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.pde.ds.annotations.prefs
deleted file mode 100644
index 5faf08b7d5c..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.pde.ds.annotations.prefs
+++ /dev/null
@@ -1,7 +0,0 @@
-dsVersion=V1_4
-eclipse.preferences.version=1
-enabled=true
-generateBundleActivationPolicyLazy=true
-path=OSGI-INF
-validationErrorLevel=error
-validationErrorLevel.missingImplicitUnbindMethod=error
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/META-INF/MANIFEST.MF b/runtime/tests/org.eclipse.e4.core.javax.tests/META-INF/MANIFEST.MF
index 5dc79131b96..1202b59de53 100644
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/META-INF/MANIFEST.MF
+++ b/runtime/tests/org.eclipse.e4.core.javax.tests/META-INF/MANIFEST.MF
@@ -4,54 +4,15 @@ Bundle-Name: E4 Core Tests
Bundle-SymbolicName: org.eclipse.e4.core.javax.tests
Bundle-Version: 1.3.300.qualifier
Bundle-Vendor: Eclipse.org
-Bundle-Activator: org.eclipse.e4.core.internal.tests.CoreTestsActivator
-Require-Bundle: org.eclipse.equinox.preferences;bundle-version="3.3.0",
- org.eclipse.e4.core.di,
- org.eclipse.e4.core.di.extensions,
- org.eclipse.e4.core.di.extensions.supplier,
- org.eclipse.e4.core.contexts,
- org.eclipse.equinox.registry;bundle-version="3.5.0",
- org.eclipse.core.tests.harness;bundle-version="3.6.0",
- org.eclipse.e4.core.services;bundle-version="1.1.0"
+Require-Bundle: org.eclipse.e4.core.di,
+ org.eclipse.e4.core.contexts
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-17
Import-Package: javax.annotation;version="[1.3.0,2.0.0)",
javax.inject;version="[1.0.0,2.0.0)",
- org.assertj.core.api,
- org.eclipse.osgi.service.datalocation,
- org.eclipse.osgi.service.debug,
org.junit.jupiter.api;version="[5.12.0,6.0.0)",
- org.junit.jupiter.api.function;version="[5.12.0,6.0.0)",
- org.junit.platform.suite.api;version="[1.12.0,2.0.0)",
- org.osgi.framework;version="[1.10.0,2.0.0)",
- org.osgi.service.component;version="1.3.0",
- org.osgi.service.component.propertytypes;version="[1.4.0,2.0.0)",
- org.osgi.service.event;version="1.3.0",
- org.osgi.util.tracker;version="[1.5.0,2.0.0)"
-Export-Package: org.eclipse.e4.core.internal.tests;x-internal:=true,
- org.eclipse.e4.core.internal.tests.contexts;x-internal:=true,
- org.eclipse.e4.core.internal.tests.contexts.inject;x-internal:=true,
- org.eclipse.e4.core.internal.tests.contexts.performance;x-internal:=true,
- org.eclipse.e4.core.internal.tests.di;x-internal:=true,
- org.eclipse.e4.core.internal.tests.di.extensions;x-internal:=true,
- org.eclipse.e4.core.internal.tests.manual;x-internal:=true,
- org.eclipse.e4.core.internal.tests.nls;x-internal:=true,
+ org.junit.platform.suite.api;version="[1.12.0,2.0.0)"
+Export-Package: org.eclipse.e4.core.internal.tests.contexts.inject;x-internal:=true,
org.eclipse.e4.core.javax.tests
-Service-Component: OSGI-INF/DisabledServiceA.xml,
- OSGI-INF/DisabledServiceB.xml,
- OSGI-INF/org.eclipse.e4.core.internal.tests.contexts.AddContextFunction.xml,
- OSGI-INF/org.eclipse.e4.core.internal.tests.contexts.inject.TestServiceA.xml,
- OSGI-INF/org.eclipse.e4.core.internal.tests.contexts.inject.TestServiceB.xml,
- OSGI-INF/org.eclipse.e4.core.internal.tests.contexts.inject.TestServiceController.xml,
- OSGI-INF/org.eclipse.e4.core.internal.tests.di.extensions.ComponentEnabler.xml,
- OSGI-INF/org.eclipse.e4.core.internal.tests.di.extensions.FilterServiceA.xml,
- OSGI-INF/org.eclipse.e4.core.internal.tests.di.extensions.FilterServiceB.xml,
- OSGI-INF/org.eclipse.e4.core.internal.tests.di.extensions.SampleServiceA.xml,
- OSGI-INF/org.eclipse.e4.core.internal.tests.di.extensions.SampleServiceB.xml
Eclipse-BundleShape: dir
-Require-Capability: osgi.extender;
- filter:="(&(osgi.extender=osgi.component)(version>=1.3)(!(version>=2.0)))",
- osgi.service;
- filter:="(objectClass=org.osgi.service.event.EventAdmin)";
- effective:="active"
Automatic-Module-Name: org.eclipse.e4.core.javax.tests
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle.properties
deleted file mode 100644
index ad0b4b93cb0..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle.properties
+++ /dev/null
@@ -1,11 +0,0 @@
-message=BundleMessage
-message_one=BundleMessageUnderscore
-messageOne=BundleMessageCamelCase
-message.two=BundleMessageUnderscoreDot
-message.three=BundleMessageCamelCaseDot
-message.four=The idea is from {0}
-messageFive_Sub=BundleMessageCamelCaseAndUnderscoreOriginal
-message_six__sub=BundleMessageCamelCaseAndUnderscoreDeCamelCasified
-message.seven..sub=BundleMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified
-messageEight.Sub=BundleMessageCamelCaseAndUnderscoreDeUnderscorified
-message_nine._sub=BundleMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified
\ No newline at end of file
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de.properties
deleted file mode 100644
index c45cde6d1d7..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de.properties
+++ /dev/null
@@ -1,10 +0,0 @@
-message=BundleNachricht
-message_one=BundleNachrichtUnderscore
-messageOne=BundleNachrichtCamelCase
-message.two=BundleNachrichtUnderscoreDot
-message.four=Die Idee ist von {0}
-messageFive_Sub=BundleNachrichtCamelCaseAndUnderscoreOriginal
-message_six__sub=BundleNachrichtCamelCaseAndUnderscoreDeCamelCasified
-message.seven..sub=BundleNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified
-messageEight.Sub=BundleNachrichtCamelCaseAndUnderscoreDeUnderscorified
-message_nine._sub=BundleNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified
\ No newline at end of file
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de_ch_test.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de_ch_test.properties
deleted file mode 100644
index a0582385afb..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de_ch_test.properties
+++ /dev/null
@@ -1,10 +0,0 @@
-message=BundleNachrichtVariant
-message_one=BundleNachrichtUnderscoreVariant
-messageOne=BundleNachrichtCamelCaseVariant
-message.two=BundleNachrichtUnderscoreDotVariant
-message.four=Die Idee ist von {0} Variant
-messageFive_Sub=BundleNachrichtCamelCaseAndUnderscoreOriginalVariant
-message_six__sub=BundleNachrichtCamelCaseAndUnderscoreDeCamelCasifiedVariant
-message.seven..sub=BundleNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorifiedVariant
-messageEight.Sub=BundleNachrichtCamelCaseAndUnderscoreDeUnderscorifiedVariant
-message_nine._sub=BundleNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasifiedVariant
\ No newline at end of file
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/README.md b/runtime/tests/org.eclipse.e4.core.javax.tests/README.md
index c15285d1bfc..26865d412c0 100644
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/README.md
+++ b/runtime/tests/org.eclipse.e4.core.javax.tests/README.md
@@ -1,2 +1,2 @@
-This is a copy of `org.eclipse.e4.core.tests`, that uses javax annotations while the original uses jakarta annotations now.
+This is a reduced minimal copy of `org.eclipse.e4.core.tests`, that verifies javax annotations continue to work, not only the mainly used jakarta annotations.
When support for javax annotations is removed from the E4-Injector, this project can be deleted entirely as well.
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/build.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/build.properties
index 76d226c77dc..298d235e506 100644
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/build.properties
+++ b/runtime/tests/org.eclipse.e4.core.javax.tests/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2010, 2015 IBM Corporation and others.
+# Copyright (c) 2010, 2026 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
@@ -17,8 +17,8 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
test.xml,\
- OSGI-INF/,\
- resources/,\
- about.html
-src.includes = resources/,\
about.html
+src.includes = about.html
+
+# Maven/Tycho POM adjustments, see https://github.com/eclipse-tycho/tycho/wiki/Tycho-Pomless
+pom.model.property.testClass = org.eclipse.e4.core.javax.tests.CoreTestSuite
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/pom.xml b/runtime/tests/org.eclipse.e4.core.javax.tests/pom.xml
deleted file mode 100644
index 0016e26e239..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/pom.xml
+++ /dev/null
@@ -1,62 +0,0 @@
-
-
-
- 4.0.0
-
- org.eclipse.platform
- eclipse.platform.runtime
- 4.40.0-SNAPSHOT
- ../..
-
- org.eclipse.e4.core.javax.tests
- 1.3.300-SNAPSHOT
- eclipse-test-plugin
-
- org.eclipse.e4.core.javax.tests.CoreTestSuite
-
-
- src
-
-
- org.apache.maven.plugins
- maven-resources-plugin
-
-
-
- copy-ds-component-xml
-
- copy-resources
-
- process-test-resources
-
-
-
-
- ${project.build.outputDirectory}/OSGI-INF
- *.xml
-
-
- ${project.basedir}/OSGI-INF
-
-
-
-
-
-
-
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/resources/another.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/resources/another.properties
deleted file mode 100644
index 86e9d9c7baf..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/resources/another.properties
+++ /dev/null
@@ -1,11 +0,0 @@
-message=ResourcesMessage
-message_one=ResourcesMessageUnderscore
-messageOne=ResourcesMessageCamelCase
-message.two=ResourcesMessageUnderscoreDot
-message.three=ResourcesMessageCamelCaseDot
-message.four=The idea is from {0}
-messageFive_Sub=ResourcesMessageCamelCaseAndUnderscoreOriginal
-message_six__sub=ResourcesMessageCamelCaseAndUnderscoreDeCamelCasified
-message.seven..sub=ResourcesMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified
-messageEight.Sub=ResourcesMessageCamelCaseAndUnderscoreDeUnderscorified
-message_nine._sub=ResourcesMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified
\ No newline at end of file
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/resources/another_de.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/resources/another_de.properties
deleted file mode 100644
index 7c4441b54a6..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/resources/another_de.properties
+++ /dev/null
@@ -1,10 +0,0 @@
-message=ResourcesNachricht
-message_one=ResourcesNachrichtUnderscore
-messageOne=ResourcesNachrichtCamelCase
-message.two=ResourcesNachrichtUnderscoreDot
-message.four=Die Idee ist von {0}
-messageFive_Sub=ResourcesNachrichtCamelCaseAndUnderscoreOriginal
-message_six__sub=ResourcesNachrichtCamelCaseAndUnderscoreDeCamelCasified
-message.seven..sub=ResourcesNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified
-messageEight.Sub=ResourcesNachrichtCamelCaseAndUnderscoreDeUnderscorified
-message_nine._sub=ResourcesNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified
\ No newline at end of file
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/CoreTestsActivator.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/CoreTestsActivator.java
deleted file mode 100644
index 6d0c273f3e1..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/CoreTestsActivator.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.e4.core.internal.tests;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.eclipse.core.runtime.preferences.IPreferencesService;
-import org.eclipse.e4.core.contexts.IContextFunction;
-import org.eclipse.e4.core.internal.tests.contexts.ContextFunctionHigh;
-import org.eclipse.e4.core.internal.tests.contexts.ContextFunctionLow;
-import org.eclipse.osgi.service.debug.DebugOptions;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.service.event.EventAdmin;
-import org.osgi.util.tracker.ServiceTracker;
-
-public class CoreTestsActivator implements BundleActivator {
-
- static private CoreTestsActivator defaultInstance;
- private BundleContext bundleContext;
- private ServiceTracker debugTracker = null;
- private ServiceTracker preferencesTracker = null;
- private ServiceTracker eventAdminTracker;
-
- public CoreTestsActivator() {
- defaultInstance = this;
- }
-
- public static CoreTestsActivator getDefault() {
- return defaultInstance;
- }
-
- @Override
- public void start(BundleContext context) throws Exception {
- bundleContext = context;
- registerContextFunctions();
- }
-
- @Override
- public void stop(BundleContext context) throws Exception {
- if (preferencesTracker != null) {
- preferencesTracker.close();
- preferencesTracker = null;
- }
- if (debugTracker != null) {
- debugTracker.close();
- debugTracker = null;
- }
- if (eventAdminTracker != null) {
- eventAdminTracker.close();
- eventAdminTracker = null;
- }
- bundleContext = null;
- }
-
- private void registerContextFunctions() {
- {
- Dictionary properties = new Hashtable<>();
- properties.put(IContextFunction.SERVICE_CONTEXT_KEY,"test.contextfunction.ranking");
- properties.put(Constants.SERVICE_RANKING, 0);
- bundleContext.registerService(IContextFunction.SERVICE_NAME, new ContextFunctionLow(), properties);
- }
-
- Dictionary properties = new Hashtable<>();
- properties.put(IContextFunction.SERVICE_CONTEXT_KEY,"test.contextfunction.ranking");
- properties.put(Constants.SERVICE_RANKING, 100);
- bundleContext.registerService(IContextFunction.SERVICE_NAME, new ContextFunctionHigh(), properties);
-
- }
-
- public BundleContext getBundleContext() {
- return bundleContext;
- }
-
- public EventAdmin getEventAdmin() {
- if (eventAdminTracker == null) {
- if (bundleContext == null) {
- return null;
- }
- eventAdminTracker = new ServiceTracker<>(bundleContext, EventAdmin.class.getName(), null);
- eventAdminTracker.open();
- }
- return eventAdminTracker.getService();
- }
-
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java
deleted file mode 100644
index 300b411d4b8..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java
+++ /dev/null
@@ -1,332 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- ******************************************************************************/
-
-package org.eclipse.e4.core.internal.tests.contexts;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.eclipse.e4.core.contexts.ContextFunction;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.contexts.RunAndTrack;
-import org.junit.jupiter.api.Test;
-
-public class ActivationTest {
-
- static public class TestRAT extends ContextFunction {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- IEclipseContext activeContext = context.getActiveLeaf();
- // returns name of the context
- return activeContext.get("debugString");
- }
- }
-
- @Test
- public void testContextActivation() {
- IEclipseContext rootContext = EclipseContextFactory.create("root");
- rootContext.set("testRAT", new TestRAT());
-
- IEclipseContext child1 = rootContext.createChild("child1");
- IEclipseContext child11 = child1.createChild("child11");
- IEclipseContext child12 = child1.createChild("child12");
-
- IEclipseContext child2 = rootContext.createChild("child2");
- IEclipseContext child21 = child2.createChild("child21");
- IEclipseContext child22 = child2.createChild("child22");
-
- assertEquals(rootContext, rootContext.getActiveLeaf());
- assertNull(rootContext.getActiveChild());
- assertEquals("root", rootContext.get("testRAT"));
-
- child12.activateBranch();
- assertEquals(child12, rootContext.getActiveLeaf());
- assertEquals(child1, rootContext.getActiveChild());
- assertEquals("child12", rootContext.get("testRAT"));
-
- assertEquals(child2, child2.getActiveLeaf());
- assertNull(child2.getActiveChild());
- assertEquals("child2", child2.get("testRAT"));
-
- child21.activateBranch();
- assertEquals(child21, rootContext.getActiveLeaf());
- assertEquals(child2, rootContext.getActiveChild());
- assertEquals("child21", rootContext.get("testRAT"));
- assertEquals(child12, child1.getActiveLeaf());
- assertEquals(child12, child1.getActiveChild());
- assertEquals("child12", child1.get("testRAT"));
- assertEquals(child21, child2.getActiveLeaf());
- assertEquals(child21, child2.getActiveChild());
- assertEquals("child21", child2.get("testRAT"));
-
- child21.deactivate();
- assertEquals(child2, rootContext.getActiveLeaf());
- assertEquals("child2", rootContext.get("testRAT"));
- assertEquals(child12, child1.getActiveLeaf());
- assertEquals("child12", child1.get("testRAT"));
- assertEquals(child2, child2.getActiveLeaf());
- assertNull(child2.getActiveChild());
- assertEquals("child2", child2.get("testRAT"));
-
- child22.activateBranch();
- assertEquals(child22, rootContext.getActiveLeaf());
- assertEquals("child22", rootContext.get("testRAT"));
- assertEquals(child12, child1.getActiveLeaf());
- assertEquals("child12", child1.get("testRAT"));
- assertEquals(child22, child2.getActiveLeaf());
- assertEquals("child22", child2.get("testRAT"));
-
- child11.activateBranch();
- assertEquals(child11, rootContext.getActiveLeaf());
- assertEquals("child11", rootContext.get("testRAT"));
- assertEquals(child11, child1.getActiveLeaf());
- assertEquals("child11", child1.get("testRAT"));
- assertEquals(child22, child2.getActiveLeaf());
- assertEquals("child22", child2.get("testRAT"));
-
- child11.deactivate();
- assertEquals(child1, rootContext.getActiveLeaf());
- assertEquals("child1", rootContext.get("testRAT"));
- assertEquals(child1, child1.getActiveLeaf());
- assertEquals("child1", child1.get("testRAT"));
- assertEquals(child22, child2.getActiveLeaf());
- assertEquals("child22", child2.get("testRAT"));
-
- child1.dispose();
- assertNull(rootContext.getActiveChild());
- child2.activateBranch();
- assertEquals(child22, rootContext.getActiveLeaf());
- assertEquals("child22", rootContext.get("testRAT"));
- assertEquals(child22, child2.getActiveLeaf());
- assertEquals("child22", child2.get("testRAT"));
- }
-
- @Test
- public void testGetActive() {
- IEclipseContext root = EclipseContextFactory.create("root");
-
- IEclipseContext child1 = root.createChild("child1");
- IEclipseContext child11 = child1.createChild("child11");
- IEclipseContext child12 = child1.createChild("child12");
-
- IEclipseContext child2 = root.createChild("child2");
- IEclipseContext child21 = child2.createChild("child21");
- IEclipseContext child22 = child2.createChild("child22");
-
- child11.set("var", "1");
- child12.set("var", "2");
- child1.set("var", "3");
- child21.set("var", "4");
- child22.set("var", "5");
- child2.set("var", "6");
- root.set("var", "7");
-
- // nothing is active - we get value from the node
- assertEquals("3", child1.getActive("var"));
-
- child11.activateBranch();
- assertEquals("1", child1.getActive("var"));
- child12.activateBranch();
- assertEquals("2", child1.getActive("var"));
- child22.activateBranch();
- assertEquals("5", child2.getActive("var"));
- }
-
- @Test
- public void testGetActiveBug384425() {
- IEclipseContext root = EclipseContextFactory.create("root");
-
- IEclipseContext child1 = root.createChild("child1");
- IEclipseContext child11 = child1.createChild("child11");
-
- IEclipseContext child2 = root.createChild("child2");
-
- // nothing is active - we get value from the node
- assertNull(root.getActive("var"));
- assertNull(child1.getActive("var"));
- assertNull(child2.getActive("var"));
-
- child11.activateBranch();
- child11.set("var", "1");
-
- assertEquals("1", root.getActive("var"));
- assertEquals("1", child1.getActive("var"));
- assertNull(child2.getActive("var"));
- }
-
- @Test
- public void testGetActiveRAT() {
- IEclipseContext root = EclipseContextFactory.create("root");
-
- IEclipseContext child1 = root.createChild("child1");
- IEclipseContext child11 = child1.createChild("child11");
- IEclipseContext child12 = child1.createChild("child12");
-
- IEclipseContext child2 = root.createChild("child2");
- IEclipseContext child21 = child2.createChild("child21");
- IEclipseContext child22 = child2.createChild("child22");
-
- child11.set("var", "1");
- child12.set("var", "2");
- child1.set("var", "3");
- child21.set("var", "4");
- child22.set("var", "5");
- child2.set("var", "6");
- root.set("var", "7");
-
- final String[] result = new String[1];
-
- child1.runAndTrack(new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- result[0] = (String) context.getActive("var");
- return true;
- }});
-
- // nothing is active - we get value from the node
- assertEquals("3", result[0]);
-
- child11.activateBranch();
- assertEquals("1", result[0]);
- child12.activateBranch();
- assertEquals("2", result[0]);
- child22.activateBranch();
- assertEquals("2", result[0]);
- }
-
- @Test
- public void testGetActiveRATNumberOfCalls() {
- IEclipseContext root = EclipseContextFactory.create("root");
-
- IEclipseContext child1 = root.createChild("child1");
- IEclipseContext child11 = child1.createChild("child11");
- IEclipseContext child12 = child1.createChild("child12");
-
- IEclipseContext child2 = root.createChild("child2");
- IEclipseContext child21 = child2.createChild("child21");
- IEclipseContext child22 = child2.createChild("child22");
-
- child11.set("var", "1");
- child12.set("var", "1");
- child1.set("var", "3");
- child21.set("var", "4");
- child22.set("var", "4");
- child2.set("var", "6");
- root.set("var", "7");
-
- final String[] result = new String[1];
- final int[] called = new int[1];
- called[0] = 0;
-
- child1.runAndTrack(new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- result[0] = (String) context.getActive("var");
- called[0]++;
- return true;
- }});
-
- // nothing is active - we get value from the node
- assertEquals("3", result[0]);
- assertEquals(1, called[0]);
-
- child11.activateBranch();
- assertEquals("1", result[0]);
- assertEquals(2, called[0]);
-
- child12.activateBranch();
- assertEquals("1", result[0]);
- assertEquals(3, called[0]);
-
- child22.activateBranch();
- assertEquals("1", result[0]);
- assertEquals(3, called[0]);
-
- child21.activateBranch();
- assertEquals("1", result[0]);
- assertEquals(3, called[0]);
- }
-
- /**
- * A variation of {@link #testGetActiveRATNumberOfCalls()} that
- * uses distinct values in the leaf contexts.
- */
- @Test
- public void testGetActiveRATNumberOfCalls2() {
- IEclipseContext root = EclipseContextFactory.create("root");
-
- IEclipseContext child1 = root.createChild("child1");
- IEclipseContext child11 = child1.createChild("child11");
- IEclipseContext child12 = child1.createChild("child12");
-
- IEclipseContext child2 = root.createChild("child2");
- IEclipseContext child21 = child2.createChild("child21");
- IEclipseContext child22 = child2.createChild("child22");
-
- child11.set("var", "11");
- child12.set("var", "12");
- child1.set("var", "3");
- child21.set("var", "21");
- child22.set("var", "22");
- child2.set("var", "6");
- root.set("var", "7");
-
- final String[] result = new String[1];
- final int[] called = new int[1];
- called[0] = 0;
-
- child1.runAndTrack(new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- result[0] = (String) context.getActive("var");
- called[0]++;
- return true;
- }});
-
- // nothing is active - we get value from the node
- assertEquals("3", result[0]);
- assertEquals(1, called[0]);
-
- child11.activateBranch();
- assertEquals("11", result[0]);
- assertEquals(2, called[0]);
-
- child12.activateBranch();
- assertEquals("12", result[0]);
- assertEquals(3, called[0]);
-
- child22.activateBranch();
- assertEquals("12", result[0]);
- assertEquals(3, called[0]);
-
- child21.activateBranch();
- assertEquals("12", result[0]);
- assertEquals(3, called[0]);
- }
-
- public static class ActiveInject {
- //@Inject @Named("var")
- public String value;
-
- @Inject
- public void setValue(@Named("var") String value) {
- this.value = value;
- }
- }
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/AddContextFunction.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/AddContextFunction.java
deleted file mode 100644
index 1e10cf4003d..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/AddContextFunction.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.e4.core.internal.tests.contexts;
-
-import org.eclipse.e4.core.contexts.ContextFunction;
-import org.eclipse.e4.core.contexts.IContextFunction;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.osgi.service.component.annotations.Component;
-
-
-/**
- * A function provided as a declarative service. See OSGI-INF/adder.xml.
- */
-@Component(service = IContextFunction.class, property = IContextFunction.SERVICE_CONTEXT_KEY + "=sum")
-public class AddContextFunction extends ContextFunction {
-
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- Integer xInt = (Integer) context.get("x");
- Integer yInt = (Integer) context.get("y");
- int sum = xInt == null ? 0 : xInt.intValue();
- sum += yInt == null ? 0 : yInt.intValue();
- return Integer.valueOf(sum);
- }
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextDynamicTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextDynamicTest.java
deleted file mode 100644
index be8067c592c..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextDynamicTest.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- *******************************************************************************/
-package org.eclipse.e4.core.internal.tests.contexts;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-import org.eclipse.e4.core.contexts.ContextFunction;
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.internal.tests.contexts.inject.ObjectBasic;
-import org.junit.jupiter.api.Test;
-
-/**
- * Tests for the basic context functionality
- */
-public class ContextDynamicTest {
-
-
- @Test
- public void testReplaceFunctionWithStaticValue() {
- IEclipseContext parent = EclipseContextFactory.create();
- IEclipseContext context = parent.createChild();
- assertNull(context.getLocal("bar"));
- context.set("bar", "baz1");
- context.set("bar", new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- return "baz1";
- }
- });
- parent.set("bar", "baz2");
- assertEquals("baz1", context.get("bar"));
- context.set("bar", "baz3");
- assertEquals("baz3", context.get("bar"));
- }
-
- /**
- * Tests objects being added and removed from the context
- */
- @Test
- public synchronized void testAddRemove() {
- Integer testInt = Integer.valueOf(123);
- String testString = "abc";
- Double testDouble = Double.valueOf(1.23);
- Float testFloat = Float.valueOf(12.3f);
- Character testChar = Character.valueOf('v');
-
- // create original context
- IEclipseContext context = EclipseContextFactory.create();
- context.set(Integer.class.getName(), testInt);
- context.set(String.class.getName(), testString);
- context.set(Double.class.getName(), testDouble);
- context.set(Float.class.getName(), testFloat);
- context.set(Character.class.getName(), testChar);
-
- ObjectBasic userObject = new ObjectBasic();
- ContextInjectionFactory.inject(userObject, context);
-
- // check basic injection
- assertEquals(testString, userObject.injectedString);
- assertEquals(testInt, userObject.getInt());
- assertEquals(context, userObject.context);
- assertEquals(1, userObject.setMethodCalled);
- assertEquals(1, userObject.setMethodCalled2);
- assertEquals(testDouble, userObject.d);
- assertEquals(testFloat, userObject.f);
- assertEquals(testChar, userObject.c);
-
- // change value
- Double testDouble2 = Double.valueOf(3.45);
- Integer testInt2 = Integer.valueOf(123);
- context.set(Double.class.getName(), testDouble2);
- context.set(Integer.class.getName(), testInt2);
-
- // and check
- assertEquals(testString, userObject.injectedString);
- assertEquals(testInt2, userObject.getInt());
- assertEquals(context, userObject.context);
- assertEquals(2, userObject.setMethodCalled);
- assertEquals(1, userObject.setMethodCalled2);
- assertEquals(testDouble2, userObject.d);
- assertEquals(testFloat, userObject.f);
- assertEquals(testChar, userObject.c);
-
- // remove element
- context.remove(String.class.getName());
- context.remove(Character.class.getName());
-
- // and check
- assertNull(userObject.injectedString);
- assertEquals(testInt2, userObject.getInt());
- assertEquals(context, userObject.context);
- assertEquals(2, userObject.setMethodCalled);
- assertEquals(2, userObject.setMethodCalled2);
- assertEquals(testDouble2, userObject.d);
- assertEquals(testFloat, userObject.f);
- assertNull(userObject.c);
- }
-
- /**
- * Tests objects being added and removed from the context
- */
- @Test
- public synchronized void testParentAddRemove() {
- Integer testInt = Integer.valueOf(123);
- String testString = "abc";
- Double testDouble = Double.valueOf(1.23);
- Float testFloat = Float.valueOf(12.3f);
- Character testChar = Character.valueOf('v');
-
- // create original context
- IEclipseContext parentContext = EclipseContextFactory.create();
- parentContext.set(Integer.class.getName(), testInt);
- parentContext.set(String.class.getName(), testString);
- parentContext.set(Double.class.getName(), testDouble);
- parentContext.set(Float.class.getName(), testFloat);
- parentContext.set(Character.class.getName(), testChar);
- IEclipseContext context = parentContext.createChild();
-
- ObjectBasic userObject = new ObjectBasic();
- ContextInjectionFactory.inject(userObject, context);
-
- // check basic injection
- assertEquals(testString, userObject.injectedString);
- assertEquals(testInt, userObject.getInt());
- assertEquals(context, userObject.context);
- assertEquals(1, userObject.setMethodCalled);
- assertEquals(1, userObject.setMethodCalled2);
- assertEquals(testDouble, userObject.d);
- assertEquals(testFloat, userObject.f);
- assertEquals(testChar, userObject.c);
-
- // change value
- Double testDouble2 = Double.valueOf(3.45);
- Integer testInt2 = Integer.valueOf(123);
- context.set(Double.class.getName(), testDouble2);
- context.set(Integer.class.getName(), testInt2);
-
- // and check
- assertEquals(testString, userObject.injectedString);
- assertEquals(testInt2, userObject.getInt());
- assertEquals(context, userObject.context);
- assertEquals(2, userObject.setMethodCalled);
- assertEquals(1, userObject.setMethodCalled2);
- assertEquals(testDouble2, userObject.d);
- assertEquals(testFloat, userObject.f);
- assertEquals(testChar, userObject.c);
-
- // remove element
- parentContext.remove(String.class.getName());
- parentContext.remove(Character.class.getName());
-
- // and check
- assertNull(userObject.injectedString);
- assertEquals(testInt2, userObject.getInt());
- assertEquals(context, userObject.context);
- assertEquals(2, userObject.setMethodCalled);
- assertEquals(2, userObject.setMethodCalled2);
- assertEquals(testDouble2, userObject.d);
- assertEquals(testFloat, userObject.f);
- assertNull(userObject.c);
- }
-
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionHigh.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionHigh.java
deleted file mode 100644
index f229460b3e7..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionHigh.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.eclipse.e4.core.internal.tests.contexts;
-
-import org.eclipse.e4.core.contexts.ContextFunction;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-
-public class ContextFunctionHigh extends ContextFunction {
- @Override
- public Object compute(IEclipseContext context) {
- return "High";
- }
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionLow.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionLow.java
deleted file mode 100644
index 9e04f359f29..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionLow.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.eclipse.e4.core.internal.tests.contexts;
-
-import org.eclipse.e4.core.contexts.ContextFunction;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-
-public class ContextFunctionLow extends ContextFunction {
- @Override
- public Object compute(IEclipseContext context) {
- return "Low";
- }
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/DependenciesLeakTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/DependenciesLeakTest.java
deleted file mode 100644
index 111294b9c6d..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/DependenciesLeakTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation 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:
- * Stefan Mücke - initial API and implementation
- * Lars Vogel - Bug 474274
- *******************************************************************************/
-package org.eclipse.e4.core.internal.tests.contexts;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import org.eclipse.e4.core.contexts.ContextFunction;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.internal.contexts.EclipseContext;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-@SuppressWarnings("restriction")
-public class DependenciesLeakTest {
-
- final static String LEGACY_H_ID = "legacy::handler::"; //$NON-NLS-1$
-
- static class HandlerSelectionFunction extends ContextFunction {
- private final String commandId;
- public HandlerSelectionFunction(String commandId) {
- this.commandId = commandId;
- }
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- return context.get(LEGACY_H_ID + commandId);
- }
- @Override
- public String toString() {
- return "HandlerSelectionFunction [commandId=" + commandId + "]";
- }
- }
-
- private IEclipseContext windowContext;
- private IEclipseContext perspectiveContext;
- private IEclipseContext partContext;
-
- @BeforeEach
- public void setUp() throws Exception {
- windowContext = EclipseContextFactory.create("Window");
- perspectiveContext = windowContext.createChild("Perspective");
- partContext = perspectiveContext.createChild("Part");
- }
-
- @Test
- public void testBug() {
- // register a handler
- Object handler = "";
- windowContext.set("legacy::handler::foo.bar", handler); // fake activate legacy handler
- windowContext.set("foo.bar", new HandlerSelectionFunction("foo.bar"));
-
- // there may be no listeners initially
- assertNoListeners(windowContext);
- assertNoListeners(perspectiveContext);
- assertNoListeners(partContext);
-
- // cause a ValueComputation to be created
- Object object = partContext.get("foo.bar");
- assertEquals(object, handler);
-
- // now invalidate the name; this should notify the part context
- windowContext.set("foo.bar", null);
- //windowContext.remove("foo.bar");
-
- // all ValueComputation listeners must have been removed
- assertNoListeners(windowContext);
- assertNoListeners(perspectiveContext);
- assertNoListeners(partContext);
- }
-
- @Test
- public void testInvalidateDirectly() {
- windowContext.set("x", 42);
- windowContext.set("y", 11);
- windowContext.set("some.handler", new AddContextFunction());
- assertNoListeners(windowContext);
- assertNoListeners(perspectiveContext);
- assertNoListeners(partContext);
-
- Object object = partContext.get("some.handler");
- assertEquals(object, 53);
-
- windowContext.set("some.handler", null); // invalidate
- assertNoListeners(windowContext);
- assertNoListeners(perspectiveContext);
- assertNoListeners(partContext);
- }
-
- private void assertNoListeners(IEclipseContext context) {
- EclipseContext c = (EclipseContext) context;
- try {
- assertTrue(c.getListeners().isEmpty());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/EclipseContextTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/EclipseContextTest.java
deleted file mode 100644
index cf44025fa3e..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/EclipseContextTest.java
+++ /dev/null
@@ -1,397 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2021 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- *******************************************************************************/
-package org.eclipse.e4.core.internal.tests.contexts;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import org.eclipse.e4.core.contexts.ContextFunction;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.contexts.RunAndTrack;
-import org.eclipse.e4.core.di.IInjector;
-import org.eclipse.e4.core.internal.contexts.EclipseContext;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.osgi.framework.FrameworkUtil;
-
-@SuppressWarnings("restriction")
-public class EclipseContextTest {
-
- private static class ComputedValueBar extends ContextFunction {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- return context.get("bar");
- }
- }
-
- private IEclipseContext context;
- private IEclipseContext parentContext;
-
- private int runCounter;
-
- @BeforeEach
- public void setUp() throws Exception {
- parentContext = EclipseContextFactory.create("EclipseContextTest" + "-parent");
- context = parentContext.createChild("EclipseContextTest");
- runCounter = 0;
- }
-
- @Test
- public void testContainsKey() {
- assertFalse(context.containsKey("function"));
- assertFalse(context.containsKey("separator"));
-
- context.set("separator", ",");
- assertTrue(context.containsKey("separator"));
-
- // null value is still a value
- context.set("separator", null);
- assertTrue(context.containsKey("separator"));
-
- context.remove("separator");
- assertFalse(context.containsKey("separator"));
- }
-
- @Test
- public void testGet() {
- assertNull(context.get("foo"));
- context.set("foo", "bar");
- assertEquals("bar", context.get("foo"));
- assertNull(parentContext.get("foo"));
- context.remove("foo");
- assertNull(context.get("foo"));
- parentContext.set("foo", "bar");
- assertEquals("bar", context.get("foo"));
- context.set("foo", new ComputedValueBar());
- assertNull(context.get("foo"));
- context.set("bar", "baz");
- assertEquals("baz", context.get("foo"));
- }
-
- @Test
- public void testGetLocal() {
- assertNull(context.getLocal("foo"));
- context.set("foo", "bar");
- assertEquals("bar", context.getLocal("foo"));
- assertNull(parentContext.getLocal("foo"));
- context.remove("foo");
- assertNull(context.getLocal("foo"));
- parentContext.set("foo", "bar");
- assertNull(context.getLocal("foo"));
- context.set("foo", new ComputedValueBar());
- assertNull(context.getLocal("foo"));
- context.set("bar", "baz");
- assertEquals("baz", context.getLocal("foo"));
- }
-
- /**
- * Tests that a context no longer looks up values from its parent when disposed.
- */
- @Test
- public void testDisposeRemovesParentReference() {
- assertNull(context.get("foo"));
- parentContext.set("foo", "bar");
- assertEquals("bar", context.get("foo"));
- context.dispose();
- assertNull(context.get("foo"));
- assertFalse(((EclipseContext) parentContext).getChildren().iterator().hasNext());
- }
-
- @Test
- public void testDisposeClearsNotifyOnDisposalSet() {
- ((EclipseContext) context).notifyOnDisposal(context -> runCounter++);
- context.dispose();
- assertEquals(1, runCounter);
- context.dispose();
- assertEquals(1, runCounter);
- }
-
- /**
- * Tests handling of a context function defined in the parent that uses values defined in the
- * child
- */
- @Test
- public void testContextFunctionInParent() {
- IEclipseContext parent = EclipseContextFactory.create();
- final IEclipseContext child = parent.createChild();
- parent.set("sum", new AddContextFunction());
- parent.set("x", Integer.valueOf(3));
- parent.set("y", Integer.valueOf(3));
- child.set("x", Integer.valueOf(1));
- child.set("y", Integer.valueOf(1));
- assertEquals(6, ((Integer) parent.get("sum")).intValue());
- assertEquals(2, ((Integer) child.get("sum")).intValue());
- child.set("x", Integer.valueOf(5));
- assertEquals(6, ((Integer) parent.get("sum")).intValue());
- assertEquals(6, ((Integer) child.get("sum")).intValue());
- child.remove("x");
- assertEquals(6, ((Integer) parent.get("sum")).intValue());
- assertEquals(4, ((Integer) child.get("sum")).intValue());
- parent.set("x", Integer.valueOf(10));
- assertEquals(13, ((Integer) parent.get("sum")).intValue());
- assertEquals(11, ((Integer) child.get("sum")).intValue());
- }
-
- @Test
- public void testRunAndTrack() {
- final Object[] value = new Object[1];
- context.runAndTrack(new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- runCounter++;
- value[0] = context.get("foo");
- return true;
- }
- });
- assertEquals(1, runCounter);
- assertEquals(null, value[0]);
- context.set("foo", "bar");
- assertEquals(2, runCounter);
- assertEquals("bar", value[0]);
- context.remove("foo");
- assertEquals(3, runCounter);
- assertEquals(null, value[0]);
- context.set("foo", new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- return context.get("bar");
- }
- });
- assertEquals(4, runCounter);
- assertEquals(null, value[0]);
- context.set("bar", "baz");
- assertEquals(5, runCounter);
- assertEquals("baz", value[0]);
- context.set("bar", "baf");
- assertEquals(6, runCounter);
- assertEquals("baf", value[0]);
- context.remove("bar");
- assertEquals(7, runCounter);
- assertEquals(null, value[0]);
- parentContext.set("bar", "bam");
- assertEquals(8, runCounter);
- assertEquals("bam", value[0]);
- }
-
- /**
- * Tests registering a single run and track instance multiple times with the same context.
- */
- @Test
- public void testRegisterRunAndTrackTwice() {
- final Object[] value = new Object[1];
- RunAndTrack runnable = new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- runCounter++;
- value[0] = context.get("foo");
- return true;
- }
- };
- context.runAndTrack(runnable);
- assertEquals(1, runCounter);
- context.runAndTrack(runnable);
- assertEquals(2, runCounter);
- assertEquals(null, value[0]);
- context.set("foo", "bar");
- assertEquals(3, runCounter);
- assertEquals("bar", value[0]);
- context.remove("foo");
- assertEquals(4, runCounter);
-
- }
-
- @Test
- public void testRunAndTrackMultipleValues() {
- IEclipseContext parent = EclipseContextFactory.create("ParentContext");
- final IEclipseContext child = parent.createChild("ChildContext");
- parent.set("parentValue", "x");
- child.set("childValue", "x");
- RunAndTrack runnable = new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- runCounter++;
- if (runCounter < 2) {
- child.get("childValue");
- return true;
- }
- if (runCounter < 3) {
- child.get("parentValue");
- return true;
- }
- return false;
- }
- };
- child.runAndTrack(runnable);
- assertEquals(1, runCounter);
- child.set("childValue", "z");
- assertEquals(2, runCounter);
- parent.set("parentValue", "z");
- assertEquals(3, runCounter);
- }
-
- @Test
- public void testModify() {
- IEclipseContext grandParent = EclipseContextFactory.create();
- IEclipseContext parent = grandParent.createChild();
- IEclipseContext child = parent.createChild();
-
- child.set("a", "a1");
- parent.set("b", "b2");
- grandParent.set("c", "c3");
-
- child.declareModifiable("a");
- parent.declareModifiable("b");
- grandParent.declareModifiable("c");
-
- // test pre-conditions
- assertNull(grandParent.get("b"));
- assertEquals("b2", parent.get("b"));
- assertEquals("b2", child.get("b"));
- assertNull(child.getLocal("b"));
-
- // modify value on the middle node via its child
- child.modify("b", "abc");
-
- assertFalse(grandParent.containsKey("b"));
- assertEquals("abc", parent.get("b"));
- assertEquals("abc", child.get("b"));
- assertNull(child.getLocal("b"));
-
- // modifying non-exist values adds it to the context
- child.modify("d", "123");
-
- assertFalse(grandParent.containsKey("d"));
- assertFalse(parent.containsKey("d"));
- assertNull(parent.get("d"));
- assertEquals("123", child.get("d"));
-
- // edge conditions: modify value in the top node
- grandParent.modify("c", "cNew");
- assertTrue(grandParent.containsKey("c"));
- assertEquals("cNew", grandParent.get("c"));
- assertNull(parent.getLocal("c"));
- assertNull(child.getLocal("c"));
- assertTrue(child.containsKey("c"));
-
- // edge condition: modify value in the leaf node
- child.modify("a", "aNew");
- assertTrue(child.containsKey("a"));
- assertFalse(parent.containsKey("a"));
- assertFalse(grandParent.containsKey("a"));
- assertEquals("aNew", child.get("a"));
- assertNull(parent.get("a"));
-
- // test access rules
- child.set("aNo", "a1");
- parent.set("bNo", "b2");
- grandParent.set("cNo", "c3");
-
- boolean exception = false;
- try {
- child.modify("bNo", "new");
- } catch (IllegalArgumentException e) {
- exception = true;
- }
- assertTrue(exception);
-
- exception = false;
- try {
- grandParent.modify("cNo", "new");
- } catch (IllegalArgumentException e) {
- exception = true;
- }
- assertTrue(exception);
-
- exception = false;
- try {
- child.modify("aNo", "new");
- } catch (IllegalArgumentException e) {
- exception = true;
- }
- assertTrue(exception);
- }
-
- @Test
- public void testRemoveValueComputationOnDispose() {
- IEclipseContext parent = EclipseContextFactory.create("ParentContext");
- IEclipseContext child = parent.createChild("ChildContext");
- parent.set("x", Integer.valueOf(1));
- parent.set("y", Integer.valueOf(1));
- parent.set("sum", new AddContextFunction());
-
- child.get("sum");
- assertEquals(1, listenersCount(child));
- child.dispose();
- assertEquals(0, listenersCount(parent));
- }
-
- @Test
- public void testNullInheritance() {
- IEclipseContext parent = EclipseContextFactory.create("ParentContext");
- IEclipseContext child = parent.createChild("ChildContext");
- parent.set("x", Integer.valueOf(1));
- child.set("x", null);
- assertNull(child.get("x"));
- }
-
- @Test
- public void testGetCFNotAValue() {
- IEclipseContext context = EclipseContextFactory.create("ParentContext");
- context.set("x", new ContextFunction() {
-
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- return IInjector.NOT_A_VALUE;
- }
- });
-
- // must call several times as the underlying ValueComputation wrapper is
- // created on the first time, but re-used for subsequent calls.
- assertNull(context.get("x"));
- assertNull(context.get("x"));
- assertNull(context.get("x"));
- context.dispose();
- }
-
- @Test
- public void testGetCFNotAValueToParent() {
- IEclipseContext parent = EclipseContextFactory.create("ParentContext");
- IEclipseContext child = parent.createChild();
- parent.set("x", Integer.valueOf(1));
- child.set("x", new ContextFunction() {
-
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- return IInjector.NOT_A_VALUE;
- }
- });
-
- assertEquals(1, child.get("x"));
- parent.dispose();
- }
-
- @Test
- public void testContextFunctionOrdering() {
- IEclipseContext osgiContext = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext());
- assertEquals("High",osgiContext.get("test.contextfunction.ranking"));
- }
-
- private int listenersCount(IEclipseContext context) {
- return ((EclipseContext) context).getListeners().size();
- }
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/NeutralValueTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/NeutralValueTest.java
deleted file mode 100644
index 0e78e8797df..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/NeutralValueTest.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021 Joerg Kubitz.
- *
- * 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:
- * Joerg Kubitz - initial API and implementation
- *******************************************************************************/
-package org.eclipse.e4.core.internal.tests.contexts;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.e4.core.internal.contexts.ConcurrentNeutralValueMap;
-import org.eclipse.e4.core.internal.contexts.ConcurrentNeutralValueMap.Value;
-import org.junit.jupiter.api.Test;
-
-@SuppressWarnings("restriction")
-public class NeutralValueTest {
-
- @Test
- public void testConcurrentNeutralValueMap() {
- ConcurrentNeutralValueMap map = new ConcurrentNeutralValueMap<>(Double.NaN);
- map.put("nix", null); // modify
- map.put("2", 2.0); // modify
- map.put("3", 3.0); // modify
- map.put("4", 4.0); // modify
- map.put("garnix", null); // modify
- assertTrue(map.containsKey("garnix"));
- map.remove("garnix");
-
- assertTrue(map.containsKey("nix"));
- assertTrue(map.containsKey("2"));
- assertFalse(map.containsKey("1"));
- assertFalse(map.containsKey("garnix"));
-
- assertEquals(4, map.size());
-
- assertFalse(map.isEmpty());
-
- assertEquals(null, map.get("nix"));
- assertEquals(null, map.get("1"));
- assertEquals(Double.valueOf(2.0), map.get("2"));
- assertEquals(Double.valueOf(3.0), map.get("3"));
- assertEquals(Double.valueOf(4.0), map.get("4"));
-
- Set keys = new HashSet<>();
- Set values = new HashSet<>();
- map.forEach((k, v) -> keys.add(k));
- map.forEach((k, v) -> values.add(v));
- assertEquals(Set.of("nix", "2", "3", "4"), keys);
- assertTrue(values.contains(null));
- assertTrue(values.contains(2.0));
-
- assertTrue(map.getValue("nix").isPresent());
- assertFalse(map.getValue("1").isPresent());
- assertTrue(map.getValue("2").isPresent());
- assertTrue(map.getValue("3").isPresent());
- assertTrue(map.getValue("4").isPresent());
-
- {
- Value v = map.getValue("nix");
- assertTrue(v.isPresent());
- assertEquals(null, v.unwrapped());
- }
- {
- Value v = map.getValue("1");
- assertFalse(v.isPresent());
- assertEquals(null, v.unwrapped());
- }
- {
- Value v = map.getValue("2");
- assertTrue(v.isPresent());
- assertEquals(Double.valueOf(2.0), v.unwrapped());
- }
-
- {
- Value v = map.putAndGetOld("5", 5555.0); // modify
- assertFalse(v.isPresent());
- assertEquals(null, v.unwrapped());
- assertEquals(Double.valueOf(5555.0), map.get("5"));
- }
- {
- Value v = map.putAndGetOld("5", 5.0); // modify
- assertTrue(v.isPresent());
- assertEquals(Double.valueOf(5555.0), v.unwrapped());
- assertEquals(Double.valueOf(5.0), map.get("5"));
- }
- map.putIfAbsent("5", 5555.0); // modify
- assertEquals(Double.valueOf(5.0), map.get("5"));
- map.remove("5"); // modify
- assertFalse(map.containsKey("5"));
-
- {
- Value v = map.putAndGetOld("five", null); // modify
- assertFalse(v.isPresent());
- assertEquals(null, v.unwrapped());
- assertEquals(null, map.get("five"));
- }
- {
- Value v = map.putAndGetOld("five", 5.0); // modify
- assertTrue(v.isPresent());
- assertEquals(null, v.unwrapped());
- assertEquals(Double.valueOf(5.0), map.get("five"));
- }
- {
- map.putIfAbsent("five", null); // modify
- Value v = map.getValue("five");
- assertTrue(v.isPresent());
- assertEquals(Double.valueOf(5.0), v.unwrapped());
- }
- map.remove("five"); // modify
- {
- map.putIfAbsent("five", null); // modify
- Value v = map.getValue("five");
- assertTrue(v.isPresent());
- assertEquals(null, v.unwrapped());
- }
- map.remove("five"); // modify
- assertFalse(map.containsKey("five"));
-
- map.clear(); // modify
- assertEquals(0, map.size());
- assertTrue(map.isEmpty());
- }
-
- @Test
- public void testToString() {
- ConcurrentNeutralValueMap map1 = new ConcurrentNeutralValueMap<>();
- map1.put("0", 0f);
- map1.put("NULL", null);
- map1.put("nothing", null);
- map1.put("1", 1f);
- map1.put("~2", 2.1f);
- assertTrue(map1.toString().contains("0=0.0"));
- assertTrue(map1.toString().contains("1=1.0"));
- assertTrue(map1.toString().contains("~2=2.1"));
- assertTrue(map1.toString().contains("NULL=null"));
- assertTrue(map1.toString().contains("nothing=null"));
- }
-
- @Test
- public void testCustomToString() {
- ConcurrentNeutralValueMap map1 = new ConcurrentNeutralValueMap<>(Float.NaN);
- map1.put("0", 0f);
- map1.put("NULL", null);
- assertTrue(map1.toString().contains("0=0.0"));
- assertTrue(map1.toString().contains("NULL=NaN"));
- }
-
- @Test
- public void testEquals() {
- {
- ConcurrentNeutralValueMap map1 = new ConcurrentNeutralValueMap<>();
- ConcurrentNeutralValueMap map2 = new ConcurrentNeutralValueMap<>();
- map1.put("0", 0f);
- map1.put("NULL", null);
- map2.put("NULL", null);
- map2.put("0", 0f);
- assertEquals(map1.hashCode(), map2.hashCode());
- assertEquals(map1, map2);
- }
- {
- ConcurrentNeutralValueMap map1 = new ConcurrentNeutralValueMap<>();
- ConcurrentNeutralValueMap map2 = new ConcurrentNeutralValueMap<>();
- map1.put("0", 0f);
- map1.put("1", 1f);
- map1.put("NULL", null);
- map2.put("NULL", null);
- map2.put("0", 0f);
- assertNotEquals(map1.hashCode(), map2.hashCode());
- assertNotEquals(map1, map2);
- }
- {
- ConcurrentNeutralValueMap map1 = new ConcurrentNeutralValueMap<>(Float.NaN);
- ConcurrentNeutralValueMap map2 = new ConcurrentNeutralValueMap<>(Float.NaN);
- map1.put("0", 0f);
- map1.put("NULL", null);
- map2.put("NULL", null);
- map2.put("0", 0f);
- assertEquals(map1.hashCode(), map2.hashCode());
- assertEquals(map1, map2);
- }
- {
- ConcurrentNeutralValueMap map1 = new ConcurrentNeutralValueMap<>(Float.NaN);
- ConcurrentNeutralValueMap map2 = new ConcurrentNeutralValueMap<>(Float.NaN);
- map1.put("0", 0f);
- map1.put("1", 1f);
- map1.put("NULL", null);
- map2.put("NULL", null);
- map2.put("0", 0f);
- assertNotEquals(map1.hashCode(), map2.hashCode());
- assertNotEquals(map1, map2);
- }
- }
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ReparentingTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ReparentingTest.java
deleted file mode 100644
index 763a6241706..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ReparentingTest.java
+++ /dev/null
@@ -1,387 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- ******************************************************************************/
-
-package org.eclipse.e4.core.internal.tests.contexts;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.eclipse.e4.core.contexts.ContextFunction;
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.contexts.RunAndTrack;
-import org.eclipse.e4.core.internal.tests.contexts.inject.ObjectSuperClass;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test for changing a context's parent.
- */
-public class ReparentingTest {
-
-
- /**
- * Tests handling of a context function defined in the parent when the parent is changed to no
- * longer have the function.
- */
- @Test
- public void testContextFunctionInParentRemove() {
- IEclipseContext parent = EclipseContextFactory.create("parent");
- final IEclipseContext child = parent.createChild("child");
- parent.set("sum", new AddContextFunction());
- parent.set("x", Integer.valueOf(3));
- parent.set("y", Integer.valueOf(3));
- child.set("x", Integer.valueOf(1));
- child.set("y", Integer.valueOf(1));
- assertEquals(6, ((Integer) parent.get("sum")).intValue());
- assertEquals(2, ((Integer) child.get("sum")).intValue());
- child.setParent(EclipseContextFactory.create());
- assertEquals(6, ((Integer) parent.get("sum")).intValue());
- assertNull(child.get("sum"), "Expected null but was: " + child.get("sum"));
- }
-
- /**
- * Tests handling of a context function defined in the parent when the parent is changed to have
- * the function
- */
- @Test
- public void testContextFunctionInParentAdd() {
- // setup
- IEclipseContext parent = EclipseContextFactory.create();
- final IEclipseContext child = parent.createChild();
- child.set("x", Integer.valueOf(1));
- child.set("y", Integer.valueOf(1));
- assertEquals(null, parent.get("sum"));
- assertEquals(null, child.get("sum"));
-
- // switch parent
- IEclipseContext newParent = EclipseContextFactory.create();
- child.setParent(newParent);
- newParent.set("sum", new AddContextFunction());
- assertEquals(0, ((Integer) newParent.get("sum")).intValue());
- assertEquals(2, ((Integer) child.get("sum")).intValue());
-
- // changed values in parent shouldn't affect child
- newParent.set("x", Integer.valueOf(3));
- newParent.set("y", Integer.valueOf(3));
- assertEquals(6, ((Integer) newParent.get("sum")).intValue());
- assertEquals(2, ((Integer) child.get("sum")).intValue());
- }
-
- @Test
- public void testContextFunctionNullBecomeParent() {
- final IEclipseContext child = EclipseContextFactory.create();
- child.set("sum", new AddContextFunction());
- assertEquals(0, ((Integer) child.get("sum")).intValue());
- IEclipseContext parent = EclipseContextFactory.create();
- parent.set("x", Integer.valueOf(3));
- parent.set("y", Integer.valueOf(3));
- child.setParent(parent);
- assertEquals(6, ((Integer) child.get("sum")).intValue());
-
- }
-
- @Test
- public void testContextFunctionParentBecomeNull() {
- IEclipseContext parent = EclipseContextFactory.create();
- final IEclipseContext child = parent.createChild();
- parent.set("x", Integer.valueOf(3));
- parent.set("y", Integer.valueOf(3));
- child.set("sum", new AddContextFunction());
- assertEquals(6, ((Integer) child.get("sum")).intValue());
- child.setParent(null);
- assertEquals(0, ((Integer) child.get("sum")).intValue());
- }
-
- @Test
- public void testContextFunctionSwitchParent() {
- IEclipseContext parent = EclipseContextFactory.create();
- final IEclipseContext child = parent.createChild();
- parent.set("x", Integer.valueOf(3));
- parent.set("y", Integer.valueOf(3));
- child.set("sum", new AddContextFunction());
- assertEquals(6, ((Integer) child.get("sum")).intValue());
- IEclipseContext newParent = EclipseContextFactory.create();
- newParent.set("x", Integer.valueOf(1));
- newParent.set("y", Integer.valueOf(1));
- child.setParent(newParent);
- assertEquals(2, ((Integer) child.get("sum")).intValue());
- }
-
- /**
- * Tests a child switching from a null parent to a non-null parent.
- */
- @Test
- public void testRunAndTrackNullBecomesParent() {
- final String[] value = new String[1];
- final IEclipseContext child = EclipseContextFactory.create();
- child.runAndTrack(new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- value[0] = (String) child.get("x");
- return true;
- }
- });
- assertEquals(null, value[0]);
- IEclipseContext parent = EclipseContextFactory.create();
- parent.set("x", "newParent");
- child.setParent(parent);
- assertEquals("newParent", value[0]);
- }
-
- /**
- * Tests a child switching from a non-null parent to a null parent.
- */
- @Test
- public void testRunAndTrackParentBecomeNull() {
- final String[] value = new String[1];
- IEclipseContext parent = EclipseContextFactory.create();
- final IEclipseContext child = parent.createChild();
- parent.set("x", "oldParent");
- child.runAndTrack(new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- value[0] = (String) child.get("x");
- return true;
- }
- });
- assertEquals("oldParent", value[0]);
- child.setParent(null);
- assertNull(value[0]);
- }
-
- @Test
- public void testRunAndTrackSwitchParent() {
- final String[] value = new String[1];
- IEclipseContext parent = EclipseContextFactory.create();
- final IEclipseContext child = parent.createChild();
- parent.set("x", "oldParent");
- child.runAndTrack(new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- value[0] = (String) child.get("x");
- return true;
- }
- });
- assertEquals("oldParent", value[0]);
- IEclipseContext newParent = EclipseContextFactory.create();
- newParent.set("x", "newParent");
- child.setParent(newParent);
- assertEquals("newParent", value[0]);
- }
-
- /**
- * Tests an object consuming simple values from a parent context, and a parent change causes a
- * change in simple values. TODO: Still fails
- */
- @Test
- public void testInjectSwitchParent() {
-
- IEclipseContext oldParent = EclipseContextFactory.create();
- oldParent.set("String", "oldField");
- oldParent.set(String.class.getName(), "old");
- oldParent.set(Float.class.getName(), Float.valueOf(12.3f));
- IEclipseContext newParent = EclipseContextFactory.create();
- newParent.set("String", "newField");
- newParent.set(String.class.getName(), "new");
- newParent.set(Float.class.getName(), Float.valueOf(34.5f));
- IEclipseContext child = oldParent.createChild();
-
- ObjectSuperClass object = new ObjectSuperClass();
- ContextInjectionFactory.inject(object, child);
- assertEquals(1, object.setStringCalled);
- assertEquals("old", object.getStringViaMethod());
-
- child.setParent(newParent);
- assertEquals("new", object.getStringViaMethod());
- assertEquals(2, object.setStringCalled);
-
- }
-
- /**
- * Tests an object consuming services from a grandparent. A parent switch where the grandparent
- * stays unchanged should ideally not cause changes for the injected object.
- */
- @Test
- public void testInjectSwitchParentSameGrandparent() {
- IEclipseContext grandpa = EclipseContextFactory.create();
- grandpa.set("String", "field");
- grandpa.set(String.class.getName(), "s");
- grandpa.set(Float.class.getName(), Float.valueOf(12.3f));
-
- IEclipseContext oldParent = grandpa.createChild();
- IEclipseContext newParent = grandpa.createChild();
- IEclipseContext child = oldParent.createChild();
-
- ObjectSuperClass object = new ObjectSuperClass();
- ContextInjectionFactory.inject(object, child);
- assertEquals(1, object.setStringCalled);
-
- child.setParent(newParent);
- assertEquals(1, object.setStringCalled);
- }
-
- @Test
- public void testUpdateSameParent() {
- final Boolean[] called = new Boolean[1] ;
- IEclipseContext parent = EclipseContextFactory.create("parent");
- IEclipseContext newParent = EclipseContextFactory.create("newParent");
- IEclipseContext child = parent.createChild("child");
- parent.set("x", "1");
- newParent.set("x", "2");
-
- child.runAndTrack(new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- called[0] = true;
- context.get("x"); // creates a link
- return true;
- }
- });
- called[0] = false;
-
- // make sure setting parent to the same value does not trigger updates
- child.setParent(parent);
- assertFalse(called[0]);
-
- child.setParent(newParent);
- assertTrue(called[0]);
- }
-
- static public class TestService {
- // empty
- }
-
- @Test
- public void testUpdateSameParentCalculated() {
- final int[] testServiceCount = new int[1];
- testServiceCount[0] = 0;
- IEclipseContext parentContext = EclipseContextFactory.create("parent");
- parentContext.set(TestService.class.getName(), new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- testServiceCount[0]++;
- return ContextInjectionFactory.make(TestService.class, context);
- }
- });
-
- IEclipseContext childContext = parentContext.createChild("child");
- childContext.get(TestService.class);
- assertEquals(1, testServiceCount[0]);
-
- childContext.setParent(childContext.getParent());
- assertEquals(1, testServiceCount[0]);
- }
-
- @Test
- public void testBug468048_contextFunction() {
- IEclipseContext p1 = EclipseContextFactory.create("parent1");
- p1.set("sample", new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context) {
- return Integer.valueOf(1);
- }
- });
-
- IEclipseContext p2 = EclipseContextFactory.create("parent2");
- p2.set("sample", new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context) {
- return Integer.valueOf(2);
- }
- });
-
- final IEclipseContext intermed = p1.createChild("intermed");
-
- final IEclipseContext leaf = intermed.createChild("leaf");
- assertEquals(Integer.valueOf(1), leaf.get("sample"));
- intermed.setParent(p2);
- assertEquals(Integer.valueOf(2), leaf.get("sample"));
- }
-
- @Test
- public void testBug468048_injection() {
- IEclipseContext p1 = EclipseContextFactory.create("parent1");
- p1.set("sample", new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context) {
- return Integer.valueOf(1);
- }
- });
-
- IEclipseContext p2 = EclipseContextFactory.create("parent2");
- p2.set("sample", new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context) {
- return Integer.valueOf(2);
- }
- });
-
- final IEclipseContext intermed = p1.createChild("intermed");
-
- final IEclipseContext leaf = intermed.createChild("leaf");
- Bug468048 b = ContextInjectionFactory.make(Bug468048.class, leaf);
-
- assertEquals(Integer.valueOf(1), b.sample);
- intermed.setParent(p2);
- assertEquals(Integer.valueOf(2), b.sample);
- }
-
- @Test
- public void testContextFunctionSwitchParent_2() {
- IEclipseContext superParent = EclipseContextFactory.create("root");
-
- IEclipseContext parent = superParent.createChild("parent-1");
- final IEclipseContext child = parent.createChild("child-1");
- child.set("x", Integer.valueOf(3));
- child.set("y", Integer.valueOf(3));
-
- superParent.set("sum", new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- if (context != child) {
- throw new IllegalStateException("Invalid context state");
- }
- return (Integer) context.get("x") + (Integer) context.get("y");
- }
- });
-
- Bug541498 bug = ContextInjectionFactory.make(Bug541498.class, child);
- assertEquals(Integer.valueOf(6), bug.value);
-
- IEclipseContext newParent = superParent.createChild("parent-2");
- child.setParent(newParent);
-
- assertEquals(Integer.valueOf(6), bug.value);
- }
-
- public static class Bug541498 {
- @Inject
- @Named("sum")
- Integer value;
- }
-
- public static class Bug468048 {
- @Inject
- @Named("sample")
- public Integer sample;
-
- }
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/RunAndTrackTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/RunAndTrackTest.java
deleted file mode 100644
index 8c34e328a9f..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/RunAndTrackTest.java
+++ /dev/null
@@ -1,430 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- ******************************************************************************/
-
-package org.eclipse.e4.core.internal.tests.contexts;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.e4.core.contexts.ContextFunction;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.contexts.RunAndTrack;
-import org.eclipse.e4.core.internal.tests.CoreTestsActivator;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Test;
-
-/**
- * Tests for {@link org.eclipse.e4.core.contexts.RunAndTrack}.
- */
-public class RunAndTrackTest {
-
- private static final class TestRAT extends RunAndTrack {
-
-
- private final String varName;
- private Object varValue;
- private int calls = 0;
-
- public TestRAT(String varName) {
- this.varName = varName;
- }
-
- @Override
- public boolean changed(IEclipseContext context) {
- ++calls;
- varValue = context.get(varName);
- return true;
- }
-
- public int getCalls() {
- return calls;
- }
-
- public Object getVarValue() {
- return varValue;
- }
-
- public void resetCalls() {
- calls = 0;
- }
-
- }
-
- private static class ActivePartLookupFunction extends ContextFunction {
-
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- IEclipseContext childContext = (IEclipseContext) context.getLocal(ACTIVE_CHILD);
- if (childContext != null) {
- return childContext.get(ACTIVE_PART);
- }
- return context.get(INTERNAL_LOCAL_PART);
- }
-
- }
-
- static final String ACTIVE_CHILD = "activeChild";
-
- static final String ACTIVE_PART = "activePart";
-
- static final String ACTIVE_PART_ID = "activePartId";
-
- static final String INTERNAL_LOCAL_PART = "localPart";
-
- private final List createdContexts = new ArrayList<>();
-
- private IEclipseContext createContext(IEclipseContext parentContext, String level) {
- IEclipseContext childContext = parentContext.createChild(level);
- createdContexts.add(childContext);
- return childContext;
- }
-
- private IEclipseContext getGlobalContext() {
- IEclipseContext serviceContext = EclipseContextFactory
- .getServiceContext(CoreTestsActivator.getDefault().getBundleContext());
- // global initialization and setup, usually done by workbench
- IEclipseContext appContext = createContext(serviceContext, "globalContext");
-
- appContext.set("globalContext", appContext);
-
- return appContext;
- }
-
- private IEclipseContext[] createNextLevel(IEclipseContext parent, String prefix, int num) {
- assertTrue(num > 0);
- IEclipseContext[] contexts = new IEclipseContext[num];
- for (int i = 0; i < num; i++) {
- contexts[i] = createContext(parent, prefix + i);
- contexts[i].set(INTERNAL_LOCAL_PART, prefix + i);
- }
- parent.set(ACTIVE_CHILD, contexts[0]);
- return contexts;
- }
-
- @AfterEach
- public void tearDown() throws Exception {
- for (IEclipseContext context : createdContexts) {
- context.dispose();
- }
- createdContexts.clear();
- }
-
- @Test
- public void testActiveChain() throws Exception {
- final IEclipseContext workbenchContext = getGlobalContext();
- workbenchContext.set("activePart", new ActivePartLookupFunction());
- final IEclipseContext[] windows = createNextLevel(workbenchContext, "window", 1);
- createNextLevel(windows[0], "part", 2);
- assertEquals("part0", workbenchContext.get(ACTIVE_PART));
- }
-
- @Test
- public void testActiveChange() throws Exception {
- final IEclipseContext workbenchContext = getGlobalContext();
- workbenchContext.set("activePart", new ActivePartLookupFunction());
- final IEclipseContext[] windows = createNextLevel(workbenchContext, "window", 1);
- final IEclipseContext[] parts = createNextLevel(windows[0], "part", 2);
- assertEquals("part0", workbenchContext.get(ACTIVE_PART));
-
- windows[0].set(ACTIVE_CHILD, parts[1]);
- assertEquals("part1", workbenchContext.get(ACTIVE_PART));
- }
-
- /**
- * There was a failing scenario in the legacy workbench support. This captures the hierarchy and
- * function (without any workbench level references). It should be updated when we figure out
- * the failing scenario :-)
- */
- @Test
- public void testRunAndTrackComplex() throws Exception {
- final IEclipseContext workbenchContext = getGlobalContext();
- workbenchContext.set("activePart", new ActivePartLookupFunction());
- final IEclipseContext[] windows = createNextLevel(workbenchContext, "window", 1);
- windows[0].runAndTrack(new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- final Object part = windows[0].get(ACTIVE_PART);
- windows[0].set(ACTIVE_PART_ID, part);
- return true;
- }
-
- @Override
- public String toString() {
- return ACTIVE_PART_ID;
- }
- });
-
- final IEclipseContext[] mainSashes = createNextLevel(windows[0], "mainSash", 2);
- createNextLevel(mainSashes[1], "editorArea", 1);
- final IEclipseContext[] viewSashes = createNextLevel(mainSashes[0], "viewSashes", 2);
-
- // create package explorer stack
- final IEclipseContext[] packageStack = createNextLevel(viewSashes[0], "packageStack", 1);
- final IEclipseContext[] packageViews = createNextLevel(packageStack[0], "packageViews", 3);
- assertNotNull(packageViews);
- assertEquals("packageViews0", windows[0].get(ACTIVE_PART));
- assertEquals("packageViews0", windows[0].get(ACTIVE_PART_ID));
-
- // create problems stack
- final IEclipseContext[] problemsStack = createNextLevel(viewSashes[1], "problemsStack", 1);
- final IEclipseContext[] problemsViews = createNextLevel(problemsStack[0], "problemViews", 5);
- assertNotNull(problemsViews);
- assertEquals("packageViews0", windows[0].get(ACTIVE_PART));
- assertEquals("packageViews0", windows[0].get(ACTIVE_PART_ID));
-
- assertEquals("problemViews0", problemsStack[0].get(ACTIVE_PART));
- // this won't change since it is a "runAndTrack" at the window context
- // level
- assertEquals("packageViews0", problemsStack[0].get(ACTIVE_PART_ID));
-
- // set the "problems view" active, propagating the information up
- // the active chain.
- problemsStack[0].set(ACTIVE_CHILD, problemsViews[0]);
- viewSashes[1].set(ACTIVE_CHILD, problemsStack[0]);
- mainSashes[0].set(ACTIVE_CHILD, viewSashes[1]);
- windows[0].set(ACTIVE_CHILD, mainSashes[0]);
- workbenchContext.set(ACTIVE_CHILD, windows[0]);
-
- assertEquals("problemViews0", windows[0].get(ACTIVE_PART));
- assertEquals("problemViews0", windows[0].get(ACTIVE_PART_ID));
-
- assertEquals("packageViews0", packageStack[0].get(ACTIVE_PART));
- assertEquals("problemViews0", packageStack[0].get(ACTIVE_PART_ID));
- }
-
- @Test
- public void testRunAndTrackSimple() throws Exception {
- final IEclipseContext workbenchContext = getGlobalContext();
- workbenchContext.set("activePart", new ActivePartLookupFunction());
- final IEclipseContext[] windows = createNextLevel(workbenchContext, "window", 1);
- windows[0].runAndTrack(new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- final Object part = windows[0].get(ACTIVE_PART);
- windows[0].set(ACTIVE_PART_ID, part);
- return true;
- }
-
- @Override
- public String toString() {
- return ACTIVE_PART_ID;
- }
- });
-
- final IEclipseContext[] parts = createNextLevel(windows[0], "part", 2);
- assertEquals("part0", workbenchContext.get(ACTIVE_PART));
- assertEquals("part0", windows[0].get(ACTIVE_PART_ID));
-
- windows[0].set(ACTIVE_CHILD, parts[1]);
- assertEquals("part1", windows[0].get(ACTIVE_PART));
- assertEquals("part1", windows[0].get(ACTIVE_PART_ID));
- }
-
- /**
- * Test how a RAT responds to a change hidden from it; changed value is == to child value
- */
- @Test
- public void testSetHiddenValueToChildObject() {
- final String newRootValue = "child";
-
- doHiddenValueChangeTest(newRootValue);
- }
-
- /**
- * Test how a RAT responds to a change hidden from it; changed value is != to child value
- */
- @Test
- public void testSetHiddenValueToDifferentObject() {
- final String newRootValue = "other";
-
- doHiddenValueChangeTest(newRootValue);
- }
-
- /**
- * Test how a RAT responds to a change hidden from it; changed value is != to child value (but is .equals())
- */
- @Test
- public void testSetHiddenValueToObjectEqualToChild() {
- // avoid compiler's pushing all my strings into a single string pool
- final String newRootValue = new String("child");
-
- doHiddenValueChangeTest(newRootValue);
- }
-
- /**
- * Test how a RAT responds to a change hidden from it; changed value is == to root value
- */
- @Test
- public void testSetHiddenValueToRootObject() {
- final String newRootValue = "root";
-
- doHiddenValueChangeTest(newRootValue);
- }
-
- /**
- * Test how a RAT responds to a change hidden from it; changed value is != to root value (but is .equals())
- */
- @Test
- public void testSetHiddenValueToEqualRootObject() {
- // avoid compiler's pushing all my strings into a single string pool
- final String newRootValue = new String("root");
-
- doHiddenValueChangeTest(newRootValue);
- }
-
- /**
- * Test how a RAT responds to a change hidden from it; changed value is == to root value
- */
- @Test
- public void testSetHiddenValueToNull() {
- final String newRootValue = null;
-
- doHiddenValueChangeTest(newRootValue);
- }
-
- /**
- * Perform a hidden value test that verifies that the test RAT does not run, and
- * that has last seen the initial value in the child context (namely "child").
- * @param newRootValue the new value for the variable 'v' in the root context.
- * @see #doHiddenValueChangeTest(ITestAction, Object, int)
- */
- void doHiddenValueChangeTest(final String newRootValue) {
- doHiddenValueChangeTest((IEclipseContext root, String var) -> {
- root.set(var, newRootValue);
- }, "child", 0);
- }
-
- /**
- * Interface defining function
- */
- private interface ITestAction {
-
- void execute(IEclipseContext root, String var);
-
- }
- /**
- * Create a two level hierarchy of contexts, each defining a variable 'v' with values 'root' and 'child', respectively.
- * Create and install a RAT on the child context that is dependent on 'v'.
- * Run testAction.
- * Tests whether the RAT ran the expected number of times,
- * and tests last value of 'v' that the RAT saw.
- * @param testAction the context action to perform as part of the test
- * @param expectedValue the expected last value of variable 'v' that the RAT saw.
- * @param expectedRATCalls the expected number of times the RAT was run in response to testAction
- */
- void doHiddenValueChangeTest(ITestAction testAction, Object expectedValue, int expectedRATCalls) {
- final IEclipseContext root = getGlobalContext();
- final IEclipseContext child = root.createChild("child");
-
- root.set("v", "root");
- child.set("v", "child");
- final TestRAT testRAT = new TestRAT("v");
-
- // install the RAT
- child.runAndTrack(testRAT);
- assertEquals("child", testRAT.getVarValue());
- assertEquals(1, testRAT.getCalls());
-
- testRAT.resetCalls();
- // set the new root value
- testAction.execute(root, "v");
- assertEquals(expectedValue, testRAT.getVarValue());
- assertEquals(expectedRATCalls, testRAT.getCalls());
- }
-
- /**
- * Test that a variable change in a context hidden from a RAT in
- * a child context does not re-run the RAT.
- */
- @Test
- public void testRemoveHiddenVariable() {
- doHiddenValueChangeTest((IEclipseContext root, String var) -> {
- root.remove(var);
- }, "child", 0);
- }
-
- /**
- * Test that setting a context variable to it's existing
- * value does not re-run dependent RATs
- */
- @Test
- public void testSetContextVarToSameObject() {
- doSingleContextChangeTest((IEclipseContext root, String var) -> {
- root.set(var, "root");
- }, "root", 0);
- }
-
- /**
- * Test that setting a context variable to a value that {@link Object#equals(Object) equals}
- * the current value, but is same object DOES re-run dependent RATs.
- */
- @Test
- public void testSetContextVarToEqualObject() {
- doSingleContextChangeTest((IEclipseContext root, String var) -> {
- root.set(var, new String("root"));
- }, "root", 1);
- }
-
- /**
- * Test that setting a context variable to a different object, not equal to the
- * current value re-runs dependent RATs.
- */
- @Test
- public void testSetContextVarToOtherObject() {
- doSingleContextChangeTest((IEclipseContext root, String var) -> {
- root.set(var, "other");
- }, "other", 1);
- }
-
- /**
- * Test that removing a context variable re-runs dependent RATs.
- */
- @Test
- public void testRemoveContextVar() {
- doSingleContextChangeTest(IEclipseContext::remove, null, 1);
-
- }
-
- /**
- * Creates a context, sets a variable 'v' to "root", creates a RAT dependent on 'v' in the context,
- * then executes testAction and tests whether the RAT ran the expected number of times,
- * and tests last value of 'v' that the RAT saw.
- * @param testAction the context action to perform as part of the test
- * @param expectedValue the expected last value of variable 'v' that the RAT saw.
- * @param expectedRATCalls the expected number of times the RAT was run in response to testAction
- */
- private void doSingleContextChangeTest(ITestAction testAction, Object expectedValue, int expectedRATCalls) {
- final IEclipseContext root = getGlobalContext();
-
- root.set("v", "root");
-
- final TestRAT testRAT = new TestRAT("v");
- // install the RAT
- root.runAndTrack(testRAT);
- assertEquals("root", testRAT.getVarValue());
- assertEquals(1, testRAT.getCalls());
-
- testRAT.resetCalls();
- testAction.execute(root, "v");
- assertEquals(expectedRATCalls, testRAT.getCalls());
- assertEquals(expectedValue, testRAT.getVarValue());
-
- }
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/StrongIterableTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/StrongIterableTest.java
deleted file mode 100644
index 33019cebbc5..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/StrongIterableTest.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021 Joerg Kubitz.
- *
- * 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:
- * Joerg Kubitz - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.e4.core.internal.tests.contexts;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.lang.ref.Reference;
-import java.lang.ref.WeakReference;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import java.util.concurrent.ConcurrentLinkedDeque;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.function.Supplier;
-import java.util.stream.StreamSupport;
-
-import org.eclipse.e4.core.internal.contexts.StrongIterable;
-import org.junit.jupiter.api.Test;
-
-@SuppressWarnings("restriction")
-public class StrongIterableTest {
-
- @Test
- public void testStrongIterableDeque() {
- testStrongIterable(ConcurrentLinkedDeque::new);
- }
-
- @Test
- public void testStrongIterableQueue() {
- testStrongIterable(ConcurrentLinkedQueue::new);
- }
-
- void testStrongIterable(Supplier>> constructor) {
- testIterate(constructor.get());
- testRemoveWhileIterate(constructor.get());
- testRemoveAll(constructor.get());
- testRemoveByClear(constructor.get());
- testNextWithoutHasNext(constructor.get());
- }
-
- private void testNextWithoutHasNext(Collection> iterable) {
- WeakReference EMPTY1 = new WeakReference<>(null);
- WeakReference EMPTY2 = new WeakReference<>(null);
- WeakReference ONE = new WeakReference<>(1);
- WeakReference TWO = new WeakReference<>(2);
- WeakReference THREE = new WeakReference<>(3);
- iterable.add(EMPTY1); // ignored
- iterable.add(ONE);
- iterable.add(TWO);
- iterable.add(EMPTY2); // ignored
- iterable.add(THREE);
- StrongIterable strongIterable = new StrongIterable<>(iterable);
- {
- Iterator i = strongIterable.iterator();
- assertEquals(1, i.next().intValue());
- assertEquals(2, i.next().intValue());
- assertEquals(3, i.next().intValue());
- try {
- i.next();
- } catch (NoSuchElementException e) {
- assertNotNull(e);
- }
- }
- {
- Iterator i = strongIterable.iterator();
- assertEquals(1, i.next().intValue());
- assertEquals(3L, count(strongIterable));
- assertEquals(3L, poorMansCount(strongIterable));
- i.remove();
- assertEquals(2L, count(strongIterable));
- assertEquals(2L, poorMansCount(strongIterable));
- assertEquals(2, i.next().intValue());
- i.remove();
- assertEquals(3, i.next().intValue());
- i.remove();
- try {
- i.next();
- } catch (NoSuchElementException e) {
- assertNotNull(e);
- }
- }
- assertEquals(0L, count(strongIterable));
- assertEquals(0L, poorMansCount(strongIterable));
- }
-
- void testRemoveWhileIterate(Collection> iterable) {
- WeakReference ONE = new WeakReference<>(1);
- WeakReference TWO = new WeakReference<>(2);
- WeakReference THREE = new WeakReference<>(3);
- iterable.add(ONE);
- iterable.add(TWO);
- iterable.add(THREE);
-
- assertEquals(3L, poorMansCount(iterable));
- StrongIterable strongIterable = new StrongIterable<>(iterable);
- {
- Iterator i = strongIterable.iterator();
- assertEquals(3L, count(strongIterable));
- assertEquals(3L, poorMansCount(strongIterable));
-
- assertTrue(i.hasNext());
- assertEquals(1, i.next().intValue());
- assertTrue(i.hasNext());
- assertEquals(2, i.next().intValue());
- i.remove(); // remove TWO
- assertEquals(2L, count(strongIterable));
- assertEquals(2L, poorMansCount(strongIterable));
- assertTrue(i.hasNext());
- assertEquals(3, i.next().intValue());
- i.remove(); // remove THREE
- assertEquals(1L, count(strongIterable));
- assertEquals(1L, poorMansCount(strongIterable));
- assertFalse(i.hasNext());
- try {
- i.next();
- } catch (NoSuchElementException e) {
- assertNotNull(e);
- }
- }
- }
-
- void testRemoveAll(Collection> iterable) {
- WeakReference ONE = new WeakReference<>(1);
- WeakReference TWO = new WeakReference<>(2);
- WeakReference THREE = new WeakReference<>(3);
- iterable.add(ONE);
- iterable.add(TWO);
- iterable.add(THREE);
-
- StrongIterable strongIterable = new StrongIterable<>(iterable);
- assertEquals(3L, count(strongIterable));
- for (Iterator i = strongIterable.iterator(); i.hasNext();) {
- i.next();
- i.remove();
- }
- assertEquals(0L, count(strongIterable));
- assertEquals(0L, poorMansCount(strongIterable));
- }
-
- void testRemoveByClear(Collection> iterable) {
- WeakReference ONE = new WeakReference<>(1);
- WeakReference TWO = new WeakReference<>(2);
- WeakReference THREE = new WeakReference<>(3);
- iterable.add(ONE);
- iterable.add(TWO);
- iterable.add(THREE);
-
- StrongIterable strongIterable = new StrongIterable<>(iterable);
- assertEquals(3L, count(strongIterable));
- for (Reference ref : iterable) {
- ref.clear();
- }
- assertEquals(0L, count(strongIterable));
- }
-
- void testIterate(Collection> iterable) {
- WeakReference EMPTY1 = new WeakReference<>(null);
- WeakReference EMPTY2 = new WeakReference<>(null);
- WeakReference ONE = new WeakReference<>(1);
- WeakReference TWO = new WeakReference<>(2);
- WeakReference THREE = new WeakReference<>(3);
- iterable.add(EMPTY1); // ignored
- iterable.add(ONE);
- iterable.add(TWO);
- iterable.add(EMPTY2); // ignored
- iterable.add(THREE);
-
- StrongIterable strongIterable = new StrongIterable<>(iterable);
- {
- Iterator i = strongIterable.iterator();
- assertEquals(3L, count(strongIterable));
- assertTrue(i.hasNext());
- assertEquals(1, i.next().intValue());
- assertTrue(i.hasNext());
- assertEquals(2, i.next().intValue());
- assertTrue(i.hasNext());
- assertEquals(3, i.next().intValue());
- assertFalse(i.hasNext());
- try {
- i.next();
- } catch (NoSuchElementException e) {
- assertNotNull(e);
- }
- }
- for (Integer strong : strongIterable) {
- assertNotNull(strong);
- }
-
- assertTrue(iterable.remove(TWO)); // remove
-
- for (Integer strong : strongIterable) {
- assertNotNull(strong);
- }
- {
- Iterator i = strongIterable.iterator();
- assertEquals(2L, count(strongIterable));
- assertTrue(i.hasNext());
- assertEquals(1, i.next().intValue());
- assertTrue(i.hasNext());
- assertEquals(3, i.next().intValue());
- assertFalse(i.hasNext());
- try {
- i.next();
- } catch (NoSuchElementException e) {
- assertNotNull(e);
- }
- }
-
- ONE.clear(); // remove on iterate
-
- {
- Iterator i = strongIterable.iterator();
- assertEquals(1L, count(strongIterable));
- assertTrue(i.hasNext());
- assertEquals(3, i.next().intValue());
- assertFalse(i.hasNext());
- try {
- i.next();
- } catch (NoSuchElementException e) {
- assertNotNull(e);
- }
- for (Integer strong : strongIterable) {
- assertNotNull(strong);
- }
- }
-
- THREE.clear(); // remove on iterate
-
- {
- Iterator i = strongIterable.iterator();
- assertEquals(0L, count(strongIterable));
- assertFalse(i.hasNext());
- try {
- i.next();
- } catch (NoSuchElementException e) {
- assertNotNull(e);
- }
- for (Integer strong : strongIterable) {
- assertNotNull(strong);
- }
- }
- }
-
- private long count(Iterable> i) {
- return StreamSupport.stream(i.spliterator(), false).count();
- }
-
- private long poorMansCount(Iterable> i) {
- long count = -1;
- try {
- for (Iterator> it = i.iterator();; it.next()) {
- count++;
- }
- } catch (NoSuchElementException expected) {
- }
- return count;
- }
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ActivationInjectionTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ActivationInjectionTest.java
deleted file mode 100644
index 63b4e5fafec..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ActivationInjectionTest.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- ******************************************************************************/
-
-package org.eclipse.e4.core.internal.tests.contexts.inject;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.eclipse.e4.core.contexts.Active;
-import org.eclipse.e4.core.contexts.ContextFunction;
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.di.annotations.Optional;
-import org.junit.jupiter.api.Test;
-
-public class ActivationInjectionTest {
-
- static public class TestRAT extends ContextFunction {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- IEclipseContext activeContext = context.getActiveLeaf();
- // returns name of the context
- return "_" + activeContext.get("debugString") + "_";
- }
- }
-
- static public class TestObject {
-
- public String name;
-
- @Inject
- public TestObject() {
- //
- }
-
- @Inject
- public void setActiveContextName(@Named("testRAT") String name) {
- this.name = name;
- }
- }
-
- @Test
- public void testContextActivation() {
- IEclipseContext rootContext = EclipseContextFactory.create("root");
- rootContext.set("testRAT", new TestRAT());
-
- IEclipseContext child1 = rootContext.createChild("child1");
- IEclipseContext child11 = child1.createChild("child11");
- IEclipseContext child12 = child1.createChild("child12");
-
- IEclipseContext child2 = rootContext.createChild("child2");
- IEclipseContext child21 = child2.createChild("child21");
- IEclipseContext child22 = child2.createChild("child22");
-
- TestObject testObject = ContextInjectionFactory.make(TestObject.class, rootContext);
-
- child12.activateBranch();
- assertEquals(child12, rootContext.getActiveLeaf());
- assertEquals("_child12_", testObject.name);
-
- child21.activateBranch();
- assertEquals(child21, rootContext.getActiveLeaf());
- assertEquals("_child21_", testObject.name);
-
- child21.deactivate();
- assertEquals(child2, rootContext.getActiveLeaf());
- assertEquals("_child2_", testObject.name);
-
- child22.activateBranch();
- assertEquals(child22, rootContext.getActiveLeaf());
- assertEquals("_child22_", testObject.name);
-
- child11.activateBranch();
- assertEquals(child11, rootContext.getActiveLeaf());
- assertEquals("_child11_", testObject.name);
-
- child11.deactivate();
- assertEquals(child1, rootContext.getActiveLeaf());
- assertEquals("_child1_", testObject.name);
-
- child1.dispose();
- child2.activateBranch();
- assertEquals(child22, rootContext.getActiveLeaf());
- assertEquals("_child22_", testObject.name);
- }
-
- static public class TestObjectInject {
- public String name;
- @Inject
- public TestObjectInject() {
- //
- }
- @Inject
- public void setActiveContextName(@Active @Named("debugString") String name) {
- this.name = "_" + name + "_";
- }
- }
-
- @Test
- public void testActivationInjection() {
- IEclipseContext rootContext = EclipseContextFactory.create("root");
-
- IEclipseContext child1 = rootContext.createChild("child1");
- IEclipseContext child11 = child1.createChild("child11");
- IEclipseContext child12 = child1.createChild("child12");
-
- IEclipseContext child2 = rootContext.createChild("child2");
- IEclipseContext child21 = child2.createChild("child21");
- IEclipseContext child22 = child2.createChild("child22");
-
- TestObjectInject testObject = ContextInjectionFactory.make(TestObjectInject.class, rootContext);
-
- child12.activateBranch();
- assertEquals(child12, rootContext.getActiveLeaf());
- assertEquals("_child12_", testObject.name);
-
- child21.activateBranch();
- assertEquals(child21, rootContext.getActiveLeaf());
- assertEquals("_child21_", testObject.name);
-
- child21.deactivate();
- assertEquals(child2, rootContext.getActiveLeaf());
- assertEquals("_child2_", testObject.name);
-
- child22.activateBranch();
- assertEquals(child22, rootContext.getActiveLeaf());
- assertEquals("_child22_", testObject.name);
-
- child11.activateBranch();
- assertEquals(child11, rootContext.getActiveLeaf());
- assertEquals("_child11_", testObject.name);
-
- child11.deactivate();
- assertEquals(child1, rootContext.getActiveLeaf());
- assertEquals("_child1_", testObject.name);
-
- child1.dispose();
- child2.activateBranch();
- assertEquals(child22, rootContext.getActiveLeaf());
- assertEquals("_child22_", testObject.name);
- }
-
- static public class TestInject {
- @Optional @Inject @Active
- public Integer number;
- }
-
- @Test
- public void testInjection() {
- IEclipseContext rootContext = EclipseContextFactory.create("root");
-
- IEclipseContext child1 = rootContext.createChild("child1");
- child1.set(Integer.class, Integer.valueOf(1));
- IEclipseContext child11 = child1.createChild("child11");
- child11.set(Integer.class, Integer.valueOf(2));
- IEclipseContext child12 = child1.createChild("child12");
- child12.set(Integer.class, Integer.valueOf(3));
-
- IEclipseContext child2 = rootContext.createChild("child2");
- child2.set(Integer.class, Integer.valueOf(4));
- IEclipseContext child21 = child2.createChild("child21");
- child21.set(Integer.class, Integer.valueOf(5));
- IEclipseContext child22 = child2.createChild("child22");
- child22.set(Integer.class, Integer.valueOf(6));
-
- TestInject testObjectRoot = ContextInjectionFactory.make(TestInject.class, rootContext);
- TestInject testObjectChild1 = ContextInjectionFactory.make(TestInject.class, child1);
- TestInject testObjectChild2 = ContextInjectionFactory.make(TestInject.class, child2);
-
- child12.activateBranch();
- assertEquals(Integer.valueOf(3), testObjectRoot.number);
- assertEquals(Integer.valueOf(3), testObjectChild1.number);
- assertEquals(Integer.valueOf(4), testObjectChild2.number);
-
- child21.activateBranch();
- assertEquals(Integer.valueOf(5), testObjectRoot.number);
- assertEquals(Integer.valueOf(3), testObjectChild1.number);
- assertEquals(Integer.valueOf(5), testObjectChild2.number);
-
- child21.deactivate();
- assertEquals(Integer.valueOf(4), testObjectRoot.number);
- assertEquals(Integer.valueOf(3), testObjectChild1.number);
- assertEquals(Integer.valueOf(4), testObjectChild2.number);
-
- child22.activateBranch();
- assertEquals(Integer.valueOf(6), testObjectRoot.number);
- assertEquals(Integer.valueOf(3), testObjectChild1.number);
- assertEquals(Integer.valueOf(6), testObjectChild2.number);
-
- child11.activateBranch();
- assertEquals(Integer.valueOf(2), testObjectRoot.number);
- assertEquals(Integer.valueOf(2), testObjectChild1.number);
- assertEquals(Integer.valueOf(6), testObjectChild2.number);
-
- child11.deactivate();
- assertEquals(Integer.valueOf(1), testObjectRoot.number);
- assertEquals(Integer.valueOf(1), testObjectChild1.number);
- assertEquals(Integer.valueOf(6), testObjectChild2.number);
-
- child1.dispose();
- child2.activateBranch();
- assertEquals(Integer.valueOf(6), testObjectRoot.number);
- assertEquals(Integer.valueOf(6), testObjectChild2.number);
- }
-
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/AnnotationsInjectionTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/AnnotationsInjectionTest.java
index bc90c9172dd..c9e2ce141c2 100644
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/AnnotationsInjectionTest.java
+++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/AnnotationsInjectionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation and others.
+ * Copyright (c) 2009, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -16,13 +16,16 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Named;
+import javax.inject.Singleton;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
@@ -30,12 +33,12 @@
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.di.annotations.Optional;
import org.junit.jupiter.api.Test;
+
/**
* Tests for the basic context injection functionality
*/
public class AnnotationsInjectionTest {
-
@Test
public void testContextSetOneArg() {
class TestData {
@@ -109,6 +112,58 @@ public void setData(TestData arg) {
assertEquals(methodValue2, object.value);
}
+ static class ObjectBasic {
+ // Injected directly
+ @Inject
+ @Optional
+ public String injectedString;
+ @Inject
+ private Integer injectedInteger;
+
+ // Injected indirectly
+ public Double d;
+ public Float f;
+ public Character c;
+ public IEclipseContext context;
+
+ // Test status
+ public boolean finalized = false;
+ public boolean disposed = false;
+ public int setMethodCalled = 0;
+ public int setMethodCalled2 = 0;
+
+ @Inject
+ public void objectViaMethod(Double d) {
+ setMethodCalled++;
+ this.d = d;
+ }
+
+ @Inject
+ public void arguments(Float f, @Optional Character c) {
+ setMethodCalled2++;
+ this.f = f;
+ this.c = c;
+ }
+
+ @PostConstruct
+ public void postCreate(IEclipseContext context) {
+ this.context = context;
+ finalized = true;
+ }
+
+ @PreDestroy
+ public void dispose(IEclipseContext context) {
+ if (this.context != context)
+ throw new IllegalArgumentException("Unexpected context");
+ this.context = null;
+ disposed = true;
+ }
+
+ public Integer getInt() {
+ return injectedInteger;
+ }
+ }
+
/**
* Tests basic context injection
*/
@@ -157,7 +212,8 @@ class TestData {
// empty
}
class Injected {
- @Inject @Named("valueField")
+ @Inject
+ @Named("valueField")
Object injectedField;
Object methodValue;
@@ -198,6 +254,33 @@ public void injectedMethod(@Optional @Named("valueMethod") Object arg) {
}
}
+ static class OptionalAnnotations {
+ @Inject
+ @Optional
+ public Float f = null;
+
+ public Double d;
+ public String s = "ouch";
+ public Integer i;
+
+ public int methodOptionalCalled = 0;
+ public int methodRequiredCalled = 0;
+
+ @Inject
+ @Optional
+ public void methodOptional(Double d) {
+ this.d = d;
+ methodOptionalCalled++;
+ }
+
+ @Inject
+ public void methodRequired(@Optional String s, Integer i) {
+ this.s = s;
+ this.i = i;
+ methodRequiredCalled++;
+ }
+ }
+
@Test
public void testOptionalInjection() {
Integer testInt = Integer.valueOf(123);
@@ -259,37 +342,6 @@ public String something(@Optional String param) {
assertEquals(2, testObject.called);
}
- /**
- * Tests that a class with multiple inherited post-construct / pre-destroy methods.
- */
- @Test
- public void testInheritedSpecialMethods() {
- IEclipseContext context = EclipseContextFactory.create();
- context.set(Integer.class, Integer.valueOf(123));
- context.set(String.class, "abc");
- context.set(Float.class, Float.valueOf(12.3f));
-
- ObjectSubClass userObject = new ObjectSubClass();
- ContextInjectionFactory.inject(userObject, context);
- assertEquals(1, userObject.superPostConstructCount);
- assertEquals(1, userObject.subPostConstructCount);
- assertEquals(0, userObject.superPreDestroyCount);
- assertEquals(0, userObject.subPreDestroyCount);
- assertEquals(0, userObject.overriddenPreDestroyCount);
-
- context.set(Float.class, Float.valueOf(45.6f));
- assertEquals(1, userObject.superPostConstructCount);
- assertEquals(1, userObject.subPostConstructCount);
- assertEquals(0, userObject.superPreDestroyCount);
- assertEquals(0, userObject.subPreDestroyCount);
- assertEquals(0, userObject.overriddenPreDestroyCount);
-
- context.dispose();
- assertEquals(1, userObject.superPreDestroyCount);
- assertEquals(1, userObject.subPreDestroyCount);
- assertEquals(1, userObject.overriddenPreDestroyCount);
- }
-
@Test
public void testInvoke() {
class TestData {
@@ -362,4 +414,24 @@ public void setData(TestData arg) {
assertNotNull(object.value);
assertNotNull(object.directFieldInjection);
}
+
+ @Singleton
+ public static class SingletonService {
+ }
+
+ public static class NonSingletonService {
+ }
+
+ @Test
+ public void testSingleton() {
+ IEclipseContext context = EclipseContextFactory.create();
+
+ SingletonService service1 = ContextInjectionFactory.make(SingletonService.class, context);
+ SingletonService service2 = ContextInjectionFactory.make(SingletonService.class, context);
+ assertSame(service1, service2);
+
+ NonSingletonService service3 = ContextInjectionFactory.make(NonSingletonService.class, context);
+ NonSingletonService service4 = ContextInjectionFactory.make(NonSingletonService.class, context);
+ assertNotSame(service3, service4);
+ }
}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/Bug317183Test.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/Bug317183Test.java
deleted file mode 100644
index dc530e86b10..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/Bug317183Test.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- ******************************************************************************/
-
-package org.eclipse.e4.core.internal.tests.contexts.inject;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.contexts.RunAndTrack;
-import org.junit.jupiter.api.Test;
-
-public class Bug317183Test {
-
- @Test
- public void testX() {
- IEclipseContext appContext = EclipseContextFactory.create();
- IEclipseContext windowContext = appContext.createChild();
- IEclipseContext partContextA = windowContext.createChild();
- IEclipseContext partContextB = windowContext.createChild();
-
- partContextA.activateBranch();
-
- RunAndTrackImpl impl = new RunAndTrackImpl();
- windowContext.runAndTrack(impl);
-
- impl.called = false;
-
- partContextA.dispose();
- partContextB.activate();
- assertTrue(impl.called); // this fails
- }
-
- @Test
- public void testY() {
- IEclipseContext appContext = EclipseContextFactory.create();
- IEclipseContext windowContext = appContext.createChild();
- IEclipseContext partContextA = windowContext.createChild();
- IEclipseContext partContextB = windowContext.createChild();
- IEclipseContext partContextC = windowContext.createChild();
-
- partContextA.activateBranch();
-
- RunAndTrackImpl impl = new RunAndTrackImpl();
- windowContext.runAndTrack(impl);
-
- partContextB.activate();
- partContextA.dispose();
-
- impl.called = false;
-
- partContextC.activate();
- assertTrue(impl.called); // this fails
- }
-
- static class RunAndTrackImpl extends RunAndTrack {
-
- boolean called = false;
-
- @Override
- public boolean changed(IEclipseContext context) {
- context.getActiveLeaf();
- called = true;
- return true;
- }
-
- }
-
-}
-
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ComplexDisposalTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ComplexDisposalTest.java
deleted file mode 100644
index b3ecb38efdc..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ComplexDisposalTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- ******************************************************************************/
-package org.eclipse.e4.core.internal.tests.contexts.inject;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.eclipse.e4.core.contexts.ContextFunction;
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.junit.jupiter.api.Test;
-
-/**
- * See bug 296337: duplicate disposal of an object
- */
-public class ComplexDisposalTest {
-
- public static class MyTest {
- private int count = 0;
-
- @Inject
- @Named("aString")
- String string;
-
- public int getCount() {
- return count;
- }
-
- @PreDestroy
- void preDestroy() {
- count++;
- }
- }
-
- public static class TestFunction extends ContextFunction {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- return ContextInjectionFactory.make(MyTest.class, context);
- }
- }
-
- @Test
- public void testU() {
- IEclipseContext parentContext = EclipseContextFactory.create();
- parentContext.set("aString", "");
- parentContext.set(MyTest.class.getName(), new TestFunction());
- IEclipseContext context = parentContext.createChild();
-
- MyTest test = context.get(MyTest.class);
-
- assertEquals(0, test.getCount());
- context.dispose();
- assertEquals(1, test.getCount(), "Context disposed, @PreDestroy should've been called");
- parentContext.dispose();
- assertEquals(1, test.getCount(), "Parent context disposed, @PreDestroy should not have been called again");
- }
-
- @Test
- public void testV() {
- IEclipseContext parentContext = EclipseContextFactory.create();
- parentContext.set("aString", "");
- IEclipseContext context = parentContext.createChild();
-
- MyTest test = ContextInjectionFactory.make(MyTest.class, context);
-
- assertEquals(0, test.getCount());
- context.dispose();
- assertEquals(1, test.getCount(), "Context disposed, @PreDestroy should've been called");
- parentContext.dispose();
- assertEquals(1, test.getCount(), "Parent context disposed, @PreDestroy should not have been called again");
- }
-
- @Test
- public void testW() {
- IEclipseContext parentContext = EclipseContextFactory.create();
- parentContext.set("aString", "");
- IEclipseContext context = parentContext.createChild();
-
- MyTest test = new MyTest();
- ContextInjectionFactory.inject(test, context);
-
- assertEquals(0, test.getCount());
- context.dispose();
- assertEquals(1, test.getCount(), "Context disposed, @PreDestroy should've been called");
- parentContext.dispose();
- assertEquals(1, test.getCount(), "Parent context disposed, @PreDestroy should not have been called again");
- }
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextFunctionDynamicsTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextFunctionDynamicsTest.java
deleted file mode 100644
index dc2bc3b5a26..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextFunctionDynamicsTest.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- ******************************************************************************/
-package org.eclipse.e4.core.internal.tests.contexts.inject;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.eclipse.e4.core.contexts.ContextFunction;
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.di.annotations.Optional;
-import org.junit.jupiter.api.Test;
-
-public class ContextFunctionDynamicsTest {
-
- private static final String SELECTION = "selection"; //$NON-NLS-1$
-
- static class InjectTarget {
- Object input;
-
- @Inject
- @Optional
- void setInput(@Named(SELECTION) Object input) {
- this.input = input;
- }
- }
-
- /**
- * Changing context function should update injected values
- */
- @Test
- public void testChangeICF() {
- IEclipseContext context1 = EclipseContextFactory.create("context1");
- IEclipseContext context2 = context1.createChild("context2");
-
- context1.set(SELECTION, new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- return "func1";
- }
- });
-
- InjectTarget target = new InjectTarget();
- ContextInjectionFactory.inject(target, context2);
-
- assertEquals("func1", target.input);
-
- context1.set(SELECTION, new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- return "func2";
- }
- });
-
- assertEquals("func2", target.input);
- }
-
- /**
- * Overriding context function with a regular value on a child node
- */
- @Test
- public void testOverrideICF() {
- IEclipseContext context1 = EclipseContextFactory.create("context1");
- IEclipseContext context2 = context1.createChild("context2");
- IEclipseContext context3 = context2.createChild("context3");
-
- context1.set(SELECTION, new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- return "func1";
- }
- });
-
- InjectTarget target = new InjectTarget();
- ContextInjectionFactory.inject(target, context3);
-
- assertEquals("func1", target.input);
-
- Object o = new Object();
- context2.set(SELECTION, o);
-
- assertEquals(o, target.input);
- }
-
- /**
- * Tests updates in a chain of 4 contexts
- */
- @Test
- public void testLongChain() {
- IEclipseContext context1 = EclipseContextFactory.create("context1");
- IEclipseContext context2 = context1.createChild("context2");
- IEclipseContext context3 = context2.createChild("context3");
- IEclipseContext context4 = context3.createChild("context4");
-
- // ICF set on top context
- context1.set(SELECTION, new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- return "func1";
- }
- });
-
- InjectTarget target = new InjectTarget();
- ContextInjectionFactory.inject(target, context4);
-
- assertEquals("func1", target.input);
-
- // Override ICF set on the 2nd context
- context2.set(SELECTION, new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- return "func2";
- }
- });
-
- assertEquals("func2", target.input);
-
- // Override removed
- context2.remove(SELECTION);
- assertEquals("func1", target.input);
-
- // Override simple value set on 3rd context
- context3.set(SELECTION, "abc");
- assertEquals("abc", target.input);
-
- // Simple value override removed from 3rd context
- context3.remove(SELECTION);
- assertEquals("func1", target.input);
- }
-
-
-
- @Test
- public void testBug315109() throws Exception {
- IEclipseContext appContext = EclipseContextFactory.create();
- IEclipseContext windowContext = appContext.createChild();
- IEclipseContext partContext = windowContext.createChild();
-
- partContext.activateBranch();
-
- appContext.set(SELECTION, new ContextFunction() {
- @Override
- public Object compute(IEclipseContext context, String contextKey) {
- IEclipseContext parent = context.getParent();
- while (parent != null) {
- context = parent;
- parent = context.getParent();
- }
- return context.getActiveLeaf().get("out.selection");
- }
- });
-
- InjectTarget target = new InjectTarget();
- ContextInjectionFactory.inject(target, partContext);
-
- assertNull(target.input, "No selection has been set, should be null"); //$NON-NLS-1$
-
- Object o = new Object();
- windowContext.set(SELECTION, o);
-
- assertEquals(
- o, target.input,
- "A selection was set into the window, should have been injected into the part"); //$NON-NLS-1$
- }
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionDisposeTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionDisposeTest.java
deleted file mode 100644
index 23712a9c275..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionDisposeTest.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- *******************************************************************************/
-package org.eclipse.e4.core.internal.tests.contexts.inject;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.di.annotations.Optional;
-import org.junit.jupiter.api.Test;
-
-/**
- * Tests for injection handling of context dispose, and handling disposal of
- * injected objects.
- */
-public class ContextInjectionDisposeTest {
-
- @Test
- public void testContextDisposedNoArg() {
- class Injected {
-
- boolean disposeInvoked = false;
-
- @SuppressWarnings("unused")
- @Inject
- private String Field;
-
- @PreDestroy
- public void dispose() {
- disposeInvoked = true;
- }
- }
-
- IEclipseContext context = EclipseContextFactory.create();
- context.set(String.class, "hello");
- Injected object = new Injected();
- ContextInjectionFactory.inject(object, context);
- context.dispose();
- assertTrue(object.disposeInvoked);
- }
-
- @Test
- public void testDisposeContext() {
- class Injected {
- boolean disposeInvoked = false;
-
- @Inject
- Object Field;
- String methodValue;
-
- @PreDestroy
- public void dispose() {
- disposeInvoked = true;
- }
-
- @Inject
- public void InjectedMethod(String arg) {
- methodValue = arg;
- }
- }
- IEclipseContext context = EclipseContextFactory.create();
- Object fieldValue = new Object();
- Object methodValue = "abc";
- context.set(Object.class, fieldValue);
- context.set(String.class.getName(), methodValue);
- Injected object = new Injected();
- ContextInjectionFactory.inject(object, context);
-
- assertEquals(fieldValue, object.Field);
- assertEquals(methodValue, object.methodValue);
-
- // disposing context calls @PreDestory, but does not clear injected
- // values
- context.dispose();
- assertNotNull(object.Field);
- assertNotNull(object.methodValue);
- assertTrue(object.disposeInvoked);
- }
-
- @Test
- public void testReleaseObject() {
- class Injected {
- boolean disposeInvoked = false;
-
- @Inject
- Integer Field;
- Object methodValue;
-
- @PreDestroy
- public void dispose() {
- disposeInvoked = true;
- }
-
- @Inject
- public void InjectedMethod(@Optional String arg) {
- methodValue = arg;
- }
- }
- IEclipseContext context = EclipseContextFactory.create();
- Integer fieldValue = Integer.valueOf(123);
- String methodValue = "abc";
- context.set(Integer.class, fieldValue);
- context.set(String.class, methodValue);
- Injected object = new Injected();
- ContextInjectionFactory.inject(object, context);
-
- assertEquals(fieldValue, object.Field);
- assertEquals(methodValue, object.methodValue);
-
- // releasing should have the same effect on the single object as
- // disposing the context does.
- ContextInjectionFactory.uninject(object, context);
-
- assertEquals(fieldValue, object.Field);
- assertNull(object.methodValue);
- assertTrue(object.disposeInvoked);
- }
-
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionFactoryTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionFactoryTest.java
deleted file mode 100644
index b84c78039ba..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionFactoryTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- ******************************************************************************/
-
-package org.eclipse.e4.core.internal.tests.contexts.inject;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-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.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-public class ContextInjectionFactoryTest {
-
- static class TestObject {
-
- private int executed = 0;
-
- private int executedWithParams = 0;
-
- @Execute
- public void execute() {
- executed++;
- }
-
- @CanExecute
- public void executeWithParams(String string) {
- executedWithParams++;
- }
-
- public int getExecuted() {
- return executed;
- }
-
- public int getExecutedWithParams() {
- return executedWithParams;
- }
-
- }
-
- static class TestConstructorObjectBasic {
- public boolean defaultConstructorCalled = false;
-
- public TestConstructorObjectBasic() {
- defaultConstructorCalled = true;
- }
- }
-
- private TestObject testObject;
- private IEclipseContext context;
-
- @BeforeEach
- public void setUp() throws Exception {
- testObject = new TestObject();
- context = EclipseContextFactory.create();
- }
-
- @Test
- public void testInvoke() throws Exception {
- ContextInjectionFactory.invoke(testObject, Execute.class, context, null);
-
- assertEquals(1, testObject.getExecuted());
- assertEquals(0, testObject.getExecutedWithParams());
- }
-
- @Test
- public void testInvokeWithParameters() throws Exception {
- context.set(String.class.getName(), "");
-
- ContextInjectionFactory.invoke(testObject, CanExecute.class, context, null);
-
- assertEquals(0, testObject.getExecuted());
- assertEquals(1, testObject.getExecutedWithParams());
- }
-
- /**
- * If no other constructors are available, the default constructor should be used
- */
- @Test
- public void testConstructorInjectionBasic() {
- IEclipseContext context = EclipseContextFactory.create();
- // add an extra argument for the inner class constructors
- context.set(ContextInjectionFactoryTest.class.getName(), this);
-
- Object basicResult = ContextInjectionFactory
- .make(TestConstructorObjectBasic.class, context);
- assertNotNull(basicResult);
- assertTrue(basicResult instanceof TestConstructorObjectBasic);
- assertTrue(((TestConstructorObjectBasic) basicResult).defaultConstructorCalled);
- }
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionTest.java
deleted file mode 100644
index cbf0c1e0cfc..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionTest.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- *******************************************************************************/
-package org.eclipse.e4.core.internal.tests.contexts.inject;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.contexts.RunAndTrack;
-import org.junit.jupiter.api.Test;
-
-/**
- * Tests for the basic context injection functionality
- */
-public class ContextInjectionTest {
-
-
- /**
- * Test trivial method injection and finalize method with context as an argument
- */
- @Test
- public void testContextSetOneArg() {
- class TestData {
- }
- class Injected {
- int contextSetCalled = 0;
- int setMethodCalled = 0;
-
- public TestData value;
-
- @Inject
- public void contextSet(IEclipseContext context) {
- contextSetCalled++;
- }
-
- @Inject
- public void InjectedMethod(TestData arg) {
- setMethodCalled++;
- value = arg;
- }
- }
- IEclipseContext context = EclipseContextFactory.create();
- TestData methodValue = new TestData();
- context.set(TestData.class.getName(), methodValue);
- Injected object = new Injected();
- ContextInjectionFactory.inject(object, context);
- assertEquals(1, object.setMethodCalled);
- assertEquals(1, object.contextSetCalled);
-
- TestData methodValue2 = new TestData();
- context.set(TestData.class.getName(), methodValue2);
- assertEquals(2, object.setMethodCalled);
- assertEquals(methodValue2, object.value);
- assertEquals(1, object.contextSetCalled);
- }
-
- /**
- * Test filnalize method - no args
- */
- @Test
- public void testContextSetZeroArgs() {
- class TestData {
- }
- class Injected {
- int contextSetCalled = 0;
- int setMethodCalled = 0;
-
- public TestData value;
-
- @Inject
- public void contextSet() {
- contextSetCalled++;
- }
-
- @Inject
- public void InjectedMethod(TestData arg) {
- setMethodCalled++;
- value = arg;
- }
- }
- IEclipseContext context = EclipseContextFactory.create();
- TestData methodValue = new TestData();
- context.set(TestData.class.getName(), methodValue);
- Injected object = new Injected();
- ContextInjectionFactory.inject(object, context);
- assertEquals(1, object.setMethodCalled);
- assertEquals(1, object.contextSetCalled);
-
- TestData methodValue2 = new TestData();
- context.set(TestData.class.getName(), methodValue2);
- assertEquals(2, object.setMethodCalled);
- assertEquals(methodValue2, object.value);
- assertEquals(1, object.contextSetCalled);
- }
-
- /**
- * Tests basic context injection
- */
- @Test
- public synchronized void testInjection() {
- Integer testInt = Integer.valueOf(123);
- String testString = "abc";
- Double testDouble = Double.valueOf(1.23);
- Float testFloat = Float.valueOf(12.3f);
- Character testChar = Character.valueOf('v');
-
- // create context
- IEclipseContext context = EclipseContextFactory.create();
- context.set(Integer.class, testInt);
- context.set(String.class, testString);
- context.set(Double.class, testDouble);
- context.set(Float.class, testFloat);
- context.set(Character.class, testChar);
-
- ObjectBasic userObject = new ObjectBasic();
- ContextInjectionFactory.inject(userObject, context);
-
- // check field injection
- assertEquals(testString, userObject.injectedString);
- assertEquals(testInt, userObject.getInt());
- // assertEquals(context, userObject.context);
-
- // check method injection
- assertEquals(1, userObject.setMethodCalled);
- assertEquals(1, userObject.setMethodCalled2);
- assertEquals(testDouble, userObject.d);
- assertEquals(testFloat, userObject.f);
- assertEquals(testChar, userObject.c);
-
- // check post processing
- assertTrue(userObject.finalized);
- }
-
- /**
- * Tests injection of objects from parent context
- */
- @Test
- public synchronized void testInjectionFromParent() {
- Integer testInt = Integer.valueOf(123);
- String testString = "abc";
- Double testDouble = Double.valueOf(1.23);
- Float testFloat = Float.valueOf(12.3f);
- Character testChar = Character.valueOf('v');
-
- // create parent context
- IEclipseContext parentContext = EclipseContextFactory.create();
- parentContext.set(Integer.class.getName(), testInt);
- parentContext.set(String.class.getName(), testString);
-
- // create child context
- IEclipseContext context = parentContext.createChild();
- context.set(Double.class.getName(), testDouble);
- context.set(Float.class.getName(), testFloat);
- context.set(Character.class.getName(), testChar);
-
- ObjectBasic userObject = new ObjectBasic();
- ContextInjectionFactory.inject(userObject, context);
-
- // check field injection
- assertEquals(testString, userObject.injectedString);
- assertEquals(testInt, userObject.getInt());
- // assertEquals(context, userObject.context);
-
- // check method injection
- assertEquals(1, userObject.setMethodCalled);
- assertEquals(1, userObject.setMethodCalled2);
- assertEquals(testDouble, userObject.d);
- assertEquals(testFloat, userObject.f);
- assertEquals(testChar, userObject.c);
-
- // check post processing
- assertTrue(userObject.finalized);
- }
-
- /**
- * Tests injection into classes with inheritance
- */
- @Test
- public synchronized void testInjectionAndInheritance() {
- Integer testInt = Integer.valueOf(123);
- String testString = "abc";
- Float testFloat = Float.valueOf(12.3f);
-
- // create context
- IEclipseContext context = EclipseContextFactory.create();
- context.set(Integer.class.getName(), testInt);
- context.set(String.class.getName(), testString);
- context.set(Float.class.getName(), testFloat);
-
- ObjectSubClass userObject = new ObjectSubClass();
- ContextInjectionFactory.inject(userObject, context);
-
- // check inherited portion
- assertEquals(testString, userObject.getString());
- // assertEquals(context, userObject.getContext());
- assertEquals(testString, userObject.getStringViaMethod());
- assertEquals(1, userObject.setStringCalled);
-
- // check declared portion
- assertEquals(testInt, userObject.getInteger());
- assertEquals(testFloat, userObject.getObjectViaMethod());
- assertEquals(1, userObject.setObjectCalled);
-
- // make sure overridden injected method was called only once
- assertEquals(1, userObject.setOverriddenCalled);
-
- // check post processing
- assertEquals(1, userObject.getFinalizedCalled());
- }
-
- static public class BaseOverrideTest {
- public String selectionString;
- public String inputString;
- public boolean finishCalled = false;
-
- @Inject
- public void setSelection(String selectionString) {
- this.selectionString = selectionString;
- }
-
- @Inject
- public void setInput(String inputString) {
- this.inputString = inputString;
- }
-
- @PostConstruct
- public void finish() {
- finishCalled = true;
- }
- }
-
- static public class OverrideTest extends BaseOverrideTest {
- public Integer selectionNum;
- public String inputStringSubclass;
- public Double inputDouble;
- public Boolean arg;
- public boolean finishOverrideCalled = false;
-
- @Inject
- public void setSelection(Integer selectionNum) {
- this.selectionNum = selectionNum;
- }
-
- @Inject
- public void setInput(String inputString, Double inputDouble) {
- this.inputStringSubclass = inputString;
- this.inputDouble = inputDouble;
-
- }
-
- @PostConstruct
- public void finish(Boolean arg) {
- finishOverrideCalled = true;
- this.arg = arg;
- }
- }
-
- /**
- * Tests injection of similar, but not overridden methods
- */
- @Test
- public synchronized void testInjectionCloseOverride() {
- Integer testInt = Integer.valueOf(123);
- String testString = "abc";
- Double testDouble = Double.valueOf(12.3);
- Boolean testBoolean = Boolean.TRUE;
-
- // create context
- IEclipseContext context = EclipseContextFactory.create();
- context.set(Integer.class, testInt);
- context.set(String.class, testString);
- context.set(Double.class, testDouble);
- context.set(Boolean.class, testBoolean);
-
- OverrideTest userObject = new OverrideTest();
- ContextInjectionFactory.inject(userObject, context);
-
- // check inherited portion
- assertEquals(testString, userObject.selectionString);
- assertEquals(testString, userObject.inputString);
- assertTrue(userObject.finishCalled);
-
- // check similar methods portion
- assertEquals(testInt, userObject.selectionNum);
- assertEquals(testString, userObject.inputStringSubclass);
- assertEquals(testDouble, userObject.inputDouble);
- assertTrue(userObject.finishOverrideCalled);
- }
-
- @Test
- public void testBug374421() {
- try {
- IEclipseContext context = EclipseContextFactory.create();
- context.runAndTrack(new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- IEclipseContext staticContext = EclipseContextFactory.create();
- ContextInjectionFactory.make(Object.class, context, staticContext);
- return true;
- }
- });
- } catch (StackOverflowError e) {
- fail("See bug 374421 for details.");
- }
- }
-
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/DisposingReferencedContextTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/DisposingReferencedContextTest.java
deleted file mode 100644
index 40996f54077..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/DisposingReferencedContextTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- ******************************************************************************/
-package org.eclipse.e4.core.internal.tests.contexts.inject;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.di.annotations.Optional;
-import org.eclipse.e4.core.internal.contexts.EclipseContext;
-import org.junit.jupiter.api.Test;
-
-@SuppressWarnings("restriction")
-public class DisposingReferencedContextTest {
-
- static class MandatoryTarget {
- @Inject @Named("object")
- Object object;
-
- @Inject
- void setActiveContext(@Named(EclipseContext.ACTIVE_CHILD) IEclipseContext partContext) {
- if (partContext != null) {
- partContext.get("someVar");
- }
- }
- }
-
- static class OptionalTarget {
- @Inject @Named("object")
- Object object;
-
- @Inject
- void setActiveContext(@Optional @Named(EclipseContext.ACTIVE_CHILD) IEclipseContext partContext) {
- if (partContext != null) {
- partContext.get("someVar");
- }
- }
- }
-
- @Test
- public void testContextDisposeCausesCompleteUninjection_Mandatory_True() {
- testContextDisposeCausesCompleteUninjection_Mandatory(true);
- }
-
- @Test
- public void testContextDisposeCausesCompleteUninjection_Mandatory_False() {
- testContextDisposeCausesCompleteUninjection_Mandatory(false);
- }
-
- @Test
- public void testContextDisposeCausesCompleteUninjection_Optional_True() {
- testContextDisposeCausesCompleteUninjection_Optional(true);
- }
-
- @Test
- public void testContextDisposeCausesCompleteUninjection_Optional_False() {
- testContextDisposeCausesCompleteUninjection_Optional(false);
- }
-
- private void testContextDisposeCausesCompleteUninjection_Mandatory(boolean disposeFirst) {
- IEclipseContext windowContext = EclipseContextFactory.create("windowContext");
- IEclipseContext partContext = windowContext.createChild("partContext");
-
- partContext.activate();
-
- Object o = new Object();
- windowContext.set("object", o);
-
- MandatoryTarget target = new MandatoryTarget();
- ContextInjectionFactory.inject(target, windowContext);
- assertEquals(o, target.object, "The object should have been injected");
-
- partContext.dispose();
-
- assertEquals(o, target.object, "The object should not have been uninjected");
- }
-
- private void testContextDisposeCausesCompleteUninjection_Optional(boolean disposeFirst) {
- IEclipseContext windowContext = EclipseContextFactory.create();
- IEclipseContext partContext = windowContext.createChild();
-
- partContext.activate();
-
- Object o = new Object();
- windowContext.set("object", o);
-
- OptionalTarget target = new OptionalTarget();
- ContextInjectionFactory.inject(target, windowContext);
- assertEquals(o, target.object, "The object should have been injected");
-
- partContext.dispose();
-
- assertEquals(o, target.object, "The object should not have been uninjected");
- }
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ExtraDependenciesTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ExtraDependenciesTest.java
deleted file mode 100644
index 015a2ce5a20..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ExtraDependenciesTest.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- *******************************************************************************/
-package org.eclipse.e4.core.internal.tests.contexts.inject;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.lang.reflect.InvocationTargetException;
-
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.junit.jupiter.api.Test;
-
-public class ExtraDependenciesTest {
-
- static public class TestObject {
-
- public String string;
- public Integer integer;
- public String other;
-
- public boolean disposed = false;
-
- @Inject
- public void injectedMethod(@Named("arg1") String strValue, @Named("arg2") Integer intValue, IEclipseContext context) {
- string = strValue;
- integer = intValue;
- if (context == null) {
- other = null;
- return;
- }
- IEclipseContext otherContext = (IEclipseContext) context.get("otherContext");
- if (otherContext == null) {
- other = null;
- } else {
- other = (String) otherContext.get("arg3");
- }
- }
-
- @PreDestroy
- public void finita() {
- disposed = true;
- }
- }
-
- @Test
- public void testExtraDependencies() throws InvocationTargetException, InstantiationException {
- IEclipseContext context = EclipseContextFactory.create();
- context.set("arg1", "abc");
- context.set("arg2", Integer.valueOf (123));
-
- IEclipseContext otherContext = EclipseContextFactory.create();
- otherContext.set("arg3", "other");
-
- context.set("otherContext", otherContext);
-
- TestObject object = ContextInjectionFactory.make(TestObject.class, context);
-
- // check that initial values are properly injected
- assertEquals("abc", object.string);
- assertEquals(Integer.valueOf(123), object.integer);
- assertEquals("other", object.other);
-
- // modify argument value to cause update - bug 308650
- context.set("arg2", Integer.valueOf (789));
-
- // change the "other" value; should not be propagated
- otherContext.set("arg3", "wrong");
- assertEquals("other", object.other);
-
- // dispose the other context; should not cause disposal of the test object
- otherContext.dispose();
- assertEquals("other", object.other);
- assertFalse(object.disposed);
-
- // remove "other" context, should not be propagated
- context.remove("otherContext");
- assertEquals("other", object.other);
-
- // check that changes in the method arguments are propagated
- context.set("arg1", "xyz");
- context.set("arg2", Integer.valueOf (456));
- assertEquals("xyz", object.string);
- assertEquals(Integer.valueOf(456), object.integer);
- assertNull(object.other);
-
- // check that disposal of the injected context causes disposal of the injected object
- context.dispose();
- assertTrue(object.disposed);
- assertNotNull(object.string);
- assertNotNull(object.integer);
- assertNull(object.other);
- }
-
-}
diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsInjectionTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsInjectionTest.java
deleted file mode 100644
index 648608d92d9..00000000000
--- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsInjectionTest.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2015 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- * Lars Vogel - Bug 474274
- *******************************************************************************/
-package org.eclipse.e4.core.internal.tests.contexts.inject;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
-import org.eclipse.e4.core.contexts.EclipseContextFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.junit.jupiter.api.Test;
-
-/**
- * Tests for the generics context injection functionality
- */
-public class GenericsInjectionTest {
-
- static public class Animal {
- }
-
- static public class Bird extends Animal {
- }
-
- static public class Feeder {
- }
-
- static public class BirdHouse extends Feeder {
- }
-
- static public class TestNamedObject {
- public Feeder field;
-
- @Inject
- public void setFeeder(@Named("test") Feeder value) {
- field = value;
- }
- }
-
- static public class TestGenericObject {
- public Feeder field;
-
- @Inject
- public void setFeeder(Feeder value) {
- field = value;
- }
- }
-
- @Test
- public synchronized void testNamedInjection() {
- Animal testAnimal = new Animal();
- Bird testBird = new Bird();
- BirdHouse testBirdHouse = new BirdHouse();
-
- // create context
- IEclipseContext context = EclipseContextFactory.create();
- context.set(Animal.class, testAnimal);
- context.set(Bird.class, testBird);
- context.set("test", testBirdHouse);
-
- TestNamedObject userObject = new TestNamedObject();
- ContextInjectionFactory.inject(userObject, context);
-
- // check field injection
- assertEquals(testBirdHouse, userObject.field);
- }
-
- @Test
- public synchronized void testGenericInjection() {
- Animal testAnimal = new Animal();
- Bird testBird = new Bird();
- BirdHouse testBirdHouse = new BirdHouse();
-
- // create context
- IEclipseContext context = EclipseContextFactory.create();
- context.set(Animal.class, testAnimal);
- context.set(Bird.class, testBird);
- context.set(Feeder.class, testBirdHouse); // note that BirdHouse is
- // added as Feeder class
-
- TestGenericObject userObject = new TestGenericObject();
- ContextInjectionFactory.inject(userObject, context);
-
- // check field injection
- assertEquals(testBirdHouse, userObject.field);
- }
-
- static public interface Interface {
- }
-
- static public class Implementation implements Interface