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