Class IterableAssert<ELEMENT>

    • Constructor Detail

      • IterableAssert

        public IterableAssert​(java.lang.Iterable<? extends ELEMENT> actual)
      • IterableAssert

        public IterableAssert​(java.util.Iterator<? extends ELEMENT> actual)
    • Method Detail

      • isEqualTo

        public IterableAssert<ELEMENT> isEqualTo​(java.lang.Object expected)
        Description copied from class: AbstractAssert
        Verifies that the actual value is equal to the given one.

        Example:

         // assertions will pass
         assertThat("abc").isEqualTo("abc");
         assertThat(new HashMap<String, Integer>()).isEqualTo(new HashMap<String, Integer>());
         
         // assertions will fail
         assertThat("abc").isEqualTo("123");
         assertThat(new ArrayList<String>()).isEqualTo(1);
        Specified by:
        isEqualTo in interface Assert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>>
        Overrides:
        isEqualTo in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        expected - the given value to compare the actual value to.
        Returns:
        this assertion object.
      • isInstanceOf

        public IterableAssert<ELEMENT> isInstanceOf​(java.lang.Class<?> type)
        Description copied from class: AbstractAssert
        Verifies that the actual value is an instance of the given type.

        Example:

         // assertions will pass
         assertThat("abc").isInstanceOf(String.class);
         assertThat(new HashMap<String, Integer>()).isInstanceOf(HashMap.class);
         assertThat(new HashMap<String, Integer>()).isInstanceOf(Map.class);
         
         // assertions will fail
         assertThat(1).isInstanceOf(String.class);
         assertThat(new ArrayList<String>()).isInstanceOf(LinkedList.class);
        Specified by:
        isInstanceOf in interface Assert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>>
        Overrides:
        isInstanceOf in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        type - the type to check the actual value against.
        Returns:
        this assertion object.
      • isInstanceOfAny

        public IterableAssert<ELEMENT> isInstanceOfAny​(java.lang.Class<?>... types)
        Description copied from class: AbstractAssert
        Verifies that the actual value is an instance of any of the given types.

        Example:

         // assertions will pass
         assertThat("abc").isInstanceOfAny(String.class, Integer.class);
         assertThat(new ArrayList<String>()).isInstanceOfAny(LinkedList.class, ArrayList.class);
         assertThat(new HashMap<String, Integer>()).isInstanceOfAny(TreeMap.class, Map.class);
         
         // assertions will fail
         assertThat(1).isInstanceOfAny(Double.class, Float.class);
         assertThat(new ArrayList<String>()).isInstanceOfAny(LinkedList.class, Vector.class);
        Specified by:
        isInstanceOfAny in interface Assert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>>
        Overrides:
        isInstanceOfAny in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        types - the types to check the actual value against.
        Returns:
        this assertion object.
      • isOfAnyClassIn

        public IterableAssert<ELEMENT> isOfAnyClassIn​(java.lang.Class<?>... types)
        Description copied from class: AbstractAssert
        Verifies that the actual value type is in given types.

        Example:

         // assertions will pass
         assertThat(new HashMap<String, Integer>()).isOfAnyClassIn(HashMap.class, TreeMap.class);
         assertThat(new ArrayList<String>()).isOfAnyClassIn(ArrayList.class, LinkedList.class);
         
         // assertions will fail
         assertThat(new HashMap<String, Integer>()).isOfAnyClassIn(TreeMap.class, Map.class);
         assertThat(new ArrayList<String>()).isOfAnyClassIn(LinkedList.class, List.class);
        Specified by:
        isOfAnyClassIn in interface Assert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>>
        Overrides:
        isOfAnyClassIn in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        types - the types to check the actual value against.
        Returns:
        this assertion object.
      • isExactlyInstanceOf

        public IterableAssert<ELEMENT> isExactlyInstanceOf​(java.lang.Class<?> type)
        Description copied from class: AbstractAssert
        Verifies that the actual value is exactly an instance of the given type.

        Example:

         // assertions will pass
         assertThat("abc").isExactlyInstanceOf(String.class);
         assertThat(new ArrayList<String>()).isExactlyInstanceOf(ArrayList.class);
         assertThat(new HashMap<String, Integer>()).isExactlyInstanceOf(HashMap.class);
         
         // assertions will fail
         assertThat(1).isExactlyInstanceOf(String.class);
         assertThat(new ArrayList<String>()).isExactlyInstanceOf(List.class);
         assertThat(new HashMap<String, Integer>()).isExactlyInstanceOf(Map.class);
        Specified by:
        isExactlyInstanceOf in interface Assert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>>
        Overrides:
        isExactlyInstanceOf in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        type - the type to check the actual value against.
        Returns:
        this assertion object.
      • isNotInstanceOf

        public IterableAssert<ELEMENT> isNotInstanceOf​(java.lang.Class<?> type)
        Description copied from class: AbstractAssert
        Verifies that the actual value is not an instance of the given type.

        Example:

         // assertions will pass
         assertThat(1).isNotInstanceOf(Double.class);
         assertThat(new ArrayList<String>()).isNotInstanceOf(LinkedList.class);
         
         // assertions will fail
         assertThat("abc").isNotInstanceOf(String.class);
         assertThat(new HashMap<String, Integer>()).isNotInstanceOf(HashMap.class);
         assertThat(new HashMap<String, Integer>()).isNotInstanceOf(Map.class);
        Specified by:
        isNotInstanceOf in interface Assert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>>
        Overrides:
        isNotInstanceOf in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        type - the type to check the actual value against.
        Returns:
        this assertion object.
      • isNotInstanceOfAny

        public IterableAssert<ELEMENT> isNotInstanceOfAny​(java.lang.Class<?>... types)
        Description copied from class: AbstractAssert
        Verifies that the actual value is not an instance of any of the given types.

        Example:

         // assertions will pass
         assertThat(1).isNotInstanceOfAny(Double.class, Float.class);
         assertThat(new ArrayList<String>()).isNotInstanceOfAny(LinkedList.class, Vector.class);
         
         // assertions will fail
         assertThat(1).isNotInstanceOfAny(Double.class, Integer.class);
         assertThat(new ArrayList<String>()).isNotInstanceOfAny(LinkedList.class, ArrayList.class);
         assertThat(new HashMap<String, Integer>()).isNotInstanceOfAny(TreeMap.class, Map.class);
        Specified by:
        isNotInstanceOfAny in interface Assert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>>
        Overrides:
        isNotInstanceOfAny in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        types - the types to check the actual value against.
        Returns:
        this assertion object.
      • isNotOfAnyClassIn

        public IterableAssert<ELEMENT> isNotOfAnyClassIn​(java.lang.Class<?>... types)
        Description copied from class: AbstractAssert
        Verifies that the actual value type is not in given types.

        Example:

         // assertions will pass
         assertThat(new HashMap<String, Integer>()).isNotOfAnyClassIn(Map.class, TreeMap.class);
         assertThat(new ArrayList<String>()).isNotOfAnyClassIn(LinkedList.class, List.class);
         
         // assertions will fail
         assertThat(new HashMap<String, Integer>()).isNotOfAnyClassIn(HashMap.class, TreeMap.class);
         assertThat(new ArrayList<String>()).isNotOfAnyClassIn(ArrayList.class, LinkedList.class);
        Specified by:
        isNotOfAnyClassIn in interface Assert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>>
        Overrides:
        isNotOfAnyClassIn in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        types - the types to check the actual value against.
        Returns:
        this assertion object.
      • isNotExactlyInstanceOf

        public IterableAssert<ELEMENT> isNotExactlyInstanceOf​(java.lang.Class<?> type)
        Description copied from class: AbstractAssert
        Verifies that the actual value is not exactly an instance of given type.

        Example:

         // assertions will pass
         assertThat(1).isNotExactlyInstanceOf(String.class);
         assertThat(new ArrayList<String>()).isNotExactlyInstanceOf(List.class);
         assertThat(new HashMap<String, Integer>()).isNotExactlyInstanceOf(Map.class);
         
         // assertions will fail
         assertThat("abc").isNotExactlyInstanceOf(String.class);
         assertThat(new ArrayList<String>()).isNotExactlyInstanceOf(ArrayList.class);
         assertThat(new HashMap<String, Integer>()).isNotExactlyInstanceOf(HashMap.class);
        Specified by:
        isNotExactlyInstanceOf in interface Assert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>>
        Overrides:
        isNotExactlyInstanceOf in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        type - the type to check the actual value against.
        Returns:
        this assertion object.
      • isSameAs

        public IterableAssert<ELEMENT> isSameAs​(java.lang.Object expected)
        Description copied from class: AbstractAssert
        Verifies that the actual value is the same as the given one, ie using == comparison.

        Example:

         // Name is a class with first and last fields, two Names are equals if both first and last are equals.
         Name tyrion = new Name("Tyrion", "Lannister");
         Name alias  = tyrion;
         Name clone  = new Name("Tyrion", "Lannister");
         
         // assertions succeed:
         assertThat(tyrion).isSameAs(alias)
                           .isEqualTo(clone);
                              
         // assertion fails:
         assertThat(tyrion).isSameAs(clone);
        Specified by:
        isSameAs in interface Assert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>>
        Overrides:
        isSameAs in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        expected - the given value to compare the actual value to.
        Returns:
        this assertion object.
      • isNotSameAs

        public IterableAssert<ELEMENT> isNotSameAs​(java.lang.Object expected)
        Description copied from class: AbstractAssert
        Verifies that the actual value is not the same as the given one, ie using == comparison.

        Example:

         // Name is a class with first and last fields, two Names are equals if both first and last are equals.
         Name tyrion = new Name("Tyrion", "Lannister");
         Name alias  = tyrion;
         Name clone  = new Name("Tyrion", "Lannister");
         
         // assertions succeed:
         assertThat(clone).isNotSameAs(tyrion)
                          .isEqualTo(tyrion);
                              
         // assertion fails:
         assertThat(alias).isNotSameAs(tyrion);
        Specified by:
        isNotSameAs in interface Assert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>>
        Overrides:
        isNotSameAs in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        expected - the given value to compare the actual value to.
        Returns:
        this assertion object.
      • actualDoesNotStartWithSequence

        private java.lang.AssertionError actualDoesNotStartWithSequence​(AssertionInfo info,
                                                                        java.lang.Iterable<?> actual,
                                                                        java.lang.Object[] sequence)
      • toIterable

        private static <T> java.lang.Iterable<T> toIterable​(java.util.Iterator<T> iterator)
      • containsOnlyOnce

        @SafeVarargs
        public final IterableAssert<ELEMENT> containsOnlyOnce​(ELEMENT... values)
        Description copied from class: AbstractIterableAssert
        Verifies that the actual group contains the given values only once.

        Examples :

         // lists are used in the examples but it would also work with arrays
         
         // assertions will pass
         assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("winter");
         assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("coming", "winter");
         
         // assertions will fail
         assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("Lannister");
         assertThat(newArrayList("Arya", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark");
         assertThat(newArrayList("Arya", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark", "Lannister", "Arya");
        Specified by:
        containsOnlyOnce in interface ObjectEnumerableAssert<IterableAssert<ELEMENT>,​ELEMENT>
        Overrides:
        containsOnlyOnce in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        values - the given values.
        Returns:
        this assertion object.
      • isSubsetOf

        @SafeVarargs
        public final IterableAssert<ELEMENT> isSubsetOf​(ELEMENT... values)
        Description copied from class: AbstractIterableAssert
        Verifies that all the elements of actual are present in the given values.

        Example:

         // an Iterable is used in the example but it would also work with an array
         Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
         
         // assertions will pass:
         assertThat(elvesRings).isSubsetOf(vilya, nenya, narya)
                               .isSubsetOf(vilya, nenya, narya, dwarfRing);
         
         // assertions will fail:
         assertThat(elvesRings).isSubsetOf(vilya, nenya);
         assertThat(elvesRings).isSubsetOf(vilya, nenya, dwarfRing);
        Specified by:
        isSubsetOf in interface ObjectEnumerableAssert<IterableAssert<ELEMENT>,​ELEMENT>
        Overrides:
        isSubsetOf in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        values - the values that should be used for checking the elements of actual.
        Returns:
        this assertion object.
      • doesNotContainSubsequence

        @SafeVarargs
        public final IterableAssert<ELEMENT> doesNotContainSubsequence​(ELEMENT... sequence)
        Description copied from class: AbstractIterableAssert
        Verifies that the actual group does not contain the given subsequence, a subsequence is defined by an ordered group of values with possibly extra values between them.

        Example:

         // an Iterable is used in the example but it would also work with an array
         Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
        
         // assertions will pass
         assertThat(elvesRings).doesNotContainSubsequence(nenya, vilya)
                               .doesNotContainSubsequence(narya, vilya);
        
         // assertion will fail
         assertThat(elvesRings).doesNotContainSubsequence(vilya, nenya);
         assertThat(elvesRings).doesNotContainSubsequence(vilya, narya);
        Specified by:
        doesNotContainSubsequence in interface ObjectEnumerableAssert<IterableAssert<ELEMENT>,​ELEMENT>
        Overrides:
        doesNotContainSubsequence in class AbstractIterableAssert<IterableAssert<ELEMENT>,​java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>>
        Parameters:
        sequence - the sequence of objects to look for.
        Returns:
        this assertion object.