@@ -48,7 +48,7 @@ class SocketTest {
4848    internal  fun  `sets defaults` 
4949      val  socket =  Socket (" wss://localhost:4000/socket" 
5050
51-       assertThat(socket.params ).isNull()
51+       assertThat(socket.paramsClosure ).isNull()
5252      assertThat(socket.channels).isEmpty()
5353      assertThat(socket.sendBuffer).isEmpty()
5454      assertThat(socket.ref).isEqualTo(0 )
@@ -81,7 +81,7 @@ class SocketTest {
8181      socket.logger =  { }
8282      socket.reconnectAfterMs =  { 10  }
8383
84-       assertThat(socket.params ).isEqualTo(mapOf (" one" 2 ))
84+       assertThat(socket.paramsClosure?.invoke() ).isEqualTo(mapOf (" one" 2 ))
8585      assertThat(socket.endpoint).isEqualTo(" wss://localhost:4000/socket/websocket" 
8686      assertThat(socket.timeout).isEqualTo(40_000 )
8787      assertThat(socket.heartbeatIntervalMs).isEqualTo(60_000 )
@@ -94,32 +94,34 @@ class SocketTest {
9494    internal  fun  `constructs with a valid URL` 
9595      //  Test different schemes
9696      assertThat(Socket (" http://localhost:4000/socket/websocket" 
97-            .isEqualTo(" http://localhost:4000/socket/websocket" 
97+         .isEqualTo(" http://localhost:4000/socket/websocket" 
9898
9999      assertThat(Socket (" https://localhost:4000/socket/websocket" 
100-            .isEqualTo(" https://localhost:4000/socket/websocket" 
100+         .isEqualTo(" https://localhost:4000/socket/websocket" 
101101
102102      assertThat(Socket (" ws://localhost:4000/socket/websocket" 
103-            .isEqualTo(" http://localhost:4000/socket/websocket" 
103+         .isEqualTo(" http://localhost:4000/socket/websocket" 
104104
105105      assertThat(Socket (" wss://localhost:4000/socket/websocket" 
106-            .isEqualTo(" https://localhost:4000/socket/websocket" 
106+         .isEqualTo(" https://localhost:4000/socket/websocket" 
107107
108108      //  test params
109109      val  singleParam =  hashMapOf(" token" " abc123" 
110110      assertThat(Socket (" ws://localhost:4000/socket/websocket" 
111-            .isEqualTo(" http://localhost:4000/socket/websocket?token=abc123" 
111+         .isEqualTo(" http://localhost:4000/socket/websocket?token=abc123" 
112112
113113      val  multipleParams =  hashMapOf(" token" " abc123" " user_id" 1 )
114114      assertThat(
115-           Socket (" http://localhost:4000/socket/websocket" 
116-           .isEqualTo(" http://localhost:4000/socket/websocket?user_id=1&token=abc123" 
115+         Socket (" http://localhost:4000/socket/websocket" 
116+       )
117+         .isEqualTo(" http://localhost:4000/socket/websocket?user_id=1&token=abc123" 
117118
118119      //  test params with spaces
119120      val  spacesParams =  hashMapOf(" token" " abc 123" " user_id" 1 )
120121      assertThat(
121-           Socket (" wss://localhost:4000/socket/websocket" 
122-           .isEqualTo(" https://localhost:4000/socket/websocket?user_id=1&token=abc%20123" 
122+         Socket (" wss://localhost:4000/socket/websocket" 
123+       )
124+         .isEqualTo(" https://localhost:4000/socket/websocket?user_id=1&token=abc%20123" 
123125    }
124126
125127    /*  End Constructor */ 
@@ -185,6 +187,28 @@ class SocketTest {
185187      assertThat(socket.connection).isNotNull()
186188    }
187189
190+     @Test
191+     internal  fun  `accounts for changing parameters` 
192+       val  transport =  mock< (URL ) ->  Transport > ()
193+       whenever(transport.invoke(any())).thenReturn(connection)
194+ 
195+       var  token =  " a" 
196+       val  socket =  Socket (" wss://localhost:4000/socket" mapOf (" token" 
197+       socket.transport =  transport
198+ 
199+       socket.connect()
200+       argumentCaptor<URL > {
201+         verify(transport).invoke(capture())
202+         assertThat(firstValue.query).isEqualTo(" token=a" 
203+ 
204+         token =  " b" 
205+         socket.disconnect()
206+         socket.connect()
207+         verify(transport, times(2 )).invoke(capture())
208+         assertThat(lastValue.query).isEqualTo(" token=b" 
209+       }
210+     }
211+ 
188212    @Test
189213    internal  fun  `sets callbacks for connection` 
190214      var  open =  0 
@@ -216,10 +240,10 @@ class SocketTest {
216240      assertThat(lastResponse).isNull()
217241
218242      val  data =  mapOf (
219-            " topic" " topic" 
220-            " event" " event" 
221-            " payload" mapOf (" go" true ),
222-            " status" " status" 
243+         " topic" " topic" 
244+         " event" " event" 
245+         " payload" mapOf (" go" true ),
246+         " status" " status" 
223247      )
224248
225249      val  json =  Defaults .gson.toJson(data)
@@ -259,10 +283,10 @@ class SocketTest {
259283      assertThat(lastResponse).isNull()
260284
261285      val  data =  mapOf (
262-            " topic" " topic" 
263-            " event" " event" 
264-            " payload" mapOf (" go" true ),
265-            " status" " status" 
286+         " topic" " topic" 
287+         " event" " event" 
288+         " payload" mapOf (" go" true ),
289+         " status" " status" 
266290      )
267291
268292      val  json =  Defaults .gson.toJson(data)
@@ -457,7 +481,7 @@ class SocketTest {
457481      socket.push(" topic" " event" mapOf (" one" " two" " ref" " join-ref" 
458482
459483      val  expect = 
460-            " {\" topic\" :\" topic\" ,\" event\" :\" event\" ,\" payload\" :{\" one\" :\" two\" },\" ref\" :\" ref\" ,\" join_ref\" :\" join-ref\" }" 
484+         " {\" topic\" :\" topic\" ,\" event\" :\" event\" ,\" payload\" :{\" one\" :\" two\" },\" ref\" :\" ref\" ,\" join_ref\" :\" join-ref\" }" 
461485      verify(connection).send(expect)
462486    }
463487
@@ -624,7 +648,6 @@ class SocketTest {
624648    }
625649  }
626650
627- 
628651  @Nested
629652  @DisplayName(" resetHeartbeat" 
630653  inner  class  ResetHeartbeat  {
@@ -658,14 +681,16 @@ class SocketTest {
658681
659682      assertThat(socket.heartbeatTask).isNotNull()
660683      argumentCaptor< () ->  Unit >  {
661-         verify(mockDispatchQueue).queueAtFixedRate(eq(5_000L ), eq(5_000L ),
662-             eq(TimeUnit .MILLISECONDS ), capture())
684+         verify(mockDispatchQueue).queueAtFixedRate(
685+           eq(5_000L ), eq(5_000L ),
686+           eq(TimeUnit .MILLISECONDS ), capture()
687+         )
663688
664689        //  fire the task
665690        allValues.first().invoke()
666691
667692        val  expected = 
668-              " {\" topic\" :\" phoenix\" ,\" event\" :\" heartbeat\" ,\" payload\" :{},\" ref\" :\" 1\" }" 
693+           " {\" topic\" :\" phoenix\" ,\" event\" :\" heartbeat\" ,\" payload\" :{},\" ref\" :\" 1\" }" 
669694        verify(connection).send(expected)
670695      }
671696    }
@@ -937,7 +962,7 @@ class SocketTest {
937962      socket.channels =  socket.channels.minus(otherChannel)
938963
939964      val  rawMessage = 
940-            " {\" topic\" :\" topic\" ,\" event\" :\" event\" ,\" payload\" :{\" one\" :\" two\" },\" status\" :\" ok\" }" 
965+         " {\" topic\" :\" topic\" ,\" event\" :\" event\" ,\" payload\" :{\" one\" :\" two\" },\" status\" :\" ok\" }" 
941966      socket.onConnectionMessage(rawMessage)
942967
943968      verify(targetChannel).trigger(message =  any())
@@ -950,7 +975,7 @@ class SocketTest {
950975      socket.onMessage { message =  it }
951976
952977      val  rawMessage = 
953-            " {\" topic\" :\" topic\" ,\" event\" :\" event\" ,\" payload\" :{\" one\" :\" two\" },\" status\" :\" ok\" }" 
978+         " {\" topic\" :\" topic\" ,\" event\" :\" event\" ,\" payload\" :{\" one\" :\" two\" },\" status\" :\" ok\" }" 
954979      socket.onConnectionMessage(rawMessage)
955980
956981      assertThat(message?.topic).isEqualTo(" topic" 
@@ -962,15 +987,14 @@ class SocketTest {
962987      socket.pendingHeartbeatRef =  " 5" 
963988
964989      val  rawMessage = 
965-            " {\" topic\" :\" topic\" ,\" event\" :\" event\" ,\" payload\" :{\" one\" :\" two\" },\" ref\" :\" 5\" }" 
990+         " {\" topic\" :\" topic\" ,\" event\" :\" event\" ,\" payload\" :{\" one\" :\" two\" },\" ref\" :\" 5\" }" 
966991      socket.onConnectionMessage(rawMessage)
967992      assertThat(socket.pendingHeartbeatRef).isNull()
968993    }
969994
970995    /*  End OnConnectionMessage */ 
971996  }
972997
973- 
974998  @Nested
975999  @DisplayName(" ConcurrentModificationException" 
9761000  inner  class  ConcurrentModificationExceptionTests  {
@@ -1015,7 +1039,7 @@ class SocketTest {
10151039    internal  fun  `onError does not throw` 
10161040      var  oneCalled =  0 
10171041      var  twoCalled =  0 
1018-       socket.onError { _, _-> 
1042+       socket.onError { _, _  -> 
10191043        socket.onError { _, _ ->  twoCalled + =  1  }
10201044        oneCalled + =  1 
10211045      }
@@ -1061,6 +1085,4 @@ class SocketTest {
10611085
10621086    /*  End ConcurrentModificationExceptionTests */ 
10631087  }
1064- 
1065- 
10661088}
0 commit comments