33import static com .thoughtworks .selenium .grid .AssertionHelper .assertDistinctHashCodes ;
44import static com .thoughtworks .selenium .grid .AssertionHelper .assertNotEquals ;
55import 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 ;
96import static junit .framework .Assert .assertEquals ;
107import static junit .framework .Assert .assertFalse ;
118import 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 ;
1511
1612import java .io .IOException ;
1713
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 ;
1819
19- public class RemoteControlProxyTest extends UsingClassMock {
20+ public class RemoteControlProxyTest {
2021
2122 @ Test (expected = IllegalArgumentException .class )
2223 public void contructorThrowsIllegalArgumentExceptionWhenServerIsNull () {
@@ -113,22 +114,19 @@ public void remoteControlPingURLTargetsTheBlankPage() {
113114 final RemoteControlProxy proxy = new RemoteControlProxy ("localhost" , 5555 , "" , null );
114115 assertEquals ("http://localhost:5555/selenium-server/heartbeat" , proxy .remoteControlPingURL ());
115116 }
116-
117+
117118 @ Test
118119 public void forwardReturnsTheResponseOfTheSeleniumRC () throws IOException {
119120 final RemoteControlProxy proxy ;
120121 final Response expectedResponse ;
121122 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 );
126125 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 );
128128 proxy = new RemoteControlProxy ("foo" , 10 , "" , (HttpClient ) client );
129129 assertEquals (expectedResponse , proxy .forward (parameters ));
130-
131- verifyMocks ();
132130 }
133131
134132 @ Test
@@ -143,11 +141,9 @@ public void toStringIncludesSessionInProgressInformation() {
143141
144142 remoteControl = new RemoteControlProxy ("grid.org" , 4444 , "" , null );
145143 remoteControl .registerNewSession ();
146- assertEquals ("[RemoteControlProxy grid.org:4444#true]" ,
147- remoteControl .toString ());
144+ assertEquals ("[RemoteControlProxy grid.org:4444#true]" , remoteControl .toString ());
148145 }
149146
150- @ SuppressWarnings ({"EqualsBetweenInconvertibleTypes" })
151147 @ Test
152148 public void aRemoteControlsIsNotEqualToARandomObject () {
153149 assertNotEquals (new RemoteControlProxy ("a.host.com" , 24 , "" , new HttpClient ()), "a random object" );
@@ -215,81 +211,70 @@ public void twoRemoteControlsDoNotHaveTheSameHashcodelIfTheirPortsDoNotMatch() {
215211 }
216212
217213 @ Test
218- public void unreliableReturnsFalseWhenTheResponseIsSuccessful () {
214+ public void unreliableReturnsFalseWhenTheResponseIsSuccessful () throws IOException {
219215 final RemoteControlProxy proxy ;
220216 final Response successfulResponse ;
221- final Mock client ;
222217
223- client = mock (HttpClient .class );
218+ HttpClient client = mock (HttpClient .class );
224219 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 );
226221 proxy = new RemoteControlProxy ("foo" , 10 , "" , (HttpClient ) client );
222+ proxy .registerNewSession ();
227223 assertFalse (proxy .unreliable ());
228-
229- verifyMocks ();
230224 }
231225
232226 @ Test
233- public void unreliableReturnsTrueWhenTheResponseIsA500 () {
227+ public void unreliableReturnsTrueWhenTheResponseIsA500 () throws IOException {
234228 final RemoteControlProxy proxy ;
235229 final Response badResponse ;
236- final Mock client ;
237-
238- client = mock (HttpClient .class );
230+
231+ HttpClient client = mock (HttpClient .class );
239232 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 );
241234 proxy = new RemoteControlProxy ("foo" , 10 , "" , (HttpClient ) client );
235+ proxy .registerNewSession ();
242236 assertTrue (proxy .unreliable ());
243-
244- verifyMocks ();
245237 }
246-
247- @ SuppressWarnings ({"ThrowableInstanceNeverThrown" })
238+
248239 @ Test
249- public void unreliableReturnsTrueWhenTheRemoteControlCannotBeReached () {
240+ public void unreliableReturnsTrueWhenTheRemoteControlCannotBeReached () throws IOException {
250241 final RemoteControlProxy proxy ;
251- final Mock client ;
252242
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 ());
256245 proxy = new RemoteControlProxy ("foo" , 10 , "" , (HttpClient ) client );
246+ proxy .registerNewSession ();
257247 assertTrue (proxy .unreliable ());
258-
259- verifyMocks ();
260248 }
261-
262- @ SuppressWarnings ({"ThrowableInstanceNeverThrown" })
249+
263250 @ Test
264- public void unreliableReturnsFalseWhenTheRemoteControlCannotBeReachedAtFirstButRecovers () {
251+ public void unreliableReturnsFalseWhenTheRemoteControlCannotBeReachedAtFirstButRecovers () throws IOException {
265252 final RemoteControlProxy proxy ;
266253 final Response successfulResponse ;
267- final Mock client ;
268254
269- client = mock (HttpClient .class );
255+ HttpClient client = mock (HttpClient .class );
270256 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 );
273260 proxy = new RemoteControlProxy ("foo" , 10 , "" , (HttpClient ) client );
261+ proxy .registerNewSession ();
274262 assertFalse (proxy .unreliable ());
275-
276- verifyMocks ();
277263 }
278-
264+
279265 @ Test
280- public void unreliableReturnsFalseWhenTheResponseIsA500ThenA200 () {
266+ public void unreliableReturnsFalseWhenTheResponseIsA500ThenA200 () throws IOException {
281267 final RemoteControlProxy proxy ;
282268 final Response badResponse ;
283269 final Response successfulResponse ;
284- final Mock client ;
285270
286- client = mock (HttpClient .class );
271+ HttpClient client = mock (HttpClient .class );
287272 badResponse = new Response (500 , "" );
288273 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 );
290275 proxy = new RemoteControlProxy ("foo" , 10 , "" , (HttpClient ) client );
276+ proxy .registerNewSession ();
291277 assertFalse (proxy .unreliable ());
292-
293- verifyMocks ();
294278 }
279+
295280}
0 commit comments