Debugging CreationException

Hi,

How do you debug something like this where the only reference is my test class and it does not say which class it failed injection on?


com.google.inject.CreationException: Unable to create injector, see the following errors:

1) Could not find a suitable constructor in com.lightbend.lagom.internal.javadsl.server.ResolvedServices. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
  at com.lightbend.lagom.internal.javadsl.server.ResolvedServices.class(JavadslServerBuilder.scala:100)
  while locating com.lightbend.lagom.internal.javadsl.server.ResolvedServices
    for the 1st parameter of com.lightbend.lagom.internal.testkit.TestTopicFactory.<init>(TestTopicFactory.scala:26)
  at com.lightbend.lagom.javadsl.testkit.ServiceTest$.startServer(ServiceTest.scala:297):
Binding(interface com.lightbend.lagom.internal.javadsl.api.broker.TopicFactory to ConstructionTarget(class com.lightbend.lagom.internal.testkit.TestTopicFactory)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)

1 error

	at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:470)
	at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:155)
	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
	at com.google.inject.Guice.createInjector(Guice.java:99)
	at com.google.inject.Guice.createInjector(Guice.java:84)
	at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:185)
	at play.inject.guice.GuiceBuilder.injector(GuiceBuilder.java:221)
	at play.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.java:156)
	at com.lightbend.lagom.javadsl.testkit.ServiceTest$.startServer(ServiceTest.scala:336)
	at com.lightbend.lagom.javadsl.testkit.ServiceTest.startServer(ServiceTest.scala)
	at com.myproject.impl.UpstreamSubscriberTest.setup(UpstreamSubscriberTest.java:115)
 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:27)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:27)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

My setup code looks like this

    @Before
    @SuppressWarnings("unchecked")
    public void setup() {
      mockPersistentEntityRegistry = mock(PersistentEntityRegistry.class);
      mockEntityRef = mock(PersistentEntityRef.class);
      scheduler = mock(Scheduler.class);

      when(mockPersistentEntityRegistry.refFor(MyEntity.class, "expectedEntityKey"))
          .thenReturn(mockEntityRef);

      Setup setup = defaultSetup()
          .withCassandra(true)
          .configureBuilder(builder ->
              builder.overrides(
                  bind(MyService1.class).to(MyService1Stub.class),
                  bind(MyService2.class).to(MyService2Stub.class),
                  bind(PersistentEntityRegistry.class).toInstance(mockPersistentEntityRegistry),
                  bind(Scheduler.class).toInstance(scheduler)
              ));
      server = startServer(setup);
    }

Thanks,
Franz

@franz stack trace is indicating problem with TopicFactory. If I recall correctly this was related to topic definition in service stub classes.
Can you share code for MyService1Stub and MyService2Stub?

@aklikic hmm… somebody fixed a dependency somewhere and now the test works. I’ll update this thread if I get this again.

Thanks!