### Question:
CinnamonExpectedConditions { public static Function<SearchContext, List<WebElement>> conditionOfAllElementsLocated(final By by, final Condition<WebElement> condition) { return context -> { try { final List<WebElement> elements = Lists.newArrayList(Iterables.filter(context.findElements(by), condition)); return elements.isEmpty() ? null : elements; } 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 conditionsOfAllElementsLocatedReturnsWebElements() { List<WebElement> webElements = Lists.newArrayList(mockElement); when(mockDriver.findElements(By.id("someid"))).thenReturn(webElements); when(mockCondition.apply(mockElement)).thenReturn(true); List<WebElement> allElementsLocated = wait.until(CinnamonExpectedConditions.conditionOfAllElementsLocated(By.id("someid"), mockCondition)); assertEquals(webElements, allElementsLocated); }
@Test public void conditionsOfAllElementsLocatedThrowsTimeoutExceptionWhenNoElementsFound() throws InterruptedException { 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.conditionOfAllElementsLocated(By.id("someid"), mockCondition)); }
@Test public void conditionsOfAllElementsLocatedThrowsTimeoutExceptionWhenNoElementsMatchCondition() { 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.conditionOfAllElementsLocated(By.id("someid"), mockCondition)); }