Skip to content

Commit

Permalink
Fixes #1046 by explicitly having assertThat methods for Stream, IntSt…
Browse files Browse the repository at this point in the history
…ream, LongStream and DoubleStream instead of BaseStream.
  • Loading branch information
joel-costigliola committed Jul 30, 2017
1 parent eefd039 commit 8b676a6
Show file tree
Hide file tree
Showing 9 changed files with 340 additions and 52 deletions.
67 changes: 58 additions & 9 deletions src/main/java/org/assertj/core/api/AbstractBDDSoftAssertions.java
Expand Up @@ -30,7 +30,10 @@
import java.util.function.IntPredicate;
import java.util.function.LongPredicate;
import java.util.function.Predicate;
import java.util.stream.BaseStream;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

import org.assertj.core.util.CheckReturnValue;

Expand Down Expand Up @@ -242,21 +245,67 @@ public LongPredicateAssert then(LongPredicate actual) {
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link BaseStream}.
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link Stream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link BaseStream} is consumed so it won't be
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link Stream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link BaseStream}.
* interacts with the {@link List} built from the {@link Stream}.
*
* <p>This method accepts {@link java.util.stream.Stream} and primitive stream variants
* {@link java.util.stream.IntStream}, {@link java.util.stream.LongStream} and {@link java.util.stream.DoubleStream}.
* @param actual the actual {@link Stream} value.
* @return the created assertion object.
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
public <ELEMENT> AbstractListAssert<?, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> then(Stream<? extends ELEMENT> actual) {
return proxy(ListAssert.class, Stream.class, actual);
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link DoubleStream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link DoubleStream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link DoubleStream}.
*
* @param actual the actual {@link DoubleStream} value.
* @return the created assertion object.
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
public AbstractListAssert<?, List<? extends Double>, Double, ObjectAssert<Double>> then(DoubleStream actual) {
return proxy(ListAssert.class, DoubleStream.class, actual);
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link LongStream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link LongStream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link LongStream}.
*
* @param actual the actual {@link BaseStream} value.
* @param actual the actual {@link LongStream} value.
* @return the created assertion object.
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
public <ELEMENT, STREAM extends BaseStream<ELEMENT, STREAM>> ListAssert<ELEMENT> then(BaseStream<? extends ELEMENT, STREAM> actual) {
return proxy(ListAssert.class, BaseStream.class, actual);
public AbstractListAssert<?, List<? extends Long>, Long, ObjectAssert<Long>> then(LongStream actual) {
return proxy(ListAssert.class, LongStream.class, actual);
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link IntStream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link IntStream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link IntStream}.
*
* @param actual the actual {@link IntStream} value.
* @return the created assertion object.
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
public AbstractListAssert<?, List<? extends Integer>, Integer, ObjectAssert<Integer>> then(IntStream actual) {
return proxy(ListAssert.class, IntStream.class, actual);
}

}
Expand Up @@ -30,7 +30,10 @@
import java.util.function.IntPredicate;
import java.util.function.LongPredicate;
import java.util.function.Predicate;
import java.util.stream.BaseStream;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

import org.assertj.core.util.CheckReturnValue;

