Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Testing E4 components injection in a simple Java class
Testing E4 components injection in a simple Java class [message #1005432] Fri, 25 January 2013 12:28 Go to next message
Gaetan Pitteloud is currently offline Gaetan PitteloudFriend
Messages: 17
Registered: September 2012
Junior Member
I would like to test specific parts of the UI by writing a Java class with a main method, following an example found in Lars Vogel's book about Eclipse 4. Something similar to this:
public static void main(Object...args) {
  Display display = new Display();
  Shell shell = new Shell(display);
  MyComponentToTest c = new MyComponentToTest();
  c.buildUI(shell, display); // @PostConstruct method
  shell.pack();
  shell.open();

  while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
       display.sleep();
    }
  }
  display.dispose();
}

MyComponentToTest is a Part and uses @Inject and other annotations to signal lifecycle events and receive objects from the EclipseContext during creation. So I transformed the code, following another example found in Lars' book about testing dependency injection :
public static void main(Object...args) {
  Display display = new Display();
  Shell shell = new Shell(display);
  IEclipseContext ctx = EclipseContextFactory.create();
  // populate ctx : add the components required by MyComponentToTest + display & shell
  ContextInjectionFactory.make(MyComponentToTest.class, ctx);
  shell.pack();
  shell.open();

  while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
       display.sleep();
    }
  }
  display.dispose();
}

When running this application, I get a NullPointerException, caused by the fact that EclipseContext declares this variable
static private final IEclipseContextDebugger debugAddOn = ContextDebugHelper.getDebugger();

Its initialization invokes OSGi-related code that obviously doesn't work if not run in a OSGi runtime.

Is there a way to deactivate this OSGi code or change something in the configuration so that I can test my component ?
Thanks in advance for any help.
Re: Testing E4 components injection in a simple Java class [message #1005459 is a reply to message #1005432] Fri, 25 January 2013 14:24 Go to previous message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Have a look at Bug 373131:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=373131

Previous Topic:application model changes via fragment at startup
Next Topic:What's up with the Package Explorer selection in Juno?
Goto Forum:
  


Current Time: Fri Apr 19 13:45:33 GMT 2024

Powered by FUDForum. Page generated in 0.01959 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top