How to mock a final class with mockito

后端 未结 25 1534
日久生厌
日久生厌 2020-11-22 16:35

I have a final class, something like this:

public final class RainOnTrees{

   public void startRain(){

        // some code here
   }
}

I

25条回答
  •  情书的邮戳
    2020-11-22 16:52

    Yes same problem here, we cannot mock a final class with Mockito. To be accurate, Mockito cannot mock/spy following:

    • final classes
    • anonymous classes
    • primitive types

    But using a wrapper class seems to me a big price to pay, so get PowerMockito instead.

提交回复
热议问题