@Test public void shouldBeAbleToCallQuitBrowserMultipleTimes() throws Exception { ChromeDriver mockChromeDriver = mock(ChromeDriver.class); ChromeDriverService mockService = mock(ChromeDriverService.class); when(mockService.isRunning()).thenReturn(true); config.getServices().put(config.currentThreadName(), mockService); config.quitBrowser(mockChromeDriver); config.quitBrowser(mockChromeDriver); assertThat(config.getServices(), is(Collections.<String, ChromeDriverService>emptyMap())); verify(mockService, times(1)).stop(); }
@Test public void shouldNotStopServiceIfNotRunningWhenQuitBrowserIsInvoked() throws Exception { ChromeDriver mockChromeDriver = mock(ChromeDriver.class); ChromeDriverService mockService = mock(ChromeDriverService.class); when(mockService.isRunning()).thenReturn(false); config.getServices().put(config.currentThreadName(), mockService); config.quitBrowser(mockChromeDriver); verify(mockChromeDriver).quit(); assertThat(config.getServices(), is(Collections.<String, ChromeDriverService>emptyMap())); verify(mockService, times(0)).stop(); }