I'm testing an (Eclipse 4) application (I'm not talking about unit test but more integration and system-test).
I've a recurrent problem I need to solve. I have to "inject" (@Inject) a context from the test into the class(es) under test. In other words I need the test does what the application usually do.
What I've done is creating a private method:
private IEclipseContext createApplicationContext() {
IEclipseContext tempContext = E4Application.createDefaultContext();
ContextInjectionFactory.make(CommandServiceAddon.class, tempContext);
ContextInjectionFactory.make(ContextServiceAddon.class, tempContext);
eventBroker = (IEventBroker) tempContext.get(IEventBroker.class.getName());
tempContext.set(IEventBroker.class, eventBroker);
return tempContext;
}
I expected (wrongly) that the context just created here would have been made available in one of the classes under test. E.g.:
class MyDBClassToTest {
@Inject
private IEclipseContext context;
@Inject
private IEventBroker broker;
// ... etc
}
for sure there is something missing! I've created the activator too (below the implementation without comment for brevity) ... but didn't help:
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
public class Activator extends AbstractUIPlugin {
// The shared instance
private static Activator plugin;
// The plug-in ID
public static final String PLUGIN_ID = "my.path....";
public static Activator getDefault() {
return plugin;
}
public Activator() {
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
@Override
public void stop(BundleContext context) throws Excepti`enter code here`on {
plugin = null;
super.stop(context);
}
}
any idea, hint or suggestion?