KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.mockobjects.net;
2
3 import alt.java.net.Socket;
4 import com.mockobjects.ExpectationCounter;
5 import com.mockobjects.ExpectationValue;
6 import com.mockobjects.MockObject;
7 import com.mockobjects.ReturnValue;
8
9 import java.io.IOException JavaDoc;
10 import java.io.InputStream JavaDoc;
11 import java.io.OutputStream JavaDoc;
12 import java.net.InetAddress JavaDoc;
13 import java.net.SocketException JavaDoc;
14
15 public class MockSocket extends MockObject implements Socket {
16     private final ExpectationValue mySoTimeout = new ExpectationValue("so timeout");
17     private final ReturnValue myInputStream = new ReturnValue("input stream");
18     private final ReturnValue myOutputStream = new ReturnValue("output stream");
19     private final ExpectationCounter myCloseCalls = new ExpectationCounter("close calls");
20
21     public InetAddress JavaDoc getInetAddress() {
22         notImplemented();
23         return null;
24     }
25
26     public InetAddress JavaDoc getLocalAddress() {
27         notImplemented();
28         return null;
29     }
30
31     public int getPort() {
32         notImplemented();
33         return 0;
34     }
35
36     public int getLocalPort() {
37         notImplemented();
38         return 0;
39     }
40
41     public void setupGetInputStream(InputStream JavaDoc anInputStream) {
42         myInputStream.setValue(anInputStream);
43     }
44
45     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
46         return (InputStream JavaDoc) myInputStream.getValue();
47     }
48
49     public void setupGetOutputStream(OutputStream JavaDoc anOutputStream) {
50         myOutputStream.setValue(anOutputStream);
51     }
52
53     public OutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
54         return (OutputStream JavaDoc) myOutputStream.getValue();
55     }
56
57     public void setTcpNoDelay(boolean on) throws SocketException JavaDoc {
58         notImplemented();
59     }
60
61     public boolean getTcpNoDelay() throws SocketException JavaDoc {
62         notImplemented();
63         return false;
64     }
65
66     public void setSoLinger(boolean on, int linger) throws SocketException JavaDoc {
67         notImplemented();
68     }
69
70     public int getSoLinger() throws SocketException JavaDoc {
71         notImplemented();
72         return 0;
73     }
74
75     public void setExpectedSoTimeout(int aSoTimeout) {
76         mySoTimeout.setExpected(aSoTimeout);
77     }
78
79     public void setSoTimeout(int aSoTimeout) throws SocketException JavaDoc {
80         mySoTimeout.setActual(aSoTimeout);
81     }
82
83     public int getSoTimeout() throws SocketException JavaDoc {
84         notImplemented();
85         return 0;
86     }
87
88     public void setSendBufferSize(int size)
89         throws SocketException JavaDoc {
90         notImplemented();
91     }
92
93     public int getSendBufferSize() throws SocketException JavaDoc {
94         notImplemented();
95         return 0;
96     }
97
98     public void setReceiveBufferSize(int size)
99         throws SocketException JavaDoc {
100         notImplemented();
101     }
102
103     public int getReceiveBufferSize()
104         throws SocketException JavaDoc {
105         notImplemented();
106         return 0;
107     }
108
109     public void setKeepAlive(boolean on) throws SocketException JavaDoc {
110         notImplemented();
111     }
112
113     public boolean getKeepAlive() throws SocketException JavaDoc {
114         notImplemented();
115         return false;
116     }
117
118     public void setExpectedCloseCalls(int aCount) {
119         myCloseCalls.setExpected(aCount);
120     }
121
122     public void close() throws IOException JavaDoc {
123         myCloseCalls.inc();
124     }
125
126     public void shutdownInput() throws IOException JavaDoc {
127         notImplemented();
128     }
129
130     public void shutdownOutput() throws IOException JavaDoc {
131         notImplemented();
132     }
133 }
134
Popular Tags