I am trying to override an existing binding with a Mock instance so I can 
verify method calls.  The TaskManager class in question is annotated with 
@Inject @Singleton.  The Injector is being created in a static @BeforeClass 
method in JUnit5.  The mock is created in a static field, initialized at 
the declaration.

My first try added the following to an OverrideModule:
new AbstractModule() {
  @Override
  protected void configure() {
   bind(TaskManager.class).toInstance(mockTaskManager);
  } 
}

I think this didn't work because of the JIT binding.  So I added a binding 
to the real module.
bind(TaskManager.class).in(Singleton.class);

Still didn't work, so I tried a different override binding, trying to match 
the scope
new AbstractModule() {
  @Override
  protected void configure() {
    bind(TaskManager.class)
        .toProvider(Providers.of(taskManager))
        .in(Singleton.class);
  }
}

I still get the real implementation of TaskManager from the Injector.

Is there any way to do what I need to do?

Thank you,

Jim McMaster

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/1441a34b-ed4b-477f-a0a1-5d3a95c77748n%40googlegroups.com.

Reply via email to