Skip to content

Commit

Permalink
Copy remaining Truth8.assertThat overloads to the main Truth clas…
Browse files Browse the repository at this point in the history
…s—except `Path` and `OptionalLong`.

We'll post some migration suggestions as part of the release notes.

This is the biggest remaining part of #746, but some loose ends remain.

RELNOTES=Added most remaining `Truth8.assertThat` overloads to the main `Truth` class.
PiperOrigin-RevId: 603485177
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Feb 1, 2024
1 parent b02a658 commit 9be8e77
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
47 changes: 43 additions & 4 deletions core/src/main/java/com/google/common/truth/Truth.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 <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?)
/**
* @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 <T extends @Nullable Object> StreamSubject assertThat(@Nullable Stream<T> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit 9be8e77

Please # to comment.