forked from ucsd-cse15l-w24/chat-server-pro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHandlerTests.java
36 lines (33 loc) · 1.24 KB
/
HandlerTests.java
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
import static org.junit.Assert.*;
import org.junit.*;
import java.net.URI;
public class HandlerTests {
@Test
public void handleRequest1() throws Exception {
ChatHandler h = new ChatHandler();
String url = "http://localhost:4000/chat?user=joe&message=hi";
URI input = new URI(url);
String expected = "joe: hi\n\n";
assertEquals(expected, h.handleRequest(input));
}
@Test
public void handleRequest2() throws Exception {
ChatHandler h = new ChatHandler();
// NOTE: %20 is the way to put a space in the parameters of a URL
String url = "http://localhost:4000/chat?user=edwin&message=happy%20friday!";
URI input = new URI(url);
String expected = "edwin: happy friday!\n\n";
assertEquals(expected, h.handleRequest(input));
}
@Test
public void handleRequestMulti() throws Exception {
ChatHandler h = new ChatHandler();
String url1 = "http://localhost:4000/chat?user=onat&message=good%20luck";
String url2 = "http://localhost:4000/chat?user=edwin&message=with%20your%20demo!";
URI input1 = new URI(url1);
URI input2 = new URI(url2);
String expected = "onat: good luck\n\nedwin: with your demo!\n\n";
h.handleRequest(input1);
assertEquals(expected, h.handleRequest(input2));
}
}