【发布时间】:2019-03-22 06:46:55
【问题描述】:
我有一段代码要测试 -
ServerHello connect(
int version, Collection<Integer> cipherSuites)
{
Socket s = null;
try {
if(proxy!=null) {
s = new Socket(proxy);
}else {
s = new Socket();
}
try {
s.connect(isa);
} catch (IOException ioe) {
System.err.println("could not connect to "
+ isa + ": " + ioe.toString());
return null;
}
byte[] ch = makeClientHello(version, cipherSuites);
OutputRecord orec = new OutputRecord(
s.getOutputStream());
orec.setType(Constants.HANDSHAKE);
orec.setVersion(version);
orec.write(ch);
orec.flush();
ServerHello x = new ServerHello(s.getInputStream());
return x;
} catch (IOException ioe) {
} finally {
try {
s.close();
} catch (IOException ioe) {
// ignored
}
}
return null;
}
我想用我自己的模拟 this.socket.getInputStream() 和 this.socket.getOutputStream() 数据。如何设置这些数据?
另外,我想确保 this.socket.connect() 在任何测试中通过,而不会在我的测试中抛出任何异常(离线测试)。
我该怎么做?我正在使用 Mockito 框架进行测试
【问题讨论】:
标签: java unit-testing junit mockito