Class IterableSubject<S extends IterableSubject<S,​T,​C>,​T,​C extends java.lang.Iterable<T>>

  • Direct Known Subclasses:
    CollectionSubject

    public class IterableSubject<S extends IterableSubject<S,​T,​C>,​T,​C extends java.lang.Iterable<T>>
    extends Subject<S,​C>
    Propositions for Iterable subjects.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  IterableSubject.NotInOrder
      Ordered implementation that always fails.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static Ordered IN_ORDER
      Ordered implementation that does nothing because it's already known to be true.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void contains​(java.lang.Object element)
      Attests (with a side-effect failure) that the subject contains the supplied item.
      private void contains​(java.lang.String failVerb, java.lang.Iterable<?> expected)  
      private Ordered containsAll​(java.lang.String failVerb, java.lang.Iterable<?> expected)  
      Ordered containsAllIn​(java.lang.Iterable<?> expected)
      Attests that the subject contains at least all of the provided objects or fails, potentially permitting duplicates in both the subject and the parameters (if the subject even can have duplicates).
      Ordered containsAllOf​(java.lang.Object first, java.lang.Object second, java.lang.Object... rest)
      Attests that the subject contains at least all of the provided objects or fails, potentially permitting duplicates in both the subject and the parameters (if the subject even can have duplicates).
      void containsAnyIn​(java.lang.Iterable<?> expected)
      Attests that a Collection contains at least one of the objects contained in the provided collection or fails.
      void containsAnyOf​(java.lang.Object first, java.lang.Object second, java.lang.Object... rest)
      Attests that the subject contains at least one of the provided objects or fails.
      Ordered containsExactly​(java.lang.Object... varargs)
      Attests that a subject contains all of the provided objects and only these objects or fails, potentially permitting duplicates in both the subject and the parameters (if the subject even can have duplicates).
      private Ordered containsExactly​(java.lang.String failVerb, java.lang.Iterable<?> required)  
      Ordered containsExactlyElementsIn​(java.lang.Iterable<?> expected)
      Attests that a subject contains all of the provided objects and only these objects or fails, potentially permitting duplicates in both the subject and the parameters (if the subject even can have duplicates).
      void containsNoDuplicates()
      Attests that the subject does not contain duplicate elements.
      private void containsNone​(java.lang.String failVerb, java.lang.Iterable<?> excluded)  
      void containsNoneIn​(java.lang.Iterable<?> excluded)
      Attests that a Collection contains none of the objects contained in the provided collection or fails, eliding duplicates.
      void containsNoneOf​(java.lang.Object first, java.lang.Object second, java.lang.Object... rest)
      Attests that a subject contains none of the provided objects or fails, eliding duplicates.
      Ordered containsOnlyElements​(java.lang.Object first, java.lang.Object second, java.lang.Object... rest)
      Deprecated.
      Ordered containsOnlyElementsIn​(java.lang.Iterable<?> expected)
      Deprecated.
      (package private) static <T,​C extends java.lang.Iterable<T>>
      IterableSubject<? extends IterableSubject<?,​T,​C>,​T,​C>
      create​(FailureStrategy failureStrategy, java.lang.Iterable<T> list)  
      void doesNotContain​(java.lang.Object element)
      Attests (with a side-effect failure) that the subject does not contain the supplied item.
      void hasSize​(int expectedSize)
      Fails if the subject does not have the given size.
      void isEmpty()
      Fails if the subject is not empty.
      void isNotEmpty()
      Fails if the subject is empty.
      void iteratesAs​(java.lang.Iterable<?> expectedItems)
      Asserts that the items are supplied in the order given by the iterable.
      void iteratesAs​(java.lang.Object... expectedItems)
      Asserts that the items are supplied in the order given by the iterable.
      void iteratesOverSequence​(java.lang.Object... expectedItems)
      Deprecated.
      Use containsExactly(Object, Object...).inOrder() instead.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • IN_ORDER

        private static final Ordered IN_ORDER
        Ordered implementation that does nothing because it's already known to be true.
    • Constructor Detail

    • Method Detail

      • isEmpty

        public void isEmpty()
        Fails if the subject is not empty.
      • isNotEmpty

        public void isNotEmpty()
        Fails if the subject is empty.
      • hasSize

        public final void hasSize​(int expectedSize)
        Fails if the subject does not have the given size.
      • iteratesAs

        public void iteratesAs​(java.lang.Iterable<?> expectedItems)
        Asserts that the items are supplied in the order given by the iterable. If the iterable under test and/or the expectedItems do not provide iteration order guarantees (say, Set<?>s), this method may provide unexpected results. Consider using Subject.isEqualTo(Object) in such cases, or using collections and iterables that provide strong order guarantees.
      • iteratesOverSequence

        @Deprecated
        public void iteratesOverSequence​(java.lang.Object... expectedItems)
        Deprecated.
        Use containsExactly(Object, Object...).inOrder() instead.
      • iteratesAs

        public void iteratesAs​(java.lang.Object... expectedItems)
        Asserts that the items are supplied in the order given by the iterable. If the iterable under test does not provide iteration order guarantees (say, a Set<?>), this method is not suitable for asserting that order. Consider using Subject.isEqualTo(Object)
      • contains

        public void contains​(@Nullable
                             java.lang.Object element)
        Attests (with a side-effect failure) that the subject contains the supplied item.
      • doesNotContain

        public void doesNotContain​(@Nullable
                                   java.lang.Object element)
        Attests (with a side-effect failure) that the subject does not contain the supplied item.
      • containsNoDuplicates

        public void containsNoDuplicates()
        Attests that the subject does not contain duplicate elements.
      • containsAnyOf

        public void containsAnyOf​(@Nullable
                                  java.lang.Object first,
                                  @Nullable
                                  java.lang.Object second,
                                  java.lang.Object... rest)
        Attests that the subject contains at least one of the provided objects or fails.
      • containsAnyIn

        public void containsAnyIn​(java.lang.Iterable<?> expected)
        Attests that a Collection contains at least one of the objects contained in the provided collection or fails.
      • contains

        private void contains​(java.lang.String failVerb,
                              java.lang.Iterable<?> expected)
      • containsAllOf

        public Ordered containsAllOf​(@Nullable
                                     java.lang.Object first,
                                     @Nullable
                                     java.lang.Object second,
                                     java.lang.Object... rest)
        Attests that the subject contains at least all of the provided objects or fails, potentially permitting duplicates in both the subject and the parameters (if the subject even can have duplicates).

        Callers may optionally chain an inOrder() call if its expected contents must be contained in the given order.

      • containsAllIn

        public Ordered containsAllIn​(java.lang.Iterable<?> expected)
        Attests that the subject contains at least all of the provided objects or fails, potentially permitting duplicates in both the subject and the parameters (if the subject even can have duplicates).

        Callers may optionally chain an inOrder() call if its expected contents must be contained in the given order.

      • containsAll

        private Ordered containsAll​(java.lang.String failVerb,
                                    java.lang.Iterable<?> expected)
      • containsOnlyElements

        @Deprecated
        public Ordered containsOnlyElements​(@Nullable
                                            java.lang.Object first,
                                            @Nullable
                                            java.lang.Object second,
                                            java.lang.Object... rest)
        Deprecated.
        Attests that a subject contains all of the provided objects and only these objects or fails, potentially permitting duplicates in both the subject and the parameters (if the subject even can have duplicates).

        Callers may optionally chain an inOrder() call if its expected contents must be contained in the given order.

      • containsOnlyElementsIn

        @Deprecated
        public Ordered containsOnlyElementsIn​(java.lang.Iterable<?> expected)
        Deprecated.
        Attests that a subject contains all of the provided objects and only these objects or fails, potentially permitting duplicates in both the subject and the parameters (if the subject even can have duplicates).

        Callers may optionally chain an inOrder() call if its expected contents must be contained in the given order.

      • containsExactly

        public Ordered containsExactly​(@Nullable
                                       java.lang.Object... varargs)
        Attests that a subject contains all of the provided objects and only these objects or fails, potentially permitting duplicates in both the subject and the parameters (if the subject even can have duplicates).

        Callers may optionally chain an inOrder() call if its expected contents must be contained in the given order.

      • containsExactlyElementsIn

        public Ordered containsExactlyElementsIn​(java.lang.Iterable<?> expected)
        Attests that a subject contains all of the provided objects and only these objects or fails, potentially permitting duplicates in both the subject and the parameters (if the subject even can have duplicates).

        Callers may optionally chain an inOrder() call if its expected contents must be contained in the given order.

      • containsExactly

        private Ordered containsExactly​(java.lang.String failVerb,
                                        java.lang.Iterable<?> required)
      • containsNoneOf

        public void containsNoneOf​(@Nullable
                                   java.lang.Object first,
                                   @Nullable
                                   java.lang.Object second,
                                   java.lang.Object... rest)
        Attests that a subject contains none of the provided objects or fails, eliding duplicates.
      • containsNoneIn

        public void containsNoneIn​(java.lang.Iterable<?> excluded)
        Attests that a Collection contains none of the objects contained in the provided collection or fails, eliding duplicates.
      • containsNone

        private void containsNone​(java.lang.String failVerb,
                                  java.lang.Iterable<?> excluded)