use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ContextInjectionTest method testBug374421.
@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.");
}
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ReparentingTest method testContextFunctionParentBecomeNull.
@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());
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ReparentingTest method testRunAndTrackSwitchParent.
@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]);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ReparentingTest method testUpdateSameParentCalculated.
@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]);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ReparentingTest method testInjectSwitchParentSameGrandparent.
/**
* 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);
}
Aggregations