I have a piece of code I'd like to test -
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;
}
I want to mock this.socket.getInputStream()
and this.socket.getOutputStream()
data with my own. How do I set this data?
And also, I want o make sure that this.socket.connect()
passes in any test without throwing any exceptions in my tests (offline tests).
How do I do it ? I'm using Mockito framework for tests