11package io .socket .parser ;
22
3- import io .socket .emitter .Emitter ;
43import org .json .JSONArray ;
54import org .json .JSONException ;
6- import org .json .JSONObject ;
75import org .junit .Test ;
86import org .junit .runner .RunWith ;
97import org .junit .runners .JUnit4 ;
108
119import java .nio .charset .Charset ;
10+ import java .nio .charset .StandardCharsets ;
1211
12+ import static java .util .Arrays .asList ;
1313import static org .hamcrest .CoreMatchers .is ;
1414import static org .junit .Assert .assertThat ;
1515
@@ -19,30 +19,30 @@ public class ByteArrayTest {
1919 private static Parser .Encoder encoder = new IOParser .Encoder ();
2020
2121 @ 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 ) ));
2525 packet .id = 23 ;
2626 packet .nsp = "/cool" ;
2727 Helpers .testBin (packet );
2828 }
2929
3030 @ Test
3131 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 })) ;
3434 packet .id = 0 ;
3535 packet .nsp = "/" ;
3636 Helpers .testBin (packet );
3737 }
3838
3939 @ Test
4040 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 ]);
4444
45- Packet <JSONObject > packet = new Packet <>(Parser .BINARY_EVENT );
45+ Packet <JSONArray > packet = new Packet <>(Parser .BINARY_EVENT );
4646 packet .data = data ;
4747 packet .id = 999 ;
4848 packet .nsp = "/deep" ;
@@ -51,10 +51,10 @@ public void encodeByteArrayDeepInJson() throws JSONException {
5151
5252 @ Test
5353 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 ]);
5656
57- Packet <JSONObject > packet = new Packet <>(Parser .BINARY_EVENT );
57+ Packet <JSONArray > packet = new Packet <>(Parser .BINARY_EVENT );
5858 packet .data = data ;
5959 packet .nsp = "/" ;
6060 packet .id = 600 ;
0 commit comments