How to mock a String using mockito?

后端 未结 15 1747
佛祖请我去吃肉
佛祖请我去吃肉 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:16

    How about just creating a String with a bad encoding name? See

    public String(byte bytes[], int offset, int length, String charsetName)
    

    Mocking String is almost certainly a bad idea.

提交回复
热议问题