stackoverflowmailer / atunit

Automatically exported from code.google.com/p/atunit
Apache License 2.0
0 stars 0 forks source link

Bug on GuiceContainer #15

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When the test class is a module, the test gets created twice: first time for 
the module and second for the test, this doesn't allow us to share instance 
variables between the module and the test, forcing us to us statics.

To fix, on GuiceContainer change the createTest method for:

public Object createTest(Class<?> testClass, Map<Field, Object> fieldValues) 
throws Exception {

    FieldModule fields = new FieldModule(fieldValues);

    Object newInstance = testClass.newInstance();

    Injector injector;
    if (Module.class.isAssignableFrom(testClass)) {
      injector = Guice.createInjector(fields, (Module) newInstance);
    } else {
      injector = Guice.createInjector(fields);
    }
    injector.injectMembers(newInstance);
    return newInstance;
  }

Original issue reported on code.google.com by gal.dol...@gmail.com on 8 Dec 2011 at 7:41