KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > net > MockSocketFactory


1 package com.mockobjects.net;
2
3 import alt.java.net.SocketFactory;
4 import alt.java.net.Socket;
5 import com.mockobjects.MockObject;
6 import com.mockobjects.ExpectationValue;
7 import com.mockobjects.ReturnValue;
8
9 public class MockSocketFactory extends MockObject implements SocketFactory {
10     private final ExpectationValue myHost = new ExpectationValue("host");
11     private final ExpectationValue myPort = new ExpectationValue("port");
12     private final ReturnValue mySocket = new ReturnValue("socket");
13
14     public void setupCreateSocket(Socket aSocket) {
15         mySocket.setValue(aSocket);
16     }
17
18     public void setExpectedHost(String JavaDoc aHost) {
19         myHost.setExpected(aHost);
20     }
21
22     public void setExpectedPort(String JavaDoc aPort) {
23         myPort.setExpected(aPort);
24     }
25
26     public Socket createSocket(String JavaDoc aHost, int aPort) {
27         myHost.setActual(aHost);
28         myPort.setActual(aPort);
29         return (Socket) mySocket.getValue();
30     }
31 }
32
Popular Tags