1
1
package io .socket .parser ;
2
2
3
- import io .socket .emitter .Emitter ;
4
3
import org .json .JSONArray ;
5
4
import org .json .JSONException ;
6
- import org .json .JSONObject ;
7
5
import org .junit .Test ;
8
6
import org .junit .runner .RunWith ;
9
7
import org .junit .runners .JUnit4 ;
10
8
11
9
import java .nio .charset .Charset ;
10
+ import java .nio .charset .StandardCharsets ;
12
11
12
+ import static java .util .Arrays .asList ;
13
13
import static org .hamcrest .CoreMatchers .is ;
14
14
import static org .junit .Assert .assertThat ;
15
15
@@ -19,30 +19,30 @@ public class ByteArrayTest {
19
19
private static Parser .Encoder encoder = new IOParser .Encoder ();
20
20
21
21
@ Test
22
- public void encodeByteArray () {
23
- Packet <byte [] > packet = new Packet <>(Parser .BINARY_EVENT );
24
- packet .data = "abc" .getBytes (Charset . forName ( "UTF-8" ));
22
+ public void encodeByteArray () throws JSONException {
23
+ Packet <JSONArray > packet = new Packet <>(Parser .BINARY_EVENT );
24
+ packet .data = new JSONArray ( asList ( "abc" , "abc" .getBytes (StandardCharsets . UTF_8 ) ));
25
25
packet .id = 23 ;
26
26
packet .nsp = "/cool" ;
27
27
Helpers .testBin (packet );
28
28
}
29
29
30
30
@ Test
31
31
public void encodeByteArray2 () {
32
- Packet <byte [] > packet = new Packet <>(Parser .BINARY_EVENT );
33
- packet .data = new byte [2 ] ;
32
+ Packet <JSONArray > packet = new Packet <>(Parser .BINARY_EVENT );
33
+ packet .data = new JSONArray ( asList ( "2" , new byte [] { 0 , 1 })) ;
34
34
packet .id = 0 ;
35
35
packet .nsp = "/" ;
36
36
Helpers .testBin (packet );
37
37
}
38
38
39
39
@ Test
40
40
public void encodeByteArrayDeepInJson () throws JSONException {
41
- JSONObject data = new JSONObject ( " {a: \" hi\" , b: {}, c: {a: \" bye\" , b: {}}}" );
42
- data .getJSONObject ("b" ).put ("why" , new byte [3 ]);
43
- data .getJSONObject ("c" ).getJSONObject ("b" ).put ("a" , new byte [6 ]);
41
+ JSONArray data = new JSONArray ( "[ {a: \" hi\" , b: {}, c: {a: \" bye\" , b: {}}}] " );
42
+ data .getJSONObject (0 ). getJSONObject ( "b" ).put ("why" , new byte [3 ]);
43
+ data .getJSONObject (0 ). getJSONObject ( "c" ).getJSONObject ("b" ).put ("a" , new byte [6 ]);
44
44
45
- Packet <JSONObject > packet = new Packet <>(Parser .BINARY_EVENT );
45
+ Packet <JSONArray > packet = new Packet <>(Parser .BINARY_EVENT );
46
46
packet .data = data ;
47
47
packet .id = 999 ;
48
48
packet .nsp = "/deep" ;
@@ -51,10 +51,10 @@ public void encodeByteArrayDeepInJson() throws JSONException {
51
51
52
52
@ Test
53
53
public void encodeDeepBinaryJSONWithNullValue () throws JSONException {
54
- JSONObject data = new JSONObject ( " {a: \" b\" , c: 4, e: {g: null}, h: null}" );
55
- data .put ("h" , new byte [9 ]);
54
+ JSONArray data = new JSONArray ( "[ {a: \" b\" , c: 4, e: {g: null}, h: null}] " );
55
+ data .getJSONObject ( 0 ). put ("h" , new byte [9 ]);
56
56
57
- Packet <JSONObject > packet = new Packet <>(Parser .BINARY_EVENT );
57
+ Packet <JSONArray > packet = new Packet <>(Parser .BINARY_EVENT );
58
58
packet .data = data ;
59
59
packet .nsp = "/" ;
60
60
packet .id = 600 ;
0 commit comments