Mocking Java InputStream

前端 未结 10 1696
既然无缘
既然无缘 2020-11-29 04:40

Please provide pointers to help me mock that java InputStream object. This is the line of code that I would wish to Mock:

InputStreamReader inputData = new I         


        
10条回答
  •  醉酒成梦
    2020-11-29 04:51

    I disagree with the selected answer for this question. Mocking frameworks like Mockito are nice and all, however when standard java api is available you might consider using that instead.

    i.e.

    BufferedReader reader = new BufferedReader(new StringReader("some string"));
    

    Why use a Mock object in your test classes when you could use a real one with all its state and behaviour?

    To see more about how this works, you could look up the 'decorator' design pattern.

提交回复
热议问题