Expand Down Expand Up @@ -242,22 +245,67 @@ public LongPredicateAssert assertThat(LongPredicate actual) {
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link BaseStream}.
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link Stream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link BaseStream} is consumed so it won't be
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link Stream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link BaseStream}.
* interacts with the {@link List} built from the {@link Stream}.
*
* <p>This method accepts {@link java.util.stream.Stream} and primitive stream variants
* {@link java.util.stream.IntStream}, {@link java.util.stream.LongStream} and {@link java.util.stream.DoubleStream}.
* @param actual the actual {@link Stream} value.
* @return the created assertion object.
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
public <ELEMENT> AbstractListAssert<?, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> assertThat(Stream<? extends ELEMENT> actual) {
return proxy(ListAssert.class, Stream.class, actual);
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link DoubleStream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link DoubleStream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link DoubleStream}.
*
* @param actual the actual {@link BaseStream} value.
* @param actual the actual {@link DoubleStream} value.
* @return the created assertion object.
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
public AbstractListAssert<?, List<? extends Double>, Double, ObjectAssert<Double>> assertThat(DoubleStream actual) {
return proxy(ListAssert.class, DoubleStream.class, actual);
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link LongStream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link LongStream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link LongStream}.
*
* @param actual the actual {@link LongStream} value.
* @return the created assertion object.
*/
@SuppressWarnings("unchecked")
@CheckReturnValue
public AbstractListAssert<?, List<? extends Long>, Long, ObjectAssert<Long>> assertThat(LongStream actual) {
return proxy(ListAssert.class, LongStream.class, actual);
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link IntStream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link IntStream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link IntStream}.
*
* @param actual the actual {@link IntStream} value.
* @return the created assertion object.
*/
@SuppressWarnings("unchecked")
public <ELEMENT, STREAM extends BaseStream<ELEMENT, STREAM>> ListAssert<ELEMENT> assertThat(BaseStream<? extends ELEMENT, STREAM> actual) {
return proxy(ListAssert.class, BaseStream.class, actual);
@CheckReturnValue
public AbstractListAssert<?, List<? extends Integer>, Integer, ObjectAssert<Integer>> assertThat(IntStream actual) {
return proxy(ListAssert.class, IntStream.class, actual);
}

}
61 changes: 53 additions & 8 deletions src/main/java/org/assertj/core/api/Assertions.java
Expand Up @@ -61,7 +61,10 @@
import java.util.function.IntPredicate;
import java.util.function.LongPredicate;
import java.util.function.Predicate;
import java.util.stream.BaseStream;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.assertj.core.api.exception.RuntimeIOException;
Expand Down Expand Up @@ -2415,20 +2418,62 @@ public static <ELEMENT> ListAssert<ELEMENT> assertThat(List<? extends ELEMENT> a
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link BaseStream}.
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link Stream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link BaseStream} is consumed so it won't be
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link Stream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link BaseStream}.
* interacts with the {@link List} built from the {@link Stream}.
*
* <p>This method accepts {@link java.util.stream.Stream} and primitive stream variants
* {@link java.util.stream.IntStream}, {@link java.util.stream.LongStream} and {@link java.util.stream.DoubleStream}.
* @param actual the actual {@link Stream} value.
* @return the created assertion object.
*/
@CheckReturnValue
public static <ELEMENT> AbstractListAssert<?, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> assertThat(Stream<? extends ELEMENT> actual) {
return AssertionsForInterfaceTypes.assertThat(actual);
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link DoubleStream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link DoubleStream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link DoubleStream}.
*
* @param actual the actual {@link DoubleStream} value.
* @return the created assertion object.
*/
@CheckReturnValue
public static AbstractListAssert<?, List<? extends Double>, Double, ObjectAssert<Double>> assertThat(DoubleStream actual) {
return AssertionsForInterfaceTypes.assertThat(actual);
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link LongStream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link LongStream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link LongStream}.
*
* @param actual the actual {@link LongStream} value.
* @return the created assertion object.
*/
@CheckReturnValue
public static AbstractListAssert<?, List<? extends Long>, Long, ObjectAssert<Long>> assertThat(LongStream actual) {
return AssertionsForInterfaceTypes.assertThat(actual);
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link IntStream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link IntStream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link IntStream}.
*
* @param actual the actual {@link BaseStream} value.
* @param actual the actual {@link IntStream} value.
* @return the created assertion object.
*/
@CheckReturnValue
public static <ELEMENT, STREAM extends BaseStream<ELEMENT, STREAM>> AbstractListAssert<?, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> assertThat(BaseStream<? extends ELEMENT, STREAM> actual) {
public static AbstractListAssert<?, List<? extends Integer>, Integer, ObjectAssert<Integer>> assertThat(IntStream actual) {
return AssertionsForInterfaceTypes.assertThat(actual);
}

Expand Down
65 changes: 55 additions & 10 deletions src/main/java/org/assertj/core/api/AssertionsForInterfaceTypes.java
Expand Up @@ -20,7 +20,10 @@
import java.util.function.IntPredicate;
import java.util.function.LongPredicate;
import java.util.function.Predicate;
import java.util.stream.BaseStream;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

import org.assertj.core.util.CheckReturnValue;

Expand Down Expand Up @@ -127,23 +130,65 @@ public static <ELEMENT> ListAssert<ELEMENT> assertThat(List<? extends ELEMENT> a
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link BaseStream}.
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link Stream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link BaseStream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link BaseStream}.
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link Stream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link Stream}.
*
* <p>This method accepts {@link java.util.stream.Stream} and primitive stream variants
* {@link java.util.stream.IntStream}, {@link java.util.stream.LongStream} and {@link java.util.stream.DoubleStream}.
* @param actual the actual {@link Stream} value.
* @return the created assertion object.
*/
@CheckReturnValue
public static <ELEMENT> AbstractListAssert<?, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> assertThat(Stream<? extends ELEMENT> actual) {
return new ListAssert<>(actual);
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link DoubleStream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link DoubleStream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link DoubleStream}.
*
* @param actual the actual {@link BaseStream} value.
* @param actual the actual {@link DoubleStream} value.
* @return the created assertion object.
*/
@CheckReturnValue
public static <ELEMENT, STREAM extends BaseStream<ELEMENT, STREAM>> ListAssert<ELEMENT> assertThat(BaseStream<? extends ELEMENT, STREAM> actual) {
public static AbstractListAssert<?, List<? extends Double>, Double, ObjectAssert<Double>> assertThat(DoubleStream actual) {
return new ListAssert<>(actual);
}


/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link LongStream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link LongStream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link LongStream}.
*
* @param actual the actual {@link LongStream} value.
* @return the created assertion object.
*/
@CheckReturnValue
public static AbstractListAssert<?, List<? extends Long>, Long, ObjectAssert<Long>> assertThat(LongStream actual) {
return new ListAssert<>(actual);
}

/**
* Creates a new instance of <code>{@link ListAssert}</code> from the given {@link IntStream}.
* <p>
* <b>Be aware that to create the returned {@link ListAssert} the given the {@link IntStream} is consumed so it won't be
* possible to use it again.</b> Calling multiple methods on the returned {@link ListAssert} is safe as it only
* interacts with the {@link List} built from the {@link IntStream}.
*
* @param actual the actual {@link IntStream} value.
* @return the created assertion object.
*/
@CheckReturnValue
public static AbstractListAssert<?, List<? extends Integer>, Integer, ObjectAssert<Integer>> assertThat(IntStream actual) {
return new ListAssert<>(actual);
}

/**
* Creates a new instance of <code>{@link IterableAssert}</code>.
*
Expand Down

0 comments on commit 8b676a6

Please sign in to comment.