Write JUnit for Guice bindings of Spring beans

蓝咒 提交于 2019-12-12 10:22:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!