diff --git a/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java b/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java index f7aa0878e..2babc9d0c 100644 --- a/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java +++ b/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java @@ -22,9 +22,16 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Multiset; import com.google.common.collect.Table; +import com.google.j2objc.annotations.J2ObjCIncompatible; import java.math.BigDecimal; +import java.nio.file.Path; import java.util.Map; import java.util.Optional; +import java.util.OptionalDouble; +import java.util.OptionalInt; +import java.util.OptionalLong; +import java.util.stream.IntStream; +import java.util.stream.LongStream; import java.util.stream.Stream; import org.checkerframework.checker.nullness.qual.Nullable; @@ -182,6 +189,36 @@ public final OptionalSubject that(@Nullable Optional actual) { return new OptionalSubject(metadata(), actual, "optional"); } + /** + * @since 1.4.0 (with access to {@link OptionalIntSubject} previously part of {@code + * truth-java8-extension}) + */ + @SuppressWarnings( + "Java7ApiChecker") // no more dangerous that wherever the user got the OptionalInt + public final OptionalIntSubject that(@Nullable OptionalInt actual) { + return new OptionalIntSubject(metadata(), actual, "optionalInt"); + } + + /** + * @since 1.4.0 (with access to {@link OptionalLongSubject} previously part of {@code + * truth-java8-extension}) + */ + @SuppressWarnings( + "Java7ApiChecker") // no more dangerous that wherever the user got the OptionalLong + public final OptionalLongSubject that(@Nullable OptionalLong actual) { + return new OptionalLongSubject(metadata(), actual, "optionalLong"); + } + + /** + * @since 1.4.0 (with access to {@link OptionalDoubleSubject} previously part of {@code + * truth-java8-extension}) + */ + @SuppressWarnings( + "Java7ApiChecker") // no more dangerous that wherever the user got the OptionalDouble + public final OptionalDoubleSubject that(@Nullable OptionalDouble actual) { + return new OptionalDoubleSubject(metadata(), actual, "optionalDouble"); + } + /** * @since 1.3.0 (with access to {@link StreamSubject} previously part of {@code * truth-java8-extension}) @@ -191,6 +228,38 @@ public final StreamSubject that(@Nullable Stream actual) { return new StreamSubject(metadata(), actual); } + /** + * @since 1.4.0 (with access to {@link IntStreamSubject} previously part of {@code + * truth-java8-extension}) + */ + @SuppressWarnings("Java7ApiChecker") // no more dangerous that wherever the user got the IntStream + public final IntStreamSubject that(@Nullable IntStream actual) { + return new IntStreamSubject(metadata(), actual); + } + + /** + * @since 1.4.0 (with access to {@link LongStreamSubject} previously part of {@code + * truth-java8-extension}) + */ + @SuppressWarnings( + "Java7ApiChecker") // no more dangerous that wherever the user got the LongStream + public final LongStreamSubject that(@Nullable LongStream actual) { + return new LongStreamSubject(metadata(), actual); + } + + // TODO(b/64757353): Add support for DoubleStream? + + /** + * @since 1.4.0 (with access to {@link PathSubject} previously part of {@code + * truth-java8-extension}) + */ + @GwtIncompatible + @J2ObjCIncompatible + @J2ktIncompatible + public final PathSubject that(@Nullable Path actual) { + return new PathSubject(metadata(), actual); + } + /** * Returns a new instance that will output the given message before the main failure message. If * this method is called multiple times, the messages will appear in the order that they were 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 cb75b934e..97b1c110c 100644 --- a/core/src/test/java/com/google/common/truth/TruthAssertThatTest.java +++ b/core/src/test/java/com/google/common/truth/TruthAssertThatTest.java @@ -25,6 +25,12 @@ import com.google.common.reflect.TypeToken; 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; @@ -45,6 +51,13 @@ public void staticAssertThatMethodsMatchStandardSubjectBuilderInstanceMethods() ImmutableSortedSet> verbTypes = 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) .toSortedSet(Ordering.usingToString()); ImmutableSortedSet> truthTypes =