### Question:
HasCookieMatcher extends TypeSafeMatcher<WebDriver> { @Factory public static Matcher<WebDriver> hasCookie(String name) { return new HasCookieMatcher(name); } protected  HasCookieMatcher(String name); @Override void describeTo(Description description); @Factory static Matcher<WebDriver> hasCookie(String name);  }### Answer:
@Test public void shouldFindExistingCookie() { WebDriver driver = mock(WebDriver.class); Options options = mock(Options.class); Cookie cookie = new Cookie(cookieName, "oki-doki"); when(driver.manage()).thenReturn(options); when(options.getCookieNamed(eq(cookieName))).thenReturn(cookie); assertThat("Cookie not found!", driver, hasCookie(cookieName)); }
@Test public void shouldNotFindUnexistingCookie() { final WebDriver driver = mock(WebDriver.class); Options options = mock(Options.class); when(driver.manage()).thenReturn(options); when(options.getCookieNamed(eq(cookieName))).thenReturn(null); assertThat("Cook should not be found", driver, not(hasCookie(cookieName))); }