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 ; 10 import java.io.InputStream ; 11 import java.io.OutputStream ; 12 import java.net.InetAddress ; 13 import java.net.SocketException ; 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 getInetAddress() { 22 notImplemented(); 23 return null; 24 } 25 26 public InetAddress 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 anInputStream) { 42 myInputStream.setValue(anInputStream); 43 } 44 45 public InputStream getInputStream() throws IOException { 46 return (InputStream ) myInputStream.getValue(); 47 } 48 49 public void setupGetOutputStream(OutputStream anOutputStream) { 50 myOutputStream.setValue(anOutputStream); 51 } 52 53 public OutputStream getOutputStream() throws IOException { 54 return (OutputStream ) myOutputStream.getValue(); 55 } 56 57 public void setTcpNoDelay(boolean on) throws SocketException { 58 notImplemented(); 59 } 60 61 public boolean getTcpNoDelay() throws SocketException { 62 notImplemented(); 63 return false; 64 } 65 66 public void setSoLinger(boolean on, int linger) throws SocketException { 67 notImplemented(); 68 } 69 70 public int getSoLinger() throws SocketException { 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 { 80 mySoTimeout.setActual(aSoTimeout); 81 } 82 83 public int getSoTimeout() throws SocketException { 84 notImplemented(); 85 return 0; 86 } 87 88 public void setSendBufferSize(int size) 89 throws SocketException { 90 notImplemented(); 91 } 92 93 public int getSendBufferSize() throws SocketException { 94 notImplemented(); 95 return 0; 96 } 97 98 public void setReceiveBufferSize(int size) 99 throws SocketException { 100 notImplemented(); 101 } 102 103 public int getReceiveBufferSize() 104 throws SocketException { 105 notImplemented(); 106 return 0; 107 } 108 109 public void setKeepAlive(boolean on) throws SocketException { 110 notImplemented(); 111 } 112 113 public boolean getKeepAlive() throws SocketException { 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 { 123 myCloseCalls.inc(); 124 } 125 126 public void shutdownInput() throws IOException { 127 notImplemented(); 128 } 129 130 public void shutdownOutput() throws IOException { 131 notImplemented(); 132 } 133 } 134 | Popular Tags |