-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMocket.java
More file actions
48 lines (41 loc) · 1.26 KB
/
Mocket.java
File metadata and controls
48 lines (41 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cs3500.pa04;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.Socket;
import java.util.List;
/**
* Mock a Socket to simulate behaviors of ProxyControllers being connected to a server.
*/
public class Mocket extends Socket {
private final InputStream testInputs;
private final ByteArrayOutputStream testlog;
/**
* @param testlog what the server has received from the client
* @param toSend what the server will send to the client
*/
public Mocket(ByteArrayOutputStream testlog, List<String> toSend) {
this.testlog = testlog;
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
for (String message : toSend) {
pw.println(message);
}
this.testInputs = new ByteArrayInputStream(sw.toString().getBytes());
}
/**
* @return InputStream -> representing the test inputs for testing
*/
public InputStream getInputStream() {
return this.testInputs;
}
/**
* @return OutputStream -> representing the test ouputs
*/
public OutputStream getOutputStream() {
return this.testlog;
}
}