### Question:
SelectedCondition extends Condition<WebElement> { @Override public boolean apply(final WebElement element) { try { return element.isSelected(); } 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 shouldMatchConditionWhenElementIsSelected() { when(mockElement.isSelected()).thenReturn(true); SelectedCondition condition = new SelectedCondition(); assertThat(condition.apply(mockElement), equalTo(true)); }
@Test public void shouldNotMatchConditionWhenElementIsNotSelected() { when(mockElement.isSelected()).thenReturn(false); SelectedCondition condition = new SelectedCondition(); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleExceptionWhenElementIsNull() { when(mockElement.isSelected()).thenThrow(new NullPointerException()); SelectedCondition condition = new SelectedCondition(); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleExceptionWhenElementHasStaleReference() { when(mockElement.isSelected()).thenThrow(new StaleElementReferenceException("stale")); SelectedCondition condition = new SelectedCondition(); assertThat(condition.apply(mockElement), equalTo(false)); }