forked from socketio/socket.io-client-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParserTest.java
More file actions
67 lines (58 loc) · 2.04 KB
/
Copy pathParserTest.java
File metadata and controls
67 lines (58 loc) · 2.04 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package io.socket.parser;
import org.json.JSONArray;
import org.json.JSONException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ParserTest {
private static Parser.Encoder encoder = new IOParser.Encoder();
@Test
public void encodeConnection() {
Packet packet = new Packet(Parser.CONNECT);
packet.nsp = "/woot";
Helpers.test(packet);
}
@Test
public void encodeDisconnection() {
Packet packet = new Packet(Parser.DISCONNECT);
packet.nsp = "/woot";
Helpers.test(packet);
}
@Test
public void encodeEvent() throws JSONException {
Packet<JSONArray> packet1 = new Packet<JSONArray>(Parser.EVENT);
packet1.data = new JSONArray("[\"a\", 1, {}]");
packet1.nsp = "/";
Helpers.test(packet1);
Packet<JSONArray> packet2 = new Packet<JSONArray>(Parser.EVENT);
packet2.data = new JSONArray("[\"a\", 1, {}]");
packet2.nsp = "/test";
Helpers.test(packet2);
}
@Test
public void encodeAck() throws JSONException {
Packet<JSONArray> packet = new Packet<JSONArray>(Parser.ACK);
packet.data = new JSONArray("[\"a\", 1, {}]");
packet.id = 123;
packet.nsp = "/";
Helpers.test(packet);
}
@Test
public void decodeInError() throws JSONException {
// Random string
Helpers.testDecodeError("asdf");
// Unknown type
Helpers.testDecodeError(Parser.types.length + "asdf");
// Binary event with no `-`
Helpers.testDecodeError(Parser.BINARY_EVENT + "asdf");
// Binary ack with no `-`
Helpers.testDecodeError(Parser.BINARY_ACK + "asdf");
// Binary event with no attachment
Helpers.testDecodeError(String.valueOf(Parser.BINARY_EVENT));
// event non numeric id
Helpers.testDecodeError(Parser.EVENT + "2sd");
// event with invalid json data
Helpers.testDecodeError(Parser.EVENT + "2[\"a\",1,{asdf}]");
}
}