Skip to content

Commit 37fd8be

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Copy Truth8.assertThat overloads for Optional and Stream to the main Truth class.
(and prepare AutoValue tests for the new overloads, since the Eclipse compiler considers the (temporary!) signatures of `assertThat(Optional)` to be ambiguous) We'll post some migration suggestions as part of the release notes. This is the biggest part of #746. RELNOTES=Added `assertThat` overloads for `Optional` and `Stream` to the main `Truth` class. PiperOrigin-RevId: 598664192
1 parent ca7e8f4 commit 37fd8be

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

core/src/main/java/com/google/common/truth/Truth.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.google.common.collect.Table;
2424
import java.math.BigDecimal;
2525
import java.util.Map;
26+
import java.util.Optional;
27+
import java.util.stream.Stream;
2628
import org.checkerframework.checker.nullness.qual.Nullable;
2729

2830
/**
@@ -249,6 +251,18 @@ public static TableSubject assertThat(@Nullable Table<?, ?, ?> actual) {
249251
return assert_().that(actual);
250252
}
251253

254+
@SuppressWarnings("Java7ApiChecker") // no more dangerous that wherever the user got the Optional
255+
@GwtIncompatible // creates ambiguities (Eclipse bug 577808 or similar?)
256+
public static <T> OptionalSubject assertThat(@Nullable Optional<T> actual) {
257+
return assert_().that(actual);
258+
}
259+
260+
@SuppressWarnings("Java7ApiChecker") // no more dangerous that wherever the user got the Stream
261+
@GwtIncompatible // creates ambiguities (Eclipse bug 577808 or similar?)
262+
public static <T extends @Nullable Object> StreamSubject assertThat(@Nullable Stream<T> actual) {
263+
return assert_().that(actual);
264+
}
265+
252266
/**
253267
* An {@code AssertionError} that (a) always supports a cause, even under old versions of Android
254268
* and (b) omits "java.lang.AssertionError:" from the beginning of its toString() representation.

core/src/test/java/com/google/common/truth/TruthAssertThatTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import com.google.common.reflect.TypeToken;
2626
import java.lang.reflect.Method;
2727
import java.lang.reflect.Modifier;
28-
import java.util.Optional;
29-
import java.util.stream.Stream;
3028
import org.junit.Test;
3129
import org.junit.runner.RunWith;
3230
import org.junit.runners.JUnit4;
@@ -47,9 +45,6 @@ public void staticAssertThatMethodsMatchStandardSubjectBuilderInstanceMethods()
4745
ImmutableSortedSet<TypeToken<?>> verbTypes =
4846
FluentIterable.from(asList(StandardSubjectBuilder.class.getMethods()))
4947
.filter(input -> input.getName().equals("that"))
50-
// TODO: b/166630734 - Remove this when we add the assertThat overloads.
51-
.filter(input -> input.getParameterTypes()[0] != Optional.class)
52-
.filter(input -> input.getParameterTypes()[0] != Stream.class)
5348
.transform(TruthAssertThatTest::methodToReturnTypeToken)
5449
.toSortedSet(Ordering.usingToString());
5550
ImmutableSortedSet<TypeToken<?>> truthTypes =

0 commit comments

Comments
 (0)