Skip to content

Commit

Permalink
Simplify Stream check in FieldArgumentsProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Apr 21, 2024
1 parent aac45b9 commit 0d49899
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
Expand Up @@ -19,9 +19,7 @@
import java.util.Iterator;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.BaseStream;
import java.util.stream.Stream;

import org.junit.jupiter.api.extension.ExtensionContext;
Expand Down Expand Up @@ -107,15 +105,8 @@ private static Object readField(Field field, Object testInstance) {
Preconditions.notNull(value,
() -> format("The value of field [%s] in class [%s] must not be null", fieldName, declaringClass));

boolean isStream = value instanceof Stream//
|| value instanceof DoubleStream//
|| value instanceof IntStream//
|| value instanceof LongStream;

Preconditions.condition(!isStream,
() -> format(
"The value of field [%s] in class [%s] must not be a Stream, IntStream, LongStream, or DoubleStream",
fieldName, declaringClass));
Preconditions.condition(!(value instanceof BaseStream),
() -> format("The value of field [%s] in class [%s] must not be a stream", fieldName, declaringClass));

Preconditions.condition(!(value instanceof Iterator),
() -> format("The value of field [%s] in class [%s] must not be an Iterator", fieldName, declaringClass));
Expand Down
Expand Up @@ -434,8 +434,7 @@ void throwsExceptionWhenLocalFieldHasStreamReturnType(String field) {

var exception = assertThrows(PreconditionViolationException.class, () -> provideArguments(field).toArray());

assertThat(exception.getMessage()).isEqualTo(
"The value of field [%s] in class [%s] must not be a Stream, IntStream, LongStream, or DoubleStream",
assertThat(exception.getMessage()).isEqualTo("The value of field [%s] in class [%s] must not be a stream",
field, factoryClass);
}

Expand Down

0 comments on commit 0d49899

Please sign in to comment.