use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class GenericsInjectionTest method testNamedInjection.
@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);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class GroupedUpdatesTest method testGrouping.
@Test
public void testGrouping() {
final IEclipseContext context = EclipseContextFactory.create();
context.set("string1", "x");
context.set("string2", "y");
InjectTarget target = new InjectTargetWait();
ContextInjectionFactory.inject(target, context);
assertEquals(1, target.countMain);
target.resetCounters();
context.set("string1", "a");
context.set("string2", "b");
assertEquals(0, target.countMain);
assertEquals(0, target.countSecondary);
context.processWaiting();
assertEquals(1, target.countMain);
assertEquals(1, target.countSecondary);
// do it again to make sure we properly cleared waiting updates
context.processWaiting();
assertEquals(1, target.countMain);
assertEquals(1, target.countSecondary);
// now with 3 updates
target.resetCounters();
context.set("string1", "x");
context.set("string2", "y");
context.set("string2", "z");
context.set("string1", "delta");
assertEquals(0, target.countMain);
assertEquals(0, target.countSecondary);
context.processWaiting();
assertEquals(1, target.countMain);
assertEquals(1, target.countSecondary);
assertEquals(target.s1, "delta");
assertEquals(target.s2, "z");
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class GroupedUpdatesTest method testNoGrouping.
@Test
public void testNoGrouping() {
IEclipseContext context = EclipseContextFactory.create();
context.set("string1", "x");
context.set("string2", "y");
InjectTarget target = new InjectTargetImmediate();
ContextInjectionFactory.inject(target, context);
assertEquals(1, target.countMain);
target.resetCounters();
// I want these two sets to be one transaction
context.set("string1", "a");
context.set("string2", "b");
assertEquals(2, target.countMain);
assertEquals(1, target.countSecondary);
context.processWaiting();
assertEquals(2, target.countMain);
assertEquals(1, target.countSecondary);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class InjectionOrderTest method testDisposeMethod.
/**
* Tests to ensure that the injection/uninjection order of fields is correct.
* <p>
* See bug 304859.
* </p>
*/
@Test
public void testDisposeMethod() throws Exception {
// create a context
IEclipseContext appContext = EclipseContextFactory.create();
// set a value
appContext.set("inject", "a");
// instantiate the object
InjectTargetMethod injectTargetMethod = ContextInjectionFactory.make(InjectTargetMethod.class, appContext);
// change the requested value so another injection occurs
appContext.set("inject", "b");
// now we dispose the context
appContext.dispose();
// check that the second 'set' invocation did not alter the order of notifications
assertTrue("@PreDestroy was incorrectly called after the method was uninjected", injectTargetMethod.nonNull);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class InjectionOrderTest method testDisposeField.
/**
* Tests to ensure that the injection/uninjection order of methods is correct.
* <p>
* See bug 304859.
* </p>
*/
@Test
public void testDisposeField() throws Exception {
// create a context
IEclipseContext appContext = EclipseContextFactory.create();
// set a value
appContext.set("inject", "a");
// instantiate the object
InjectTargetField injectTargetField = ContextInjectionFactory.make(InjectTargetField.class, appContext);
// change the requested value so another injection occurs
appContext.set("inject", "b");
// now we dispose the context
appContext.dispose();
assertTrue("@PreDestroy was incorrectly called after the field was uninjected", injectTargetField.nonNull);
}
Aggregations