### Question:
AndCondition extends Condition<T> { @Override public boolean apply(final T t) { try { for (final Condition<T> condition : conditions) { if (!condition.apply(t)) return false; } return true; } catch (Exception e) { return false; } } @SafeVarargs  AndCondition(final Condition<T>... conditions); @Override boolean apply(final T t); @Override String toString();  }### Answer:
@Test public void shouldMatchConditionWhenAllConditionsAreMet() { when(mockElement.getAttribute("class")).thenReturn("menu active"); when(mockElement.isDisplayed()).thenReturn(true); when(mockElement.isEnabled()).thenReturn(true); AndCondition<WebElement> condition = displayed.and(enabled).and(attributeContains("class", "active")); assertThat(condition.apply(mockElement), equalTo(true)); }
@Test public void shouldNotMatchConditionWhenAtLeastOneConditionIsNotMet() { when(mockElement.getAttribute("class")).thenReturn("menu disabled"); when(mockElement.isDisplayed()).thenReturn(true); when(mockElement.isEnabled()).thenReturn(true); AndCondition<WebElement> condition = displayed.and(enabled).and(attributeContains("class", "active")); assertThat(condition.apply(mockElement), equalTo(false)); }