模拟输入流,InputStreamReader和BufferedReader
我有以下代码:
InputStream inputStream = sftpConfig.getSftpChannel().get(fileAbsolutePath);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)))
String line = bufferedReader.readLine();
我想要的是模拟这些行,并在bufferedReader.readline()
中灵活,因为我会根据行(这种情况文件为空,线为空,在这种情况下,我只得到一行,一个我得到多个等等的情况)。
注意:我正在使用jsch
库来访问FTP服务器上的文件,因此方法getsftppchannel()
chance> channelsftp
作为返回类型,而get(fileabsolutepath)
具有inputStream
。
我正在使用Junit 4.12
和Mockito 3.1.0
预先感谢!
I have the following piece of code :
InputStream inputStream = sftpConfig.getSftpChannel().get(fileAbsolutePath);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)))
String line = bufferedReader.readLine();
All I want is to mock these lines, and be flexible in bufferedReader.readLine()
, because I will have several test cases depending on the lines (a case where the file is empty and the line is null, a case where I get only one line, a case where I get several etc.).
Note : I am using jsch
library for accessing files on FTP servers, so the method getSftpChannel()
has ChannelSftp
as return type, and get(fileAbsolutePath)
has InputStream
.
I am using junit 4.12
and mockito 3.1.0
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅实例化bytearrayinputstream实例而不是嘲笑它并用所需的数据填充它可能会更容易,例如
,您可以将其代替输入流。
It's probably easier just to instantiate ByteArrayInputStream instance instead of mocking it and filling it with data you need, e.g.
and you can just use that in place of your InputStream.