How to mock a String using mockito?

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

    instead of mocking string inject string value at setup method as below

    public void setup() throws IllegalAccessException {
        FieldUtils.writeField(yourTestClass, "stringVariableName", "value", true);
    }
    

提交回复
热议问题