如何防止Guice在测试中配置此模块?
class SnsModule extends AbstractModule {
override def configure(): Unit = {
val snsClient: AmazonSNSAsyncClient = AmazonSNSAsyncClientBuilder.standard().build().asInstanceOf[AmazonSNSAsyncClient]
bind(classOf[AmazonSNSAsyncClient]).toInstance(snsClient)
}
}
我尝试覆盖该模块:
private val snsModule = new AbstractModule{
override def configure(): Unit = {
val snsClient: AmazonSNSAsyncClient = mock[AmazonSNSAsyncClient]
bind(classOf[AmazonSNSAsyncClient]).toInstance(snsClient)
}
}
override implicit lazy val app: Application = GuiceApplicationBuilder().overrides(new TestJwkModule(), snsModule).build()
但是仍然调用configure()
中的SnsModule
,这是一个问题,因为在我的测试环境中,AmazonSNSAsyncClientBuilder
引发了异常。
答案 0 :(得分:1)
disable
阻止加载模块,例如:
override implicit lazy val app: Application = GuiceApplicationBuilder().
disable(classOf[SnsModule])
overrides(snsModule).build()