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.