diff --git a/core/src/main/java/com/google/common/truth/Truth.java b/core/src/main/java/com/google/common/truth/Truth.java index f49b84695..f2e1a1d32 100644 --- a/core/src/main/java/com/google/common/truth/Truth.java +++ b/core/src/main/java/com/google/common/truth/Truth.java @@ -24,6 +24,10 @@ import java.math.BigDecimal; import java.util.Map; import java.util.Optional; +import java.util.OptionalDouble; +import java.util.OptionalInt; +import java.util.stream.IntStream; +import java.util.stream.LongStream; import java.util.stream.Stream; import org.checkerframework.checker.nullness.qual.Nullable; @@ -251,24 +255,59 @@ public static TableSubject assertThat(@Nullable Table actual) { return assert_().that(actual); } - @SuppressWarnings("Java7ApiChecker") // no more dangerous that wherever the user got the Optional - @GwtIncompatible // creates ambiguities (Eclipse bug 577808 or similar?) /** * @since 1.3.0 (present in {@link Truth8} since before 1.0) */ + @SuppressWarnings({ + "Java7ApiChecker", // no more dangerous than wherever the user got the Optional + "NullableOptional", // Truth always accepts nulls, no matter the type + }) public static OptionalSubject assertThat(@Nullable Optional actual) { return assert_().that(actual); } - @SuppressWarnings("Java7ApiChecker") // no more dangerous that wherever the user got the Stream - @GwtIncompatible // creates ambiguities (Eclipse bug 577808 or similar?) /** * @since 1.3.0 (present in {@link Truth8} since before 1.0) */ + @SuppressWarnings("Java7ApiChecker") // no more dangerous than wherever the user got the Stream + public static OptionalIntSubject assertThat(@Nullable OptionalInt actual) { + return assert_().that(actual); + } + + /** + * @since 1.4.0 (present in {@link Truth8} since before 1.0) + */ + @SuppressWarnings("Java7ApiChecker") // no more dangerous than wherever the user got the Stream + public static OptionalDoubleSubject assertThat(@Nullable OptionalDouble actual) { + return assert_().that(actual); + } + + /** + * @since 1.4.0 (present in {@link Truth8} since before 1.0) + */ + @SuppressWarnings("Java7ApiChecker") // no more dangerous than wherever the user got the Stream public static StreamSubject assertThat(@Nullable Stream actual) { return assert_().that(actual); } + /** + * @since 1.4.0 (present in {@link Truth8} since before 1.0) + */ + @SuppressWarnings("Java7ApiChecker") // no more dangerous than wherever the user got the Stream + public static IntStreamSubject assertThat(@Nullable IntStream actual) { + return assert_().that(actual); + } + + /** + * @since 1.4.0 (present in {@link Truth8} since before 1.0) + */ + @SuppressWarnings("Java7ApiChecker") // no more dangerous than wherever the user got the Stream + public static LongStreamSubject assertThat(@Nullable LongStream actual) { + return assert_().that(actual); + } + + // TODO(b/64757353): Add support for DoubleStream? + /** * An {@code AssertionError} that (a) always supports a cause, even under old versions of Android * and (b) omits "java.lang.AssertionError:" from the beginning of its toString() representation. diff --git a/core/src/test/java/com/google/common/truth/TruthAssertThatTest.java b/core/src/test/java/com/google/common/truth/TruthAssertThatTest.java index 97b1c110c..e5577f3ec 100644 --- a/core/src/test/java/com/google/common/truth/TruthAssertThatTest.java +++ b/core/src/test/java/com/google/common/truth/TruthAssertThatTest.java @@ -26,11 +26,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.nio.file.Path; -import java.util.OptionalDouble; -import java.util.OptionalInt; import java.util.OptionalLong; -import java.util.stream.IntStream; -import java.util.stream.LongStream; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -52,10 +48,6 @@ public void staticAssertThatMethodsMatchStandardSubjectBuilderInstanceMethods() FluentIterable.from(asList(StandardSubjectBuilder.class.getMethods())) .filter(input -> input.getName().equals("that")) // TODO: b/166630734 - Remove this when we add the assertThat overloads. - .filter(input -> input.getParameterTypes()[0] != IntStream.class) - .filter(input -> input.getParameterTypes()[0] != LongStream.class) - .filter(input -> input.getParameterTypes()[0] != OptionalDouble.class) - .filter(input -> input.getParameterTypes()[0] != OptionalInt.class) .filter(input -> input.getParameterTypes()[0] != OptionalLong.class) .filter(input -> input.getParameterTypes()[0] != Path.class) .transform(TruthAssertThatTest::methodToReturnTypeToken)