How to mock a String using mockito?

后端 未结 15 1748
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-05 00:22

I need to simulate a test scenario in which I call the getBytes() method of a String object and I get an UnsupportedEncodingException.

I have tried to achie

15条回答
  •  失恋的感觉
    2021-02-05 01:11

    Mockito can't mock final classes. JMock, combined with a library from JDave can. Here are instructions.

    JMock doesn't do anything special for final classes other than rely on the JDave library to unfinalize everything in the JVM, so you could experiment with using JDave's unfinalizer and see if Mockito will then mock it.

提交回复
热议问题