Class CollectionAssertions

java.lang.Object
org.soliscode.test.assertions.collection.CollectionAssertions

public final class CollectionAssertions extends Object
A collection of utility methods that support asserting conditions on collections in tests.
Since:
1.0.0
Author:
evanbergstrom
  • Method Details

    • assertIsEmpty

      public static void assertIsEmpty(Iterable<?> actual)
      Assert that the collection is empty.
      Parameters:
      actual - The iterable that should be empty.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable is not empty or the iterable is null.
    • assertIsEmpty

      public static void assertIsEmpty(Iterable<?> actual, String message)
      Assert that the collection is empty.
      Parameters:
      actual - The iterable that should be empty.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable is not empty or the iterable is null.
    • assertIsEmpty

      public static void assertIsEmpty(Iterable<?> actual, Supplier<String> messageSupplier)
      Assert that the iterable is empty.
      Parameters:
      actual - The iterable that should be empty.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable is not empty or the iterable is null.
    • assertSameSize

      public static void assertSameSize(Iterable<?> expected, Iterable<?> actual)
      Assert that the collections are the same size.
      Parameters:
      expected - The collection with the expected size.
      actual - The collection with the actual size.
      Throws:
      org.opentest4j.AssertionFailedError - if the collection is not empty.
      NullPointerException - is either of the collections are null.
    • assertSameSize

      public static void assertSameSize(Iterable<?> expected, Iterable<?> actual, String message)
      Assert that the collections are the same size.
      Parameters:
      expected - The collection with the expected size.
      actual - The collection with the actual size.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the collection is not empty.
      NullPointerException - is either of the collections are null.
    • assertSameSize

      public static void assertSameSize(Iterable<?> expected, Iterable<?> actual, Supplier<String> messageSupplier)
      Assert that the collections are the same size.
      Parameters:
      expected - The collection with the expected size.
      actual - The collection with the actual size.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the collection is not empty.
      NullPointerException - is either of the collections are null.
    • assertContains

      public static void assertContains(Object expected, Iterable<?> actual)
      Test if an iterable contains a specific element. The elements are considered the same if the equals method returns true.
      Parameters:
      expected - The element it should contain
      actual - The iterable that should contain the elements.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not the element or if either of the iterable arguments is null.
    • assertContains

      public static void assertContains(Object expected, Iterable<?> actual, String message)
      Test if an iterable contains a specific element. The elements are considered the same if the equals method returns true.
      Parameters:
      expected - The element it should contain
      actual - The iterable that should contain the element.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not the element or if either of the iterable arguments is null.
    • assertContains

      public static void assertContains(Object expected, Iterable<?> actual, Supplier<String> messageSupplier)
      Test if an iterable contains a specific element. The elements are considered the same if the equals method returns true.
      Parameters:
      expected - The element it should contain
      actual - The iterable that should contain the element.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not the element or if either of the iterable arguments is null.
    • assertContainsAll

      public static void assertContainsAll(Iterable<?> expected, Iterable<?> actual)
      Test if an iterable contains all of a set of elements. The elements are considered the same if the equals method returns true.
      Parameters:
      expected - The elements the iterable must contain.
      actual - The iterable that should contain the elements.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertContainsAll

      public static void assertContainsAll(Iterable<?> expected, Iterable<?> actual, String message)
      Test if an iterable contains all of a set of elements. The elements are considered the same if the equals method returns true.
      Parameters:
      expected - The elements the iterable must contain.
      actual - The iterable that should contain the elements.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertContainsAll

      public static void assertContainsAll(Iterable<?> expected, Iterable<?> actual, Supplier<String> messageSupplier)
      Test if an iterable contains all of a set of elements. The elements are considered the same if the equals method returns true.
      Parameters:
      expected - The elements the iterable must contain.
      actual - The iterable that should contain the elements.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertEquals

      public static void assertEquals(Iterable<?> expected, Iterable<?> actual)
      Test if an iterable contains all of a set of elements in the same order. The elements are considered the same if the equals method returns true.
      Parameters:
      expected - The elements the iterable must contain.
      actual - The iterable that should contain the elements.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertEquals

      public static <E> void assertEquals(E[] expected, Iterable<?> actual)
      Test if an iterable contains all of an array of elements in the same order. The elements are considered the same if the equals method returns true.
      Type Parameters:
      E - the type of the element.
      Parameters:
      expected - An array of the elements the iterable must contain.
      actual - The iterable that should contain the elements.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertEquals

      public static <E> void assertEquals(Iterable<?> expected, E[] actual)
      Test if an array contains all of a list of elements in the same order. The elements are considered the same if the equals method returns true.
      Type Parameters:
      E - the type of the element.
      Parameters:
      expected - The elements the array must contain.
      actual - The array that should contain the elements.
      Throws:
      org.opentest4j.AssertionFailedError - if the array does not contain all the elements or if either of the arguments is null.
    • assertEquals

      public static <E> void assertEquals(Iterable<?> expected, E[] actual, String message)
      Test if an array contains all of a list of elements in the same order. The elements are considered the same if the equals method returns true.
      Type Parameters:
      E - the type of the element.
      Parameters:
      expected - The elements the array must contain.
      actual - The array that should contain the elements.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the array does not contain all the elements or if either of the arguments is null.
    • assertEquals

      public static <E> void assertEquals(Iterable<?> expected, E[] actual, Supplier<String> messageSupplier)
      Test if an array contains all of a list of elements in the same order. The elements are considered the same if the equals method returns true.
      Type Parameters:
      E - the type of the element.
      Parameters:
      expected - The elements the array must contain.
      actual - The array that should contain the elements.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the array does not contain all the elements or if either of the arguments is null.
    • assertEquals

      public static void assertEquals(Iterable<?> expected, Iterable<?> actual, String message)
      Test if an iterable contains all of a set of elements in the same order. The elements are considered the same if the equals method returns true.
      Parameters:
      expected - The elements the iterable must contain.
      actual - The iterable that should contain the elements.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertEquals

      public static <E> void assertEquals(E[] expected, Iterable<?> actual, String message)
      Test if an iterable contains all of an array of elements in the same order. The elements are considered the same if the equals method returns true.
      Type Parameters:
      E - the type of the element.
      Parameters:
      expected - An array of the elements the iterable must contain.
      actual - The iterable that should contain the elements.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertEquals

      public static void assertEquals(Iterable<?> expected, Iterable<?> actual, Supplier<String> messageSupplier)
      Test if an iterable contains all of a set of elements in the same order. The elements are considered the same if the equals method returns true.
      Parameters:
      expected - The elements the iterable must contain.
      actual - The iterable that should contain the elements.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertEquals

      public static <E> void assertEquals(E[] expected, Iterable<?> actual, Supplier<String> messageSupplier)
      Test if an iterable contains all of an array of elements in the same order. The elements are considered the same if the equals method returns true.
      Type Parameters:
      E - the type of the element.
      Parameters:
      expected - An array of the elements the iterable must contain.
      actual - The iterable that should contain the elements.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the arguments is null.
    • assertEqualsByIdentity

      public static void assertEqualsByIdentity(Iterable<?> expected, Iterable<?> actual)
      Test if an iterable contains all of a set of elements in the same order. The elements are considered the same if only if they same object.
      Parameters:
      expected - The elements the iterable must contain.
      actual - The iterable that should contain the elements.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertEqualsByIdentity

      public static <E> void assertEqualsByIdentity(E[] expected, Iterable<?> actual)
      Test if an iterable contains all of an array of elements in the same order. The elements are considered the same only if they same object.
      Type Parameters:
      E - the type of the element.
      Parameters:
      expected - An array of the elements the iterable must contain.
      actual - The iterable that should contain the elements.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertEqualsByIdentity

      public static <E> void assertEqualsByIdentity(Iterable<?> expected, E[] actual)
      Test if an array contains all of a list of elements in the same order. The elements are considered the same only if they same object.
      Type Parameters:
      E - the type of the element.
      Parameters:
      expected - The elements the array must contain.
      actual - The array that should contain the elements.
      Throws:
      org.opentest4j.AssertionFailedError - if the array does not contain all the elements or if either of the arguments is null.
    • assertEqualsByIdentity

      public static <E> void assertEqualsByIdentity(Iterable<?> expected, E[] actual, String message)
      Test if an array contains all of a list of elements in the same order. The elements are considered the same only if they same object.
      Type Parameters:
      E - the type of the element.
      Parameters:
      expected - The elements the array must contain.
      actual - The array that should contain the elements.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the array does not contain all the elements or if either of the arguments is null.
    • assertEqualsByIdentity

      public static <E> void assertEqualsByIdentity(Iterable<?> expected, E[] actual, Supplier<String> messageSupplier)
      Test if an array contains all of a list of elements in the same order. The elements are considered the same only if they same object.
      Type Parameters:
      E - the type of the element.
      Parameters:
      expected - The elements the array must contain.
      actual - The array that should contain the elements.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the array does not contain all the elements or if either of the arguments is null.
    • assertEqualsByIdentity

      public static void assertEqualsByIdentity(Iterable<?> expected, Iterable<?> actual, String message)
      Test if an iterable contains all of a set of elements in the same order. The elements are considered the same only if they same object.
      Parameters:
      expected - The elements the iterable must contain.
      actual - The iterable that should contain the elements.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertEqualsByIdentity

      public static <E> void assertEqualsByIdentity(E[] expected, Iterable<?> actual, String message)
      Test if an iterable contains all of an array of elements in the same order. The elements are considered the same only if they same object.
      Type Parameters:
      E - the type of the element.
      Parameters:
      expected - An array of the elements the iterable must contain.
      actual - The iterable that should contain the elements.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertEqualsByIdentity

      public static void assertEqualsByIdentity(Iterable<?> expected, Iterable<?> actual, Supplier<String> messageSupplier)
      Test if an iterable contains all of a set of elements in the same order. The elements are considered the same only if they same object.
      Parameters:
      expected - The elements the iterable must contain.
      actual - The iterable that should contain the elements.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertEqualsByIdentity

      public static <E> void assertEqualsByIdentity(E[] expected, Iterable<?> actual, Supplier<String> messageSupplier)
      Test if an iterable contains all of an array of elements in the same order. The elements are considered the same only if they same object.
      Type Parameters:
      E - the type of the element.
      Parameters:
      expected - An array of the elements the iterable must contain.
      actual - The iterable that should contain the elements.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the arguments is null.
    • assertContainsAllByIdentity

      public static void assertContainsAllByIdentity(Iterable<?> expected, Iterable<?> actual)
      Test if an iterable contains all of a set of elements. Two elements are only considered the same is they have the same identity (i.e they are the same object).
      Parameters:
      expected - The elements the iterable must contain.
      actual - The iterable that should contain the elements.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertContainsAllByIdentity

      public static void assertContainsAllByIdentity(Iterable<?> expected, Iterable<?> actual, String message)
      Test if an iterable contains all of a set of elements. Two elements are only considered the same is they have the same identity (i.e they are the same object).
      Parameters:
      expected - The elements the iterable must contain.
      actual - The iterable that should contain the elements.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertContainsAllByIdentity

      public static void assertContainsAllByIdentity(Iterable<?> expected, Iterable<?> actual, Supplier<String> messageSupplier)
      Test if an iterable contains all of a set of elements. Two elements are only considered the same is they have the same identity (i.e they are the same object).
      Parameters:
      expected - The elements the iterable must contain.
      actual - The iterable that should contain the elements.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements or if either of the iterable arguments is null.
    • assertContainsNone

      public static void assertContainsNone(Iterable<?> excluded, Iterable<?> actual)
      Test if an iterable contains no element from a set of elements. The elements are considered the same if the equals method returns true.
      Parameters:
      excluded - The elements the iterable must not contain.
      actual - The iterable that should not contain the elements.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable contains any of the elements or if either of the iterable arguments is null.
    • assertContainsNone

      public static void assertContainsNone(Iterable<?> excluded, Iterable<?> actual, String message)
      Test if an iterable contains no element from a set of elements. The elements are considered the same if the equals method returns true.
      Parameters:
      excluded - The elements the iterable must not contain.
      actual - The iterable that should not contain the elements.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable contains any of the elements or if either of the iterable arguments is null.
    • assertContainsNone

      public static void assertContainsNone(Iterable<?> excluded, Iterable<?> actual, Supplier<String> messageSupplier)
      Test if an iterable contains no element from a set of elements. The elements are considered the same if the equals method returns true.
      Parameters:
      excluded - The elements the iterable must not contain.
      actual - The iterable that should not contain the elements.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable contains any of the elements or if either of the iterable arguments is null.
    • assertContainsSame

      public static void assertContainsSame(Iterable<?> expected, Iterable<?> actual)

      A collection of utility methods that support asserting that two collections contain the same elements. The iterators must have the same number of elements, and for each element in the iterator being tested (actual), there must be an element in the comparison iterator (expected) that returns true when the equals()` method is called.

      This function should be called through the CollectionAssertions class:

         Iterable<Integer> actual = ...
         Iterable<Integer> expected = ...
         CollectionAssertions.assertContainsSame(expected, actual);
      
      Parameters:
      expected - The iterable with the expected set of elements.
      actual - The iterable with the actual set of elements.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements.
    • assertContainsSame

      public static void assertContainsSame(Iterable<?> expected, Iterable<?> actual, String message)

      A collection of utility methods that support asserting that two collections contain the same elements. The iterators must have the same number of elements, and for each element in the iterator being tested (actual), there must be an element in the comparison iterator (expected) that returns true when the equals()` method is called.

      This function should be called through the CollectionAssertions class:

         Iterable<Integer> actual = ...
         Iterable<Integer> expected = ...
         CollectionAssertions.assertContainsSame(expected, actual, "Iterators are not the same");
      
      Parameters:
      expected - The iterable with the expected set of elements.
      actual - The iterable with the actual set of elements.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements.
    • assertContainsSame

      public static void assertContainsSame(Iterable<?> expected, Iterable<?> actual, Supplier<String> messageSupplier)

      A collection of utility methods that support asserting that two collections contain the same elements. The iterators must have the same number of elements, and for each element in the iterator being tested (actual), there must be an element in the comparison iterator (expected) that returns true when the equals()` method is called.

      This function should be called through the CollectionAssertions class:

         Iterable<Integer> actual = ...
         Iterable<Integer> expected = ...
         CollectionAssertions.assertContainsSame(expected, actual, () -> "Iterators are not the same");
      
      Parameters:
      expected - The iterable with the expected set of elements.
      actual - The iterable with the actual set of elements.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements.
    • assertContainsSameByIdentity

      public static void assertContainsSameByIdentity(Iterable<?> expected, Iterable<?> actual)
      Test if two iterables contain the same set of elements. Two elements are only considered the same is they have the same identity (i.e they are the same object).
      Parameters:
      expected - The iterable with the expected set of elements.
      actual - The iterable with the actual set of elements.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements.
    • assertContainsSameByIdentity

      public static void assertContainsSameByIdentity(Iterable<?> expected, Iterable<?> actual, String message)
      Test if two iterables contain the same set of elements. Two elements are only considered the same is they have the same identity (i.e they are the same object).
      Parameters:
      expected - The iterable with the expected set of elements.
      actual - The iterable with the actual set of elements.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements.
    • assertContainsSameByIdentity

      public static void assertContainsSameByIdentity(Iterable<?> expected, Iterable<?> actual, Supplier<String> messageSupplier)
      Test if two iterables contain the same set of elements. Two elements are only considered the same is they have the same identity (i.e they are the same object).
      Parameters:
      expected - The iterable with the expected set of elements.
      actual - The iterable with the actual set of elements.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable does not contain all the elements.
    • assertDoesNotContain

      public static void assertDoesNotContain(Object expected, Iterable<?> actual)
      Test if an iterable does not contain a specific element. The elements are considered the same if the equals method returns true.
      Parameters:
      expected - The element it should not contain
      actual - The iterable that should not contain the elements.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable contains the element or if either of the iterable arguments is null.
    • assertDoesNotContain

      public static void assertDoesNotContain(Object expected, Iterable<?> actual, String message)
      Test if an iterable does not contain a specific element. The elements are considered the same if the equals method returns true.
      Parameters:
      expected - The element it should not contain
      actual - The iterable that should not contain the element.
      message - The message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable contains the element or if either of the iterable arguments is null.
    • assertDoesNotContain

      public static void assertDoesNotContain(Object expected, Iterable<?> actual, Supplier<String> messageSupplier)
      Test if an iterable does not contain a specific element. The elements are considered the same if the equals method returns true.
      Parameters:
      expected - The element it should not contain
      actual - The iterable that should not contain the element.
      messageSupplier - The supplier to call top generate message to supply if the assertion fails.
      Throws:
      org.opentest4j.AssertionFailedError - if the iterable contains the element or if either of the iterable arguments is null.