Class ListAssert<ELEMENT>

java.lang.Object
org.assertj.core.api.AbstractAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>>
org.assertj.core.api.AbstractIterableAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
org.assertj.core.api.AbstractCollectionAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
org.assertj.core.api.AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
org.assertj.core.api.FactoryBasedNavigableListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
org.assertj.core.api.ListAssert<ELEMENT>
Type Parameters:
ELEMENT - the type of elements of the "actual" value.
All Implemented Interfaces:
Assert<ListAssert<ELEMENT>,List<? extends ELEMENT>>, Descriptable<ListAssert<ELEMENT>>, EnumerableAssert<ListAssert<ELEMENT>,ELEMENT>, ExtensionPoints<ListAssert<ELEMENT>,List<? extends ELEMENT>>, IndexedObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>, ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>

public class ListAssert<ELEMENT> extends FactoryBasedNavigableListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
Assertion methods for Lists.

To create an instance of this class, invoke Assertions.assertThat(List).

Author:
Yvonne Wang, Alex Ruiz, Joel Costigliola, Mikhail Mazursky
  • Constructor Details

    • ListAssert

      public ListAssert(List<? extends ELEMENT> actual)
    • ListAssert

      public ListAssert(Stream<? extends ELEMENT> actual)
    • ListAssert

      public ListAssert(IntStream actual)
    • ListAssert

      public ListAssert(LongStream actual)
    • ListAssert

      public ListAssert(DoubleStream actual)
  • Method Details

    • assertThatList

      public static <ELEMENT> ListAssert<ELEMENT> assertThatList(List<? extends ELEMENT> actual)
    • assertThatStream

      public static <ELEMENT> ListAssert<ELEMENT> assertThatStream(Stream<? extends ELEMENT> actual)
    • assertThatDoubleStream

      public static ListAssert<Double> assertThatDoubleStream(DoubleStream actual)
    • assertThatLongStream

      public static ListAssert<Long> assertThatLongStream(LongStream actual)
    • assertThatIntStream

      public static ListAssert<Integer> assertThatIntStream(IntStream actual)
    • newAbstractIterableAssert

      protected ListAssert<ELEMENT> newAbstractIterableAssert(Iterable<? extends ELEMENT> iterable)
      Description copied from class: AbstractIterableAssert
      This methods is needed to build a new concrete instance of AbstractIterableAssert after a filtering operation is executed.

      If you create your own subclass of AbstractIterableAssert, simply returns an instance of it in this method.

      Overrides:
      newAbstractIterableAssert in class FactoryBasedNavigableListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
      Parameters:
      iterable - the iterable used to build the concrete instance of AbstractIterableAssert
      Returns:
      concrete instance of AbstractIterableAssert
    • isEqualTo

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

      Example:

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

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

      Example:

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

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

      Example:

       // assertions succeed
       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 fail
       assertThat(1).isInstanceOfAny(Double.class, Float.class);
       assertThat(new ArrayList<String>()).isInstanceOfAny(LinkedList.class, Vector.class);
      Specified by:
      isInstanceOfAny in interface Assert<ListAssert<ELEMENT>,List<? extends ELEMENT>>
      Overrides:
      isInstanceOfAny in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
      Parameters:
      types - the types to check the actual value against.
      Returns:
      this assertion object.
    • isOfAnyClassIn

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

      Example:

       // assertions succeed
       assertThat(new HashMap<String, Integer>()).isOfAnyClassIn(HashMap.class, TreeMap.class);
       assertThat(new ArrayList<String>()).isOfAnyClassIn(ArrayList.class, LinkedList.class);
      
       // assertions 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<ListAssert<ELEMENT>,List<? extends ELEMENT>>
      Overrides:
      isOfAnyClassIn in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
      Parameters:
      types - the types to check the actual value against.
      Returns:
      this assertion object.
    • isExactlyInstanceOf

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

      Example:

       // assertions succeed
       assertThat("abc").isExactlyInstanceOf(String.class);
       assertThat(new ArrayList<String>()).isExactlyInstanceOf(ArrayList.class);
       assertThat(new HashMap<String, Integer>()).isExactlyInstanceOf(HashMap.class);
      
       // assertions 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<ListAssert<ELEMENT>,List<? extends ELEMENT>>
      Overrides:
      isExactlyInstanceOf in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
      Parameters:
      type - the type to check the actual value against.
      Returns:
      this assertion object.
    • isNotInstanceOf

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

      Example:

       // assertions succeed
       assertThat(1).isNotInstanceOf(Double.class);
       assertThat(new ArrayList<String>()).isNotInstanceOf(LinkedList.class);
      
       // assertions 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<ListAssert<ELEMENT>,List<? extends ELEMENT>>
      Overrides:
      isNotInstanceOf in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
      Parameters:
      type - the type to check the actual value against.
      Returns:
      this assertion object.
    • isNotInstanceOfAny

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

      Example:

       // assertions succeed
       assertThat(1).isNotInstanceOfAny(Double.class, Float.class);
       assertThat(new ArrayList<String>()).isNotInstanceOfAny(LinkedList.class, Vector.class);
      
       // assertions 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<ListAssert<ELEMENT>,List<? extends ELEMENT>>
      Overrides:
      isNotInstanceOfAny in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
      Parameters:
      types - the types to check the actual value against.
      Returns:
      this assertion object.
    • isNotOfAnyClassIn

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

      Example:

       // assertions succeed
       assertThat(new HashMap<String, Integer>()).isNotOfAnyClassIn(Map.class, TreeMap.class);
       assertThat(new ArrayList<String>()).isNotOfAnyClassIn(LinkedList.class, List.class);
      
       // assertions 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<ListAssert<ELEMENT>,List<? extends ELEMENT>>
      Overrides:
      isNotOfAnyClassIn in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
      Parameters:
      types - the types to check the actual value against.
      Returns:
      this assertion object.
    • isNotExactlyInstanceOf

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

      Example:

       // assertions succeed
       assertThat(1).isNotExactlyInstanceOf(String.class);
       assertThat(new ArrayList<String>()).isNotExactlyInstanceOf(List.class);
       assertThat(new HashMap<String, Integer>()).isNotExactlyInstanceOf(Map.class);
      
       // assertions 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<ListAssert<ELEMENT>,List<? extends ELEMENT>>
      Overrides:
      isNotExactlyInstanceOf in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
      Parameters:
      type - the type to check the actual value against.
      Returns:
      this assertion object.
    • isSameAs

      public ListAssert<ELEMENT> isSameAs(Object expected)
      Description copied from class: AbstractAssert
      Verifies that the actual value is the same as the given one, i.e., 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<ListAssert<ELEMENT>,List<? extends ELEMENT>>
      Overrides:
      isSameAs in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
      Parameters:
      expected - the given value to compare the actual value to.
      Returns:
      this assertion object.
    • isNotSameAs

      public ListAssert<ELEMENT> isNotSameAs(Object expected)
      Description copied from class: AbstractAssert
      Verifies that the actual value is not the same as the given one, i.e., 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<ListAssert<ELEMENT>,List<? extends ELEMENT>>
      Overrides:
      isNotSameAs in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
      Parameters:
      expected - the given value to compare the actual value to.
      Returns:
      this assertion object.
    • startsWithForProxy

      protected ListAssert<ELEMENT> startsWithForProxy(ELEMENT[] sequence)
      Overrides:
      startsWithForProxy in class AbstractIterableAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>