Class AssertionsForInterfaceTypes

Entry point for assertion methods for different data types. Each method in this class is a static factory for the
type-specific assertion objects. The purpose of this class is to make test code more readable.

Java 8 is picky when choosing the right assertThat method if the object under test is generic and bounded,
for example if foo is instance of T that extends Exception, java 8 will complain that it can't resolve
the proper assertThat method (normally assertThat(Throwable) as foo might implement an interface like List,
if that occurred assertThat(List) would also be a possible choice - thus confusing java 8.

assertThat

Be aware that calls to most methods on returned IterableAssert will consume Iterator so it won't be possible to
iterate over it again. Calling multiple methods on returned IterableAssert is safe as Iterator's elements are
cached by IterableAssert first time Iterator is consumed.

assertThat

Be aware that the Stream under test will be converted to a List when an assertions require to inspect its content.
Once this is done the Stream can't reused as it would have been consumed.

Calling multiple methods on the returned ListAssert is safe as it only interacts with the List built from the Stream.

Examples:

// you can chain multiple assertions on the Stream as it is converted to a List
assertThat(Stream.of(1, 2, 3)).contains(1)
.doesNotContain(42);

The following assertion fails as the Stream under test is converted to a List before being compared to the expected Stream:

// FAIL: the Stream under test is converted to a List and compared to a Stream but a List is not a Stream.
assertThat(Stream.of(1, 2, 3)).isEqualTo(Stream.of(1, 2, 3));

These assertions succeed as isEqualTo and isSameAs checks references which does not require to convert the Stream to a List.

// The following assertions succeed as it only performs reference checking which does not require to convert the Stream to a List
Stream<Integer> stream = Stream.of(1, 2, 3);
assertThat(stream).isEqualTo(stream)
.isSameAs(stream);

// you can chain multiple assertions on the DoubleStream as it is converted to a List
assertThat(DoubleStream.of(1.0, 2.0, 3.0)).contains(1.0)
.doesNotContain(42.0);

The following assertion fails as the DoubleStream under test is converted to a List before being compared to the expected DoubleStream:

// FAIL: the DoubleStream under test is converted to a List and compared to a DoubleStream but a List is not a DoubleStream.
assertThat(DoubleStream.of(1.0, 2.0, 3.0)).isEqualTo(DoubleStream.of(1.0, 2.0, 3.0));

These assertions succeed as isEqualTo and isSameAs checks references which does not require to convert the DoubleStream to a List.

// The following assertions succeed as it only performs reference checking which does not require to convert the DoubleStream to a List
DoubleStream stream = DoubleStream.of(1.0, 2.0, 3.0);
assertThat(stream).isEqualTo(stream)
.isSameAs(stream);

assertThat

Be aware that the LongStream under test will be converted to a List when an assertions require to inspect its content.
Once this is done the LongStream can't reused as it would have been consumed.

Calling multiple methods on the returned ListAssert is safe as it only interacts with the List built from the LongStream.

Examples:

// you can chain multiple assertions on the LongStream as it is converted to a List
assertThat(LongStream.of(1, 2, 3)).contains(1)
.doesNotContain(42);

The following assertion fails as the LongStream under test is converted to a List before being compared to the expected LongStream:

// FAIL: the LongStream under test is converted to a List and compared to a LongStream but a List is not a LongStream.
assertThat(LongStream.of(1, 2, 3)).isEqualTo(LongStream.of(1, 2, 3));

These assertions succeed as isEqualTo and isSameAs checks references which does not require to convert the LongStream to a List.

// The following assertions succeed as it only performs reference checking which does not require to convert the LongStream to a List
LongStream stream = LongStream.of(1, 2, 3);
assertThat(stream).isEqualTo(stream)
.isSameAs(stream);

assertThat

Be aware that the IntStream under test will be converted to a List when an assertions require to inspect its content.
Once this is done the IntStream can't reused as it would have been consumed.

Calling multiple methods on the returned ListAssert is safe as it only interacts with the List built from the IntStream.

Examples:

// you can chain multiple assertions on the IntStream as it is converted to a List
assertThat(IntStream.of(1, 2, 3)).contains(1)
.doesNotContain(42);

The following assertion fails as the IntStream under test is converted to a List before being compared to the expected IntStream:

// FAIL: the IntStream under test is converted to a List and compared to a IntStream but a List is not a IntStream.
assertThat(IntStream.of(1, 2, 3)).isEqualTo(IntStream.of(1, 2, 3));

These assertions succeed as isEqualTo and isSameAs checks references which does not require to convert the IntStream to a List.

// The following assertions succeed as it only performs reference checking which does not require to convert the IntStream to a List
IntStream stream = IntStream.of(1, 2, 3);
assertThat(stream).isEqualTo(stream)
.isSameAs(stream);