2626import static org .easymock .EasyMock .expect ;
2727import static org .easymock .EasyMock .verify ;
2828import static org .junit .Assert .assertEquals ;
29+ import static org .junit .Assert .assertFalse ;
2930import static org .junit .Assert .assertNotNull ;
3031import static org .junit .Assert .assertTrue ;
3132import static org .junit .Assert .fail ;
@@ -176,6 +177,7 @@ public void testLaunchWithBinaryAndArgumentsAndDefaultUserDataDir()
176177
177178 final String trigger = "\r \n \r \n DevTools listening on ws://127.0.0.1:9123/" ;
178179 expect (process .getInputStream ()).andReturn (new ByteArrayInputStream (trigger .getBytes ()));
180+ expect (process .isAlive ()).andReturn (true );
179181
180182 Capture <List <String >> captureArguments = Capture .newInstance ();
181183 expect (processLauncher .launch (eq ("test-binary-path" ), capture (captureArguments )))
@@ -188,7 +190,6 @@ public void testLaunchWithBinaryAndArgumentsAndDefaultUserDataDir()
188190
189191 ChromeService launch = launcher .launch (binaryPath , chromeArguments );
190192
191- verifyAll ();
192193 PowerMock .verify (FilesUtils .class );
193194
194195 assertNotNull (launch );
@@ -213,12 +214,16 @@ public void testLaunchWithBinaryAndArgumentsAndDefaultUserDataDir()
213214 // Ignore this exception.
214215 }
215216
217+ verifyAll ();
218+
216219 // Test closing
217220 resetAll ();
218221 PowerMock .resetAll (FilesUtils .class );
219222
220223 process .destroy ();
221224 expect (process .waitFor (60 , TimeUnit .SECONDS )).andReturn (true );
225+ expect (process .isAlive ()).andReturn (true );
226+ expect (process .isAlive ()).andReturn (false );
222227
223228 shutdownHookRegistry .remove (anyObject ());
224229
@@ -260,13 +265,12 @@ public void testLaunchWithBinaryAndArgumentsAndCustomUserDataDir()
260265 Capture <List <String >> captureArguments = Capture .newInstance ();
261266 expect (processLauncher .launch (eq ("test-binary-path" ), capture (captureArguments )))
262267 .andReturn (process );
268+ expect (process .isAlive ()).andReturn (true );
263269
264270 replayAll ();
265271
266272 ChromeService launch = launcher .launch (binaryPath , chromeArguments );
267273
268- verifyAll ();
269-
270274 assertNotNull (launch );
271275 assertTrue (launch instanceof ChromeServiceImpl );
272276
@@ -289,12 +293,17 @@ public void testLaunchWithBinaryAndArgumentsAndCustomUserDataDir()
289293 // Ignore this exception.
290294 }
291295
296+ verifyAll ();
297+
292298 // Test closing
293299 resetAll ();
294300
295301 process .destroy ();
296302 expect (process .waitFor (60 , TimeUnit .SECONDS )).andReturn (true );
297303
304+ expect (process .isAlive ()).andReturn (true );
305+ expect (process .isAlive ()).andReturn (false );
306+
298307 shutdownHookRegistry .remove (anyObject ());
299308
300309 FilesUtils .deleteQuietly (null );
@@ -321,6 +330,7 @@ public void testLaunchWithBinaryAndArgumentsAndCloseWithInterruptedException()
321330
322331 final String trigger = "\r \n \r \n DevTools listening on ws://127.0.0.1:9123/" ;
323332 expect (process .getInputStream ()).andReturn (new ByteArrayInputStream (trigger .getBytes ()));
333+ expect (process .isAlive ()).andReturn (true );
324334
325335 Capture <List <String >> captureArguments = Capture .newInstance ();
326336 expect (processLauncher .launch (eq ("test-binary-path" ), capture (captureArguments )))
@@ -330,8 +340,6 @@ public void testLaunchWithBinaryAndArgumentsAndCloseWithInterruptedException()
330340
331341 ChromeService launch = launcher .launch (binaryPath , chromeArguments );
332342
333- verifyAll ();
334-
335343 assertNotNull (launch );
336344 assertTrue (launch instanceof ChromeServiceImpl );
337345
@@ -352,6 +360,8 @@ public void testLaunchWithBinaryAndArgumentsAndCloseWithInterruptedException()
352360 // Ignore this exception.
353361 }
354362
363+ verifyAll ();
364+
355365 // Test closing
356366 resetAll ();
357367
@@ -360,6 +370,8 @@ public void testLaunchWithBinaryAndArgumentsAndCloseWithInterruptedException()
360370
361371 expect (process .destroyForcibly ()).andReturn (process );
362372
373+ expect (process .isAlive ()).andReturn (true );
374+
363375 shutdownHookRegistry .remove (anyObject ());
364376
365377 FilesUtils .deleteQuietly (null );
@@ -446,6 +458,7 @@ public void testLaunchWithBinaryAndArgumentsFailsOnReading()
446458 expect (processLauncher .isExecutable ("/test-binary-path" )).andReturn (true );
447459
448460 expect (process .getInputStream ()).andThrow (new RuntimeException ("test exception" ));
461+ expect (process .isAlive ()).andReturn (true );
449462
450463 Capture <List <String >> captureArguments = Capture .newInstance ();
451464 expect (processLauncher .launch (eq ("/test-binary-path" ), capture (captureArguments )))
@@ -479,6 +492,7 @@ public void testLaunchWithBinaryAndArgumentsThrowsExceptionOnTimeout()
479492
480493 final String trigger = "test\r \n test" ;
481494 expect (process .getInputStream ()).andReturn (new ByteArrayInputStream (trigger .getBytes ()));
495+ expect (process .isAlive ()).andReturn (true );
482496
483497 Capture <List <String >> captureArguments = Capture .newInstance ();
484498 expect (processLauncher .launch (eq ("test-binary-path" ), capture (captureArguments )))
@@ -527,6 +541,7 @@ public void testLaunchWithBinaryAndArgumentsThrowsExceptionOnTimeoutForciblyClos
527541
528542 final String trigger = "test\r \n \r \n " ;
529543 expect (process .getInputStream ()).andReturn (new ByteArrayInputStream (trigger .getBytes ()));
544+ expect (process .isAlive ()).andReturn (true );
530545
531546 Capture <List <String >> captureArguments = Capture .newInstance ();
532547 expect (processLauncher .launch (eq ("test-binary-path" ), capture (captureArguments )))
@@ -559,6 +574,67 @@ public void testLaunchWithBinaryAndArgumentsThrowsExceptionOnTimeoutForciblyClos
559574 assertEquals (removeCaptureShutdownThread .getValue (), addCaptureShutdownThread .getValue ());
560575 }
561576
577+ @ Test
578+ public void testIsAlive () throws IOException {
579+ assertFalse (launcher .isAlive ());
580+
581+ final Path binaryPath = Paths .get ("test-binary-path" );
582+
583+ final ChromeArguments chromeArguments =
584+ ChromeArguments .builder ().incognito ().userDataDir ("user-data-dir-param" ).build ();
585+
586+ shutdownHookRegistry .register (anyObject ());
587+
588+ final String trigger = "\r \n \r \n DevTools listening on ws://127.0.0.1:9123/" ;
589+ expect (process .getInputStream ()).andReturn (new ByteArrayInputStream (trigger .getBytes ()));
590+
591+ expect (process .isAlive ()).andReturn (true );
592+
593+ Capture <List <String >> captureArguments = Capture .newInstance ();
594+ expect (processLauncher .launch (eq ("test-binary-path" ), capture (captureArguments )))
595+ .andReturn (process );
596+
597+ replayAll ();
598+
599+ launcher .launch (binaryPath , chromeArguments );
600+
601+ assertTrue (launcher .isAlive ());
602+
603+ verifyAll ();
604+ }
605+
606+ @ Test (expected = IllegalStateException .class )
607+ public void testExitValueThrowsExceptionWhenProcessNotStarted () throws IOException {
608+ launcher .exitValue ();
609+ }
610+
611+ @ Test
612+ public void testExitValue () throws IOException {
613+ final Path binaryPath = Paths .get ("test-binary-path" );
614+
615+ final ChromeArguments chromeArguments =
616+ ChromeArguments .builder ().incognito ().userDataDir ("user-data-dir-param" ).build ();
617+
618+ shutdownHookRegistry .register (anyObject ());
619+
620+ final String trigger = "\r \n \r \n DevTools listening on ws://127.0.0.1:9123/" ;
621+ expect (process .getInputStream ()).andReturn (new ByteArrayInputStream (trigger .getBytes ()));
622+
623+ expect (process .exitValue ()).andReturn (123 );
624+
625+ Capture <List <String >> captureArguments = Capture .newInstance ();
626+ expect (processLauncher .launch (eq ("test-binary-path" ), capture (captureArguments )))
627+ .andReturn (process );
628+
629+ replayAll ();
630+
631+ launcher .launch (binaryPath , chromeArguments );
632+
633+ assertEquals (123 , launcher .exitValue ());
634+
635+ verifyAll ();
636+ }
637+
562638 private static void assertUserDataDir (List <String > arguments ) {
563639 boolean hasUserDataDir = false ;
564640 for (String argument : arguments ) {
0 commit comments