CustomMatchers { public static Matcher<Path> isSelectedIn(final InBrowser browser) { return new TypeSafeMatcher<Path>() { private Path el; @Override public void describeTo(final Description description) { description.appendText(el + " is selected"); } @Override protected void describeMismatchSafely(final Path el, final Description mismatchDescription) { mismatchDescription.appendText(el + " is not selected"); } @Override protected boolean matchesSafely(final Path el) { this.el = el; return browser.isSelected(el); } }; }  static Matcher<InBrowser> hasElement(final Path el); static IsPresentNTimes isPresent(int nTimes); static IsPresent isPresent(); static HasText hasText(String text); static HasElements hasElements(Path path); static Matcher<Path> isPresentIn(final InBrowser browser); static Matcher<Path> isPresentIn(final Document document); static Matcher<Path> isDisplayedIn(final InBrowser browser); static Matcher<Path> isNotDisplayedIn(final InBrowser browser); static Matcher<Path> isSelectedIn(final InBrowser browser); static Matcher<Path> isEnabledIn(final InBrowser browser); static Matcher<InBrowser> hasNoElement(final Path el); static Matcher<Path> isAbsentFrom(final InBrowser browser); static Matcher<Path> isAbsentFrom(final Document document);  }
@Test public void isSelecteddFailed() { when(browser.isSelected(div)).thenReturn(false); try { assertThat(div, CustomMatchers.isSelectedIn(browser)); fail("should fail"); } catch (AssertionError e) { assertThat(e.getMessage(), is(equalTo("\nExpected: div is selected\n but: div is not selected"))); } }