Skip to content

Commit

Permalink
Copy Truth8.assertThat overloads for Optional and Stream to the…
Browse files Browse the repository at this point in the history
… 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: 596422911
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Jan 15, 2024
1 parent ca7e8f4 commit a7a4e1c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 14 additions & 0 deletions core/src/main/java/com/google/common/truth/Truth.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.google.common.collect.Table;
import java.math.BigDecimal;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand Down Expand Up @@ -249,6 +251,18 @@ 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?)
public static <T> OptionalSubject assertThat(@Nullable Optional<T> 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?)
public static <T extends @Nullable Object> StreamSubject assertThat(@Nullable Stream<T> actual) {
return assert_().that(actual);
}

/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import com.google.common.reflect.TypeToken;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Optional;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -47,9 +45,6 @@ public void staticAssertThatMethodsMatchStandardSubjectBuilderInstanceMethods()
ImmutableSortedSet<TypeToken<?>> 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] != Optional.class)
.filter(input -> input.getParameterTypes()[0] != Stream.class)
.transform(TruthAssertThatTest::methodToReturnTypeToken)
.toSortedSet(Ordering.usingToString());
ImmutableSortedSet<TypeToken<?>> truthTypes =
Expand Down

0 comments on commit a7a4e1c

Please sign in to comment.