我想为createSocket(String host,int port)方法编写单元测试,但是我有这个错误消息:
public SSLSocketFactory getSslSocketFactory() {
return sslSocketFactory;
}
public Socket createSocket(String host, int port)
throws IOException {
SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(host, port);
return sslSocket;
}
这是我写的测试:
@Before
public void setUp() throws Exception {
sslSocketFactory = mock(SSLSocketFactory.class);
clientCertSocketFactory = new ClientCertSocketFactory();
sslSocketFactory = clientCertSocketFactory.getSslSocketFactory();
}
@Test
public void shouldCreateSocketWithHostAndPort() throws Exception {
clientCertSocketFactory.createSocket(HOST, PORT);
verify(sslSocketFactory).createSocket(HOST, PORT);
}
如何修复此错误。感谢
答案 0 :(得分:0)
此代码全部错误。
模拟的ssl套接字工厂从未使用过 - 它被创建,然后被getSslSocketFactory
的调用所取代。