Search in sources :

Example 1 with ObjectSuperClass

use of org.eclipse.e4.core.internal.tests.contexts.inject.ObjectSuperClass 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);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ObjectSuperClass(org.eclipse.e4.core.internal.tests.contexts.inject.ObjectSuperClass) Test(org.junit.Test)

Example 2 with ObjectSuperClass

use of org.eclipse.e4.core.internal.tests.contexts.inject.ObjectSuperClass in project eclipse.platform.runtime by eclipse.

the class ReparentingTest method testInjectSwitchParent.

/**
 * 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);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ObjectSuperClass(org.eclipse.e4.core.internal.tests.contexts.inject.ObjectSuperClass) Test(org.junit.Test)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)2 ObjectSuperClass (org.eclipse.e4.core.internal.tests.contexts.inject.ObjectSuperClass)2 Test (org.junit.Test)2