### Question:
DisplayedCondition extends Condition<WebElement> { @Override public boolean apply(final WebElement element) { try { return element.isDisplayed(); } catch (NullPointerException | WebDriverException e) { return false; } }  @Override boolean apply(final WebElement element); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void shouldMatchConditionWhenElementIsDisplayed() { when(mockElement.isDisplayed()).thenReturn(true); DisplayedCondition condition = new DisplayedCondition(); assertThat(condition.apply(mockElement), equalTo(true)); }
@Test public void shouldNotMatchConditionWhenElementIsNotDisplayed() { when(mockElement.isDisplayed()).thenReturn(false); DisplayedCondition condition = new DisplayedCondition(); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleExceptionWhenElementIsNull() { when(mockElement.isDisplayed()).thenThrow(new NullPointerException()); DisplayedCondition condition = new DisplayedCondition(); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleExceptionWhenElementHasStaleReference() { when(mockElement.isDisplayed()).thenThrow(new StaleElementReferenceException("stale")); DisplayedCondition condition = new DisplayedCondition(); assertThat(condition.apply(mockElement), equalTo(false)); }