Scala / PowerMockito - Java final classes causing build error in Scala Tests using Powermockito

时间秒杀一切 提交于 2019-12-10 17:32:19

问题


I have a final class:

public final class AClass {
    private final AConfig aClassConfig;
    public final static BeanName = "aClass"
}

and I'm trying to mock it in tests:

@RunWith(classOf[PowerMockRunner])
@PrepareForTest(Array(classOf[AClass]))
class AClassTests extends FunSuite {
    test("mock final class test") {
        val aClass = PowerMockito.mock(classOf[AClass])
        assert(aClass != null)
    }
}

This causes the error:

Cannot subclass final class class com.me.AClass
java.lang.IllegalArgumentException: Cannot subclass final class class com.me.AClass

I've followed multiple tutorials on how these tests should be set up and as far as I can tell the error is due to @PrepareForTest(...) not running properly, but that's just a guess.

来源:https://stackoverflow.com/questions/34515740/scala-powermockito-java-final-classes-causing-build-error-in-scala-tests-usi

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