Hi Bill,

I am sorry you stumbled in a Guice/Onami-Logger limitation:
Onami-Logger indeed injects the logger instance AFTER the injectee is
created by the Guice framework, via a MembersInjector<I>
implementation, that is why you cannot use the logged inside the
constructor - it has not been injected yet :(

HTH, all the best,
-Simo

http://people.apache.org/~simonetripodi/
http://twitter.com/simonetripodi


On Sat, Jun 15, 2013 at 10:55 PM, William Speirs <[email protected]> wrote:
> I'm trying to use Slf4jLoggingModule in a unit test with an
> AssistedInject. Here is my basic setup:
>
>
> public class BaseClass {
>     private @InjectLogger Logger LOG;
>
>     public BaseClass() {
>         LOG.debug("Calling constructor"); // dies with NPE
>     }
>
> public class ClassA extends BaseClass {
>     private @InjectLogger Logger LOG;
>
>     @Inject
>     public ClassA(@Assisted Bean bean) {
>         super();
>     }
>
>     public interface ClassAFactory {
>         public ClassA create(Bean bean);
>     }
> }
>
> @RunWith( OnamiRunner.class )
> @MockFramework( MockType.MOCKITO )
> public class ClassATest extends AbstractModule {
>
>     @Inject ClassAFactory factory;
>
>     @GuiceProvidedModules
>     public static Module createComplexModule() {
>         return new Slf4jLoggingModule();
>     }
>
>     @Override
>     public void configure() {
>         install(new FactoryModuleBuilder()
>         .implement(ClassA.class, ClassA.class)
>         .build(ClassAFactory.class));
>     }
>
>     @Test
>     public void test() throws Exception {
>         ClassA a = factory.create(bean);
>     }
> }
>
>
> What am I doing wrong? This is my first time using Onami and so I'm
> sure I'm missing something obvious/stupid.
>
> Thanks...
>
> Bill-

Reply via email to