### Question:
CinnamonExpectedConditions { public static Function<SearchContext, WebElement> conditionOfElementLocated(final By by, final Condition<WebElement> condition) { return context -> { try { final List<WebElement> foundElements = context.findElements(by); for (final WebElement element : foundElements) { if (condition.apply(element)) { return element; } } return null; } catch (final WebDriverException e) { return null; } }; }  static ExpectedCondition<Boolean> conditionToBe(final Condition<WebDriver> condition); static Function<SearchContext, List<WebElement>> conditionOfAllElementsLocated(final By by, final Condition<WebElement> condition); static Function<SearchContext, WebElement> conditionOfElementLocated(final By by, final Condition<WebElement> condition); static Function<SearchContext, Boolean> elementCountToBe(final By by, final Condition<WebElement> condition, final int count); static ExpectedCondition<WebDriver> windowToBeAvailableAndSwitchToIt(final int zeroBasedIndex); static ExpectedCondition<WebDriver> windowToBeAvailableAndSwitchToIt(final String title); static ExpectedCondition<WebDriver> windowToBeAvailableAndSwitchToIt(final String title, final boolean partial);  }### Answer:
@Test public void conditionsOfElementLocatedReturnsWebElement() { List<WebElement> webElements = Lists.newArrayList(mockElement); when(mockDriver.findElements(By.id("someid"))).thenReturn(webElements); when(mockCondition.apply(mockElement)).thenReturn(true); WebElement elementLocated = wait.until(CinnamonExpectedConditions.conditionOfElementLocated(By.id("someid"), mockCondition)); assertEquals(mockElement, elementLocated); }
@Test public void conditionsOfElementLocatedThrowsTimeoutExceptionWhenNoElementsFound() { expectedException.expect(TimeoutException.class); expectedException.expectMessage("tried for 5 second"); List<WebElement> webElements = Lists.newArrayList(); when(mockDriver.findElements(By.id("someid"))).thenReturn(webElements); wait.until(CinnamonExpectedConditions.conditionOfElementLocated(By.id("someid"), mockCondition)); }
@Test public void conditionsOfElementLocatedThrowsTimeoutExceptionWhenNoElementsMatchCondition() { expectedException.expect(TimeoutException.class); expectedException.expectMessage("tried for 5 second"); List<WebElement> webElements = Lists.newArrayList(mockElement); when(mockDriver.findElements(By.id("someid"))).thenReturn(webElements); when(mockCondition.apply(mockElement)).thenReturn(false); wait.until(CinnamonExpectedConditions.conditionOfElementLocated(By.id("someid"), mockCondition)); }