google-code-export / gwt-test-utils

Automatically exported from code.google.com/p/gwt-test-utils
1 stars 0 forks source link

GInjectorCreateHandler does not handle @Provides methods #116

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have a Gin module with an @Provides annotated method like so:

   @Provides @Singleton GraphBuilder provideGraphBuilder(GraphFactory factory)
    {
        return factory.createGraphBuilder();
    }

When I try to instantiate the ginjector in my test, I get an error like:

com.octo.gwt.test.exceptions.GwtTestPatchException: Error while creation 
instance of 'ec.client.EcCoreGinjector' through 
'com.octo.gwt.test.gin.GInjectorCreateHandler' instance
    at com.octo.gwt.test.internal.patchers.GwtPatcher.create(GwtPatcher.java:30)
    at com.google.gwt.core.client.GWT.create(GWT.java)
    at ec.client.CorePlaceManagerTest.setUp(CorePlaceManagerTest.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at com.octo.gwt.test.internal.runner.AbstractGwtRunner.run(AbstractGwtRunner.java:40)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
Caused by: com.google.inject.ConfigurationException: Guice configuration errors:

1) Could not find a suitable constructor in ec.client.graph.GraphFactory. 
Classes must have either one (and only one) constructor annotated with @Inject 
or a zero-argument constructor that is not private.
  at ec.client.graph.GraphFactory.class(GraphFactory.java:1)

1 error
    at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:290)
    at com.octo.gwt.test.gin.DeferredBindingModule$2.visit(DeferredBindingModule.java:143)
    at com.octo.gwt.test.gin.DeferredBindingModule$2.visit(DeferredBindingModule.java:135)
    at com.google.inject.internal.BindingImpl.acceptVisitor(BindingImpl.java:93)
    at com.octo.gwt.test.gin.DeferredBindingModule.collectDependencies(DeferredBindingModule.java:135)
    at com.octo.gwt.test.gin.DeferredBindingModule.<init>(DeferredBindingModule.java:77)
    at com.octo.gwt.test.gin.GInjectorCreateHandler.readGuiceModules(GInjectorCreateHandler.java:107)
    at com.octo.gwt.test.gin.GInjectorCreateHandler.create(GInjectorCreateHandler.java:60)
    at com.octo.gwt.test.internal.patchers.GwtPatcher.create(GwtPatcher.java:22)
    ... 27 more

Original issue reported on code.google.com by snstan...@gmail.com on 13 Feb 2012 at 11:21

GoogleCodeExporter commented 9 years ago
Upon further digging, the problem is narrow than I first thought.  Basic 
@Provides annotations do appear to work.  What's broken seems to be indirect 
bindings like the declaration above where the argument to the provides method 
is also supplied by a provides method:

    @Provides @Singleton GraphFactory provideGraphFactory()
    {
        return GWT.create(GraphFactoryImpl.class);
    }

This also fails for transitive bindings like:

bind(Log.class).to(LoggerLog.class)

where the LoggerLog class is created by a provider method.

Original comment by snstan...@gmail.com on 14 Feb 2012 at 12:06

GoogleCodeExporter commented 9 years ago
which version are you using ? 
I remember fixing a related issue : 
http://code.google.com/p/gwt-test-utils/issues/detail?id=104

The fix is available on the lastest snapshots. Could you please give one of 
them a try if not already done ?

Original comment by gael.laz...@gmail.com on 14 Feb 2012 at 10:02

GoogleCodeExporter commented 9 years ago
I'm using 0.36-SNAPSHOT from the trunk.

Original comment by snstan...@gmail.com on 14 Feb 2012 at 4:37

GoogleCodeExporter commented 9 years ago
I think the related issue was not specifically dealing with the @Provides 
annotation.

Original comment by snstan...@gmail.com on 15 Feb 2012 at 11:49

GoogleCodeExporter commented 9 years ago
Did you need any additional info to reproduce this?

Original comment by snstan...@gmail.com on 21 Feb 2012 at 7:04

GoogleCodeExporter commented 9 years ago
No I think that's fine, I will fix this issue this weekend ;)

Original comment by gael.laz...@gmail.com on 22 Feb 2012 at 5:32

GoogleCodeExporter commented 9 years ago

Original comment by gael.laz...@gmail.com on 12 Jun 2012 at 8:01

GoogleCodeExporter commented 9 years ago
Month later, I finally manage to fix this issue. Modifications are available on 
the lastest 0.39-SNAPSHOT. Could you please give it a try and post some 
feedback here ?

Thank you very much ! I sincerly apologize for having taken so much time to 
solve it..

Original comment by gael.laz...@gmail.com on 12 Jun 2012 at 8:10