EventFiringWebDriver extends DecoratedWebDriver { public void removeListener(WebDriverListener listener) { listeners.remove(listener); } EventFiringWebDriver(final WebDriver driver); void addListener(WebDriverListener listener); void removeListener(WebDriverListener listener); void removeAllListeners(); @Override void beforeMethodGlobal(Decorated<?> target, Method method, Object[] args); @Override void afterMethodGlobal(Decorated<?> target, Method method, Object res, Object[] args);  }
@Test void shouldNotFireToRemovedListener() { Fixture fixture = new Fixture(); fixture.decoratedDriver.removeListener(fixture.listener); fixture.driver.get("http: verify(fixture.mockedDriver, times(1)).get("http: verifyZeroInteractions(fixture.listener); }
@Test void canRemoveASingleListener() { Fixture fixture = new Fixture(); fixture.decoratedDriver.removeListener(fixture.listener); fixture.driver.get("http: verify(fixture.mockedDriver, times(1)).get("http: verifyZeroInteractions(fixture.listener); verify(fixture.listener2, times(1)).beforeGet(fixture.mockedDriver, "http: verify(fixture.listener2, times(1)).afterGet(fixture.mockedDriver, "http: }