Mock Java static class from scala

Viewed 1879

Any idea how from ScalaTest I can mock a static Java class??

I have this code

  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)

  }

In Java mockStatic with the annotation in the class @PrepareForTest({AppContextUtil.class}) do the trick, but from Scala I can only found in scalaTest documentation how to mock the normal access, but not static.

Regards.

0 Answers
Related