本文介绍了模拟Java InputStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请提供指针以帮助我模拟该java InputStream对象.这是我希望模拟的代码行:
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 InputStreamReader(System.in);
bufferdReader = new BufferedReader(inputData);
bufferdReader.readLine();
推荐答案
BufferedReader bufferedReader = org.mockito.Mockito.mock(BufferedReader.class);
when(bufferedReader.readLine())
.thenReturn("first line")
.thenReturn("second line");
org.junit.Assert.when(new Client(bufferedReader).parseLine())
.thenEquals(IsEqual.equalTo("first line"));
这篇关于模拟Java InputStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!