TestAllModelBootstrap
did not come from an Injector—JUnit created it instead—so Guice hasn't had a chance to inject it yet. Guice can only inject into objects that it creates via getInstance
(and those objects' dependencies, recursively), or objects passed into injectMembers
, or existing instances as requested using requestInjection
.
You can manually get a factory instance:
factory = injector.getInstance(DAOFactory.class);
Or ask Guice to inject your members using injectMembers
:
injector.injectMembers(this); // sets the @Inject factory field
Or use a tool like Guiceberry to inject your test cases across your app.