### Question:
AttributeContainsCondition extends Condition<WebElement> { @Override public boolean apply(final WebElement element) { try { String attributeValue = element.getAttribute(attribute); return attributeValue != null && attributeValue.contains(value); } catch (NullPointerException | WebDriverException e) { return false; } } AttributeContainsCondition(final String attribute, final String value); @Override boolean apply(final WebElement element); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void shouldMatchConditionWhenAttributeContainsValue() { when(mockElement.getAttribute("class")).thenReturn("menu active"); AttributeContainsCondition condition = new AttributeContainsCondition("class", "active"); assertThat(condition.apply(mockElement), equalTo(true)); }
@Test public void shouldNotMatchConditionWhenAttributeDoesNotContainValue() { when(mockElement.getAttribute("style")).thenReturn("display: none"); AttributeContainsCondition condition = new AttributeContainsCondition("style", "block"); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleNullReturn() { when(mockElement.getAttribute("class")).thenReturn(null); AttributeContainsCondition condition = new AttributeContainsCondition("class", "hidden"); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleExceptionWhenElementHasStaleReference() { when(mockElement.getAttribute("class")).thenThrow(new StaleElementReferenceException("stale")); AttributeContainsCondition condition = new AttributeContainsCondition("class", "active"); assertThat(condition.apply(mockElement), equalTo(false)); }