3
3
import static com .thoughtworks .selenium .grid .AssertionHelper .assertDistinctHashCodes ;
4
4
import static com .thoughtworks .selenium .grid .AssertionHelper .assertNotEquals ;
5
5
import static com .thoughtworks .selenium .grid .AssertionHelper .assertSameHashCode ;
6
- import com .thoughtworks .selenium .grid .HttpClient ;
7
- import com .thoughtworks .selenium .grid .HttpParameters ;
8
- import com .thoughtworks .selenium .grid .Response ;
9
6
import static junit .framework .Assert .assertEquals ;
10
7
import static junit .framework .Assert .assertFalse ;
11
8
import static junit .framework .Assert .assertTrue ;
12
- import org .jbehave .classmock .UsingClassMock ;
13
- import org .jbehave .core .mock .Mock ;
14
- import org .junit .Test ;
9
+ import static org .mockito .Mockito .mock ;
10
+ import static org .mockito .Mockito .when ;
15
11
16
12
import java .io .IOException ;
17
13
14
+ import org .junit .Test ;
15
+
16
+ import com .thoughtworks .selenium .grid .HttpClient ;
17
+ import com .thoughtworks .selenium .grid .HttpParameters ;
18
+ import com .thoughtworks .selenium .grid .Response ;
18
19
19
- public class RemoteControlProxyTest extends UsingClassMock {
20
+ public class RemoteControlProxyTest {
20
21
21
22
@ Test (expected = IllegalArgumentException .class )
22
23
public void contructorThrowsIllegalArgumentExceptionWhenServerIsNull () {
@@ -113,22 +114,19 @@ public void remoteControlPingURLTargetsTheBlankPage() {
113
114
final RemoteControlProxy proxy = new RemoteControlProxy ("localhost" , 5555 , "" , null );
114
115
assertEquals ("http://localhost:5555/selenium-server/heartbeat" , proxy .remoteControlPingURL ());
115
116
}
116
-
117
+
117
118
@ Test
118
119
public void forwardReturnsTheResponseOfTheSeleniumRC () throws IOException {
119
120
final RemoteControlProxy proxy ;
120
121
final Response expectedResponse ;
121
122
final HttpParameters parameters ;
122
- final Mock client ;
123
-
124
- expectedResponse = new Response (0 , "" );
125
- client = mock (HttpClient .class );
123
+
124
+ HttpClient client = mock (HttpClient .class );
126
125
parameters = new HttpParameters ();
127
- client .expects ("post" ).with (eq ("http://foo:10/selenium-server/driver/" ), eq (parameters )).will (returnValue (expectedResponse ));
126
+ expectedResponse = new Response (0 , "" );
127
+ when (client .post ("http://foo:10/selenium-server/driver/" , parameters )).thenReturn (expectedResponse );
128
128
proxy = new RemoteControlProxy ("foo" , 10 , "" , (HttpClient ) client );
129
129
assertEquals (expectedResponse , proxy .forward (parameters ));
130
-
131
- verifyMocks ();
132
130
}
133
131
134
132
@ Test
@@ -143,11 +141,9 @@ public void toStringIncludesSessionInProgressInformation() {
143
141
144
142
remoteControl = new RemoteControlProxy ("grid.org" , 4444 , "" , null );
145
143
remoteControl .registerNewSession ();
146
- assertEquals ("[RemoteControlProxy grid.org:4444#true]" ,
147
- remoteControl .toString ());
144
+ assertEquals ("[RemoteControlProxy grid.org:4444#true]" , remoteControl .toString ());
148
145
}
149
146
150
- @ SuppressWarnings ({"EqualsBetweenInconvertibleTypes" })
151
147
@ Test
152
148
public void aRemoteControlsIsNotEqualToARandomObject () {
153
149
assertNotEquals (new RemoteControlProxy ("a.host.com" , 24 , "" , new HttpClient ()), "a random object" );
@@ -215,81 +211,70 @@ public void twoRemoteControlsDoNotHaveTheSameHashcodelIfTheirPortsDoNotMatch() {
215
211
}
216
212
217
213
@ Test
218
- public void unreliableReturnsFalseWhenTheResponseIsSuccessful () {
214
+ public void unreliableReturnsFalseWhenTheResponseIsSuccessful () throws IOException {
219
215
final RemoteControlProxy proxy ;
220
216
final Response successfulResponse ;
221
- final Mock client ;
222
217
223
- client = mock (HttpClient .class );
218
+ HttpClient client = mock (HttpClient .class );
224
219
successfulResponse = new Response (200 , "" );
225
- client .expects ( " get" ). with ( eq ( "http://foo:10/selenium-server/heartbeat" )).will ( returnValue ( successfulResponse ) );
220
+ when ( client .get ( "http://foo:10/selenium-server/heartbeat" )).thenReturn ( successfulResponse );
226
221
proxy = new RemoteControlProxy ("foo" , 10 , "" , (HttpClient ) client );
222
+ proxy .registerNewSession ();
227
223
assertFalse (proxy .unreliable ());
228
-
229
- verifyMocks ();
230
224
}
231
225
232
226
@ Test
233
- public void unreliableReturnsTrueWhenTheResponseIsA500 () {
227
+ public void unreliableReturnsTrueWhenTheResponseIsA500 () throws IOException {
234
228
final RemoteControlProxy proxy ;
235
229
final Response badResponse ;
236
- final Mock client ;
237
-
238
- client = mock (HttpClient .class );
230
+
231
+ HttpClient client = mock (HttpClient .class );
239
232
badResponse = new Response (500 , "" );
240
- client .expects ( " get" ). with ( eq ( "http://foo:10/selenium-server/heartbeat" )).will ( returnValue ( badResponse ) );
233
+ when ( client .get ( "http://foo:10/selenium-server/heartbeat" )).thenReturn ( badResponse );
241
234
proxy = new RemoteControlProxy ("foo" , 10 , "" , (HttpClient ) client );
235
+ proxy .registerNewSession ();
242
236
assertTrue (proxy .unreliable ());
243
-
244
- verifyMocks ();
245
237
}
246
-
247
- @ SuppressWarnings ({"ThrowableInstanceNeverThrown" })
238
+
248
239
@ Test
249
- public void unreliableReturnsTrueWhenTheRemoteControlCannotBeReached () {
240
+ public void unreliableReturnsTrueWhenTheRemoteControlCannotBeReached () throws IOException {
250
241
final RemoteControlProxy proxy ;
251
- final Mock client ;
252
242
253
- client = mock (HttpClient .class );
254
- client .expects ("get" ).with (eq ("http://foo:10/selenium-server/heartbeat" )).
255
- will (throwException (new RuntimeException ("Simulated Error" )));
243
+ HttpClient client = mock (HttpClient .class );
244
+ when (client .get ("http://foo:10/selenium-server/heartbeat" )).thenThrow (new RuntimeException ());
256
245
proxy = new RemoteControlProxy ("foo" , 10 , "" , (HttpClient ) client );
246
+ proxy .registerNewSession ();
257
247
assertTrue (proxy .unreliable ());
258
-
259
- verifyMocks ();
260
248
}
261
-
262
- @ SuppressWarnings ({"ThrowableInstanceNeverThrown" })
249
+
263
250
@ Test
264
- public void unreliableReturnsFalseWhenTheRemoteControlCannotBeReachedAtFirstButRecovers () {
251
+ public void unreliableReturnsFalseWhenTheRemoteControlCannotBeReachedAtFirstButRecovers () throws IOException {
265
252
final RemoteControlProxy proxy ;
266
253
final Response successfulResponse ;
267
- final Mock client ;
268
254
269
- client = mock (HttpClient .class );
255
+ HttpClient client = mock (HttpClient .class );
270
256
successfulResponse = new Response (200 , "" );
271
- client .expects ("get" ).with (eq ("http://foo:10/selenium-server/heartbeat" )).
272
- will (throwException (new RuntimeException ("Simulated Error" ))).will (returnValue (successfulResponse ));
257
+ when (client .get ("http://foo:10/selenium-server/heartbeat" ))
258
+ .thenThrow (new RuntimeException ())
259
+ .thenReturn (successfulResponse );
273
260
proxy = new RemoteControlProxy ("foo" , 10 , "" , (HttpClient ) client );
261
+ proxy .registerNewSession ();
274
262
assertFalse (proxy .unreliable ());
275
-
276
- verifyMocks ();
277
263
}
278
-
264
+
279
265
@ Test
280
- public void unreliableReturnsFalseWhenTheResponseIsA500ThenA200 () {
266
+ public void unreliableReturnsFalseWhenTheResponseIsA500ThenA200 () throws IOException {
281
267
final RemoteControlProxy proxy ;
282
268
final Response badResponse ;
283
269
final Response successfulResponse ;
284
- final Mock client ;
285
270
286
- client = mock (HttpClient .class );
271
+ HttpClient client = mock (HttpClient .class );
287
272
badResponse = new Response (500 , "" );
288
273
successfulResponse = new Response (200 , "" );
289
- client .expects ( " get" ). with ( eq ( "http://foo:10/selenium-server/heartbeat" )).will ( returnValue ( badResponse )). will ( returnValue ( successfulResponse ) );
274
+ when ( client .get ( "http://foo:10/selenium-server/heartbeat" )).thenReturn ( badResponse , successfulResponse );
290
275
proxy = new RemoteControlProxy ("foo" , 10 , "" , (HttpClient ) client );
276
+ proxy .registerNewSession ();
291
277
assertFalse (proxy .unreliable ());
292
-
293
- verifyMocks ();
294
278
}
279
+
295
280
}
0 commit comments