4646import static org .junit .Assert .assertNull ;
4747import static org .junit .Assert .assertSame ;
4848import static org .junit .Assert .assertThat ;
49+ import static org .junit .Assert .assertThrows ;
4950import static org .junit .Assert .assertTrue ;
5051import static org .junit .Assert .fail ;
5152
@@ -150,7 +151,7 @@ public void attach_detach() {
150151 }
151152 }
152153
153- /* @Test*/
154+ @ Test
154155 public void attach_with_channel_params_channels_get () {
155156 String channelName = "attach_with_channel_params_channels_get_" + testParams .name ;
156157 AblyRealtime ably = null ;
@@ -163,7 +164,7 @@ public void attach_with_channel_params_channels_get() {
163164 assertEquals ("Verify connected state reached" , ConnectionState .connected , ably .connection .state );
164165
165166 ChannelOptions options = new ChannelOptions ();
166- options .params = new HashMap <String , String >();
167+ options .params = new HashMap <>();
167168 options .params .put ("modes" , "subscribe" );
168169 options .params .put ("delta" , "vcdiff" );
169170
@@ -183,7 +184,7 @@ public void attach_with_channel_params_channels_get() {
183184 }
184185 }
185186
186- /* @Test*/
187+ @ Test
187188 public void attach_with_channel_params_set_options () {
188189 String channelName = "attach_with_channel_params_set_options_" + testParams .name ;
189190 AblyRealtime ably = null ;
@@ -196,6 +197,7 @@ public void attach_with_channel_params_set_options() {
196197 assertEquals ("Verify connected state reached" , ConnectionState .connected , ably .connection .state );
197198
198199 ChannelOptions options = new ChannelOptions ();
200+ options .params = new HashMap <>();
199201 options .params .put ("modes" , "subscribe" );
200202 options .params .put ("delta" , "vcdiff" );
201203
@@ -216,7 +218,7 @@ public void attach_with_channel_params_set_options() {
216218 }
217219 }
218220
219- /* @Test*/
221+ @ Test
220222 public void channels_get_should_throw_when_would_cause_reattach () {
221223 String channelName = "channels_get_should_throw_when_would_cause_reattach_" + testParams .name ;
222224 AblyRealtime ably = null ;
@@ -228,22 +230,25 @@ public void channels_get_should_throw_when_would_cause_reattach() {
228230 (new ConnectionWaiter (ably .connection )).waitFor (ConnectionState .connected );
229231 assertEquals ("Verify connected state reached" , ConnectionState .connected , ably .connection .state );
230232
231- ChannelOptions options = new ChannelOptions ();
232- options .params .put ("modes" , "subscribe" );
233- options .params .put ("delta" , "vcdiff" );
233+ ChannelOptions options = new ChannelOptions () {{
234+ params = new HashMap <>();
235+ params .put ("modes" , "subscribe" );
236+ params .put ("delta" , "vcdiff" );
237+ }};
234238
235239 /* create a channel and attach */
236240 final Channel channel = ably .channels .get (channelName , options );
237241 channel .attach ();
238242 (new ChannelWaiter (channel )).waitFor (ChannelState .attached );
239243
240- try {
241- ably .channels .get (channelName , options );
242- } catch (AblyException e ) {
243- assertEquals ("Verify error code" , 400 , e .errorInfo .code );
244- assertEquals ("Verify error status code" , 40000 , e .errorInfo .statusCode );
245- assertTrue ("Verify error message" , e .errorInfo .message .contains ("setOptions" ));
246- }
244+ AblyRealtime finalAbly = ably ;
245+ AblyException exception = assertThrows (AblyException .class , () ->
246+ finalAbly .channels .get (channelName , options ));
247+
248+ assertEquals ("Verify error code" , 400 , exception .errorInfo .code );
249+ assertEquals ("Verify error status code" , 40000 , exception .errorInfo .statusCode );
250+ assertTrue ("Verify error message" , exception .errorInfo .message .contains ("use Channel.setOptions()" ));
251+
247252 } catch (AblyException e ) {
248253 e .printStackTrace ();
249254 fail ("init0: Unexpected exception instantiating library" );
0 commit comments