I want to mock a scala companion object, so im trying to use PowerMockito. I have the following:
import org.junit.runner.RunWith
import org.mockito.Mockito.when
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
import org.powermock.api.mockito.PowerMockito._
@RunWith(classOf[PowerMockRunner])
@PrepareForTest(Array(classOf[ClassToMock]))
class Test {
describe("test") {
it("test") {
mockStatic(classOf[ClassToMock])
when(ClassToMock.apply()).thenReturn(null)
}
}
When running the test i get the following error:
The class path.to.ClassToMock not prepared for test.
To prepare this class, add class to the '@PrepareForTest' annotation.
In case if you don't use this annotation, add the annotation on class or method level.
org.powermock.api.mockito.ClassNotPreparedException:
Any ideas on how can i manage to make the annotation work?
Thx!!