类 IsCollectionContaining<T>

    • 方法详细资料

      • describeTo

        public void describeTo​(Description description)
        从接口复制的说明: SelfDescribing
        Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.
        参数:
        description - The description to be built or appended to.
      • hasItem

        public static <T> Matcher<Iterable<? super T>> hasItem​(Matcher<? super T> itemMatcher)
        Creates a matcher for Iterables that only matches when a single pass over the examined Iterable yields at least one item that is matched by the specified itemMatcher. Whilst matching, the traversal of the examined Iterable will stop as soon as a matching item is found.

        For example:

        assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))
        参数:
        itemMatcher - the matcher to apply to items provided by the examined Iterable
      • hasItem

        public static <T> Matcher<Iterable<? super T>> hasItem​(T item)
        Creates a matcher for Iterables that only matches when a single pass over the examined Iterable yields at least one item that is equal to the specified item. Whilst matching, the traversal of the examined Iterable will stop as soon as a matching item is found.

        For example:

        assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))
        参数:
        item - the item to compare against the items provided by the examined Iterable
      • hasItems

        public static <T> Matcher<Iterable<T>> hasItems​(Matcher<? super T>... itemMatchers)
        Creates a matcher for Iterables that matches when consecutive passes over the examined Iterable yield at least one item that is matched by the corresponding matcher from the specified itemMatchers. Whilst matching, each traversal of the examined Iterable will stop as soon as a matching item is found.

        For example:

        assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))
        参数:
        itemMatchers - the matchers to apply to items provided by the examined Iterable
      • hasItems

        public static <T> Matcher<Iterable<T>> hasItems​(T... items)
        Creates a matcher for Iterables that matches when consecutive passes over the examined Iterable yield at least one item that is equal to the corresponding item from the specified items. Whilst matching, each traversal of the examined Iterable will stop as soon as a matching item is found.

        For example:

        assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))
        参数:
        items - the items to compare against the items provided by the examined Iterable