### Question:
CssPropertyMatchesCondition extends Condition<WebElement> { @Override public boolean apply(final WebElement element) { try { String cssValue = element.getCssValue(cssProperty); Pattern pattern = flags == 0x00 ? Pattern.compile(regex) : Pattern.compile(regex, flags); Matcher matcher = pattern.matcher(cssValue); return matcher.matches(); } catch (NullPointerException | PatternSyntaxException | WebDriverException e) { return false; } } CssPropertyMatchesCondition(final String cssProperty, final String regex);  CssPropertyMatchesCondition(final String cssProperty, final String regex, final int flags); @Override boolean apply(final WebElement element); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void shouldMatchConditionWhenCssPropertyMatchesRegex() { when(mockElement.getCssValue("color")).thenReturn("rgba(68, 68, 68, 1)"); CssPropertyMatchesCondition condition = new CssPropertyMatchesCondition("color", "^rgba\\((.*)\\)$"); assertThat(condition.apply(mockElement), equalTo(true)); }
@Test public void shouldNotMatchConditionWhenCssPropertyDoesNotMatchRegex() { when(mockElement.getCssValue("color")).thenReturn("rgba(68, 68, 68, 1)"); CssPropertyMatchesCondition condition = new CssPropertyMatchesCondition("color", "^rgb\\((.*)\\)$"); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleNullReturn() { when(mockElement.getCssValue("color")).thenReturn(null); CssPropertyEqualsCondition condition = new CssPropertyEqualsCondition("color", "^rgba\\((.*)\\)$"); assertThat(condition.apply(mockElement), equalTo(false)); }
@Test public void shouldHandleExceptionWhenElementHasStaleReference() { when(mockElement.getCssValue("color")).thenThrow(new StaleElementReferenceException("stale")); CssPropertyEqualsCondition condition = new CssPropertyEqualsCondition("color", "^rgba\\((.*)\\)$"); assertThat(condition.apply(mockElement), equalTo(false)); }