### Question:
TextEqualsCondition extends Condition<WebElement> { @Override public boolean apply(WebElement element) { try { final String elementText = StringNormaliser.normalise(webElementConverter.getTextFrom(element)); return ignoreCase ? elementText.equalsIgnoreCase(text) : elementText.equals(text); } catch (NullPointerException | WebDriverException e) { return false; } } TextEqualsCondition(final String text);  TextEqualsCondition(final boolean ignoreCase, final String text);   TextEqualsCondition(final WebElementConverter webElementConverter, final boolean ignoreCase, final String text); @Override boolean apply(WebElement element); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void shouldMatchConditionWhenTextEqualsValue() { when(mockWebElementConverter.getTextFrom(mockElement)).thenReturn("Test 1"); TextEqualsCondition condition = new TextEqualsCondition(mockWebElementConverter, false, "Test 1"); assertThat(condition.apply(mockElement), equalTo(true)); }
@Test public void shouldMatchConditionIgnoringCaseWhenTextEqualsValue() { when(mockWebElementConverter.getTextFrom(mockElement)).thenReturn("TEST 1"); TextEqualsCondition condition = new TextEqualsCondition(mockWebElementConverter, true, "Test 1"); assertThat(condition.apply(mockElement), equalTo(true)); }
@Test public void shouldNotMatchConditionWhenTextDoesNotEqualValue() { when(mockWebElementConverter.getTextFrom(mockElement)).thenReturn("Test 2"); TextEqualsCondition condition = new TextEqualsCondition(mockWebElementConverter, false, "Test 1"); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleNullReturn() { when(mockWebElementConverter.getTextFrom(mockElement)).thenReturn(null); TextEqualsCondition condition = new TextEqualsCondition(mockWebElementConverter, false, "some text"); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleExceptionWhenElementHasStaleReference() { when(mockWebElementConverter.getTextFrom(mockElement)).thenThrow(new StaleElementReferenceException("stale")); TextEqualsCondition condition = new TextEqualsCondition(mockWebElementConverter, false, "some text"); assertThat(condition.apply(mockElement), equalTo(false)); }