任何想法如何从ScalaTest我可以模拟静态Java类?
我有这段代码
val mockMapperComponent: IMapperComponent = mock[IMapperComponent]
val applicationContext: ApplicationContext = mock[ApplicationContext]
val appContextUtil: AppContextUtil = mock[AppContextUtil]
override def beforeAll(): Unit = {
mockStatic(classOf[AppContextUtil])
when(AppContextUtil.getApplicationContext).thenReturn(applicationContext)
when(applicationContext.getBean(classOf[IMapperComponent])).thenReturn(mockMapperComponent)
}
在Java mockStatic
中,类@PrepareForTest({AppContextUtil.class})
中的注释可以解决问题,但是从Scala我只能在scalaTest文档中找到如何模拟正常访问,而不是静态访问。
问候。