### Question:
TextContainsCondition extends Condition<WebElement> { @Override public boolean apply(final WebElement element) { try { final String elementText = StringNormaliser.normalise(webElementConverter.getTextFrom(element)); for (String text : texts) { if (ignoreCase ? !StringUtils.containsIgnoreCase(elementText, text) : !elementText.contains(text)) return false; } return true; } catch (NullPointerException | WebDriverException e) { return false; } } TextContainsCondition(final String... texts);  TextContainsCondition(final boolean ignoreCase, final String... texts);   TextContainsCondition(final WebElementConverter webElementConverter, final boolean ignoreCase, final String... texts); @Override boolean apply(final WebElement element); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void shouldMatchConditionWhenTextContainsValues() { when(mockWebElementConverter.getTextFrom(mockElement)).thenReturn("Some text 1"); TextContainsCondition condition = new TextContainsCondition(mockWebElementConverter, false, "text", "Some"); assertThat(condition.apply(mockElement), equalTo(true)); }
@Test public void shouldMatchConditionIgnoringCaseWhenTextContainsValues() { when(mockWebElementConverter.getTextFrom(mockElement)).thenReturn("Some TEXt 1"); TextContainsCondition condition = new TextContainsCondition(mockWebElementConverter, true, "text", "SOME"); assertThat(condition.apply(mockElement), equalTo(true)); }
@Test public void shouldNotMatchConditionWhenTextDoesNotContainValue() { when(mockWebElementConverter.getTextFrom(mockElement)).thenReturn("Some tsxt 1"); TextContainsCondition condition = new TextContainsCondition(mockWebElementConverter, false, "text"); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleNullReturn() { when(mockWebElementConverter.getTextFrom(mockElement)).thenReturn(null); TextContainsCondition condition = new TextContainsCondition(mockWebElementConverter, false, "text"); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleExceptionWhenElementHasStaleReference() { when(mockWebElementConverter.getTextFrom(mockElement)).thenThrow(new StaleElementReferenceException("stale")); TextContainsCondition condition = new TextContainsCondition(mockWebElementConverter, false, "text"); assertThat(condition.apply(mockElement), equalTo(false)); }