use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class Bug317183Test method testY.
@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();
// this fails
assertTrue(impl.called);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ContextFunctionDynamicsTest method testChangeICF.
/**
* 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);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ContextInjectionFactoryTest method testConstructorInjectionBasic.
/**
* 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);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class DisposingReferencedContextTest method testContextDisposeCausesCompleteUninjection_Mandatory.
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("The object should have been injected", o, target.object);
partContext.dispose();
assertEquals("The object should not have been uninjected", o, target.object);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class GenericsInjectionTest method testGenericInjection.
@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);
// note that BirdHouse is
context.set(Feeder.class, testBirdHouse);
// added as Feeder class
TestGenericObject userObject = new TestGenericObject();
ContextInjectionFactory.inject(userObject, context);
// check field injection
assertEquals(testBirdHouse, userObject.field);
}
Aggregations