I have a constructor which unfortunately must do something non-trivial:
public MyModule() {
this.setInjector(Guice.createInjector(new AfterInjectionModule(
PostConstruct.class, Matchers.any()), new MyGuiceModule()));
}
I now need to verify that the AfterInjectionModule was called in the scheme of things with the PostConstruct.class parameter. I couldn’t care less about the other parameters for now. Unfortunately, I can’t think of how I would verify() this in Mockito. I’m currently trying the following:
this.reference = mock(new MyModule());
verify(this.reference).setInjector(Guice.createInjector(
new AfterInjectionModule(PostConstruct.class, Matchers.any()),
new MyGuiceModule()));
My unit test fails at the above line. How can I verify that this method was set to an Injector which was passed AfterInjectionModule with PostConstruct.class as its first parameter?
I would think the problem is not the mocking of the constructor, but rather the static call to Guice.createInjector(). Since you cannot mock a static method with Mockito, you can either try to verify the result from the behaviour (could be difficult) or use another tool like Powermock to override the static method.