问题
My library uses both Guice and Spring. And I have class where Spring beans are "bind"-ed for the below usage
@ModuleDescriptor(
requires = {
AnotherModule.class,
SpringIntegrationModule.class,
})
public class MyModule extends AbstractModule {
@Override
protected void configure() {
bind(Command.class)
.annotatedWith(Names.named("commandSpringBean"))
.toProvider(
SpringIntegration.fromSpring(Command.class, "commandSpringBean"));
AnotherModule.exportFunctions(this.binder(), MyGuiceInjector.class);
Note that AbstractModule
here is com.google.inject.AbstractModule
commandSpringBean
is a spring bean created in some other config file in another java package of same project. I am finally using the spring bean in MyGuiceInjector.java
as below
@Inject
@Named("commandSpringBean")
private Command commandSpringBean;
I want to finally write a JUnit that tests that the bean is successfully binded. If that is not possible I want to at least test that during bind()
, commandSpringBean
is actually of type Command.class
Is there a way I can test this?
来源:https://stackoverflow.com/questions/58031425/write-junit-for-guice-bindings-of-spring-beans