### Question:
FluentDriverWrappedCapabilitiesProvider { public Capabilities getCapabilities(WebDriver driver) { WebDriver currentDriver = driver; Capabilities capabilities = capabilitiesOf(currentDriver); while (currentDriver instanceof WrapsDriver && capabilities == null) { currentDriver = ((WrapsDriver) currentDriver).getWrappedDriver(); capabilities = capabilitiesOf(currentDriver); } return capabilities; }  Capabilities getCapabilities(WebDriver driver);  }### Answer:
@Test public void shouldReturnInnerMostWrappedDriverCapabilities() { when(((WrapsDriver) webDriverNotHaveCapabilities).getWrappedDriver()).thenReturn(webDriverHasCapabilities); when(((HasCapabilities) webDriverHasCapabilities).getCapabilities()).thenReturn(wrappedCapabilities); Capabilities capabilities = capabilitiesProvider.getCapabilities(webDriverNotHaveCapabilities); assertThat(capabilities).isSameAs(wrappedCapabilities); }