### Question:
AttributeEqualsCondition extends Condition<WebElement> { @Override public boolean apply(final WebElement element) { try { String attributeValue = element.getAttribute(attribute); return attributeValue != null && attributeValue.equals(value); } catch (NullPointerException | WebDriverException e) { return false; } } AttributeEqualsCondition(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 shouldMatchConditionWhenAttributeEqualsValue() { when(mockElement.getAttribute("class")).thenReturn("active"); AttributeEqualsCondition condition = new AttributeEqualsCondition("class", "active"); assertThat(condition.apply(mockElement), equalTo(true)); }
@Test public void shouldNotMatchConditionWhenAttributeDoesNotEqualValue() { when(mockElement.getAttribute("style")).thenReturn("display: none"); AttributeEqualsCondition condition = new AttributeEqualsCondition("style", "display: block"); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleNullReturn() { when(mockElement.getAttribute("class")).thenReturn(null); AttributeEqualsCondition condition = new AttributeEqualsCondition("class", "menu"); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleExceptionWhenElementHasStaleReference() { when(mockElement.getAttribute("class")).thenThrow(new StaleElementReferenceException("stale")); AttributeEqualsCondition condition = new AttributeEqualsCondition("class", "menu"); assertThat(condition.apply(mockElement), equalTo(false)); }