Skip to content

Commit 9be8e77

Browse files
cpovirkGoogle Java Core Libraries
authored and
Google Java Core Libraries
committedFeb 1, 2024
Copy remaining Truth8.assertThat overloads to the main Truth class—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
1 parent b02a658 commit 9be8e77

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed
 

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

+43-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
import java.math.BigDecimal;
2525
import java.util.Map;
2626
import java.util.Optional;
27+
import java.util.OptionalDouble;
28+
import java.util.OptionalInt;
29+
import java.util.stream.IntStream;
30+
import java.util.stream.LongStream;
2731
import java.util.stream.Stream;
2832
import org.checkerframework.checker.nullness.qual.Nullable;
2933

@@ -251,24 +255,59 @@ public static TableSubject assertThat(@Nullable Table<?, ?, ?> actual) {
251255
return assert_().that(actual);
252256
}
253257

254-
@SuppressWarnings("Java7ApiChecker") // no more dangerous that wherever the user got the Optional
255-
@GwtIncompatible // creates ambiguities (Eclipse bug 577808 or similar?)
256258
/**
257259
* @since 1.3.0 (present in {@link Truth8} since before 1.0)
258260
*/
261+
@SuppressWarnings({
262+
"Java7ApiChecker", // no more dangerous than wherever the user got the Optional
263+
"NullableOptional", // Truth always accepts nulls, no matter the type
264+
})
259265
public static <T> OptionalSubject assertThat(@Nullable Optional<T> actual) {
260266
return assert_().that(actual);
261267
}
262268

263-
@SuppressWarnings("Java7ApiChecker") // no more dangerous that wherever the user got the Stream
264-
@GwtIncompatible // creates ambiguities (Eclipse bug 577808 or similar?)
265269
/**
266270
* @since 1.3.0 (present in {@link Truth8} since before 1.0)
267271
*/
272+
@SuppressWarnings("Java7ApiChecker") // no more dangerous than wherever the user got the Stream
273+
public static OptionalIntSubject assertThat(@Nullable OptionalInt actual) {
274+
return assert_().that(actual);
275+
}
276+
277+
/**
278+
* @since 1.4.0 (present in {@link Truth8} since before 1.0)
279+
*/
280+
@SuppressWarnings("Java7ApiChecker") // no more dangerous than wherever the user got the Stream
281+
public static OptionalDoubleSubject assertThat(@Nullable OptionalDouble actual) {
282+
return assert_().that(actual);
283+
}
284+
285+
/**
286+
* @since 1.4.0 (present in {@link Truth8} since before 1.0)
287+
*/
288+
@SuppressWarnings("Java7ApiChecker") // no more dangerous than wherever the user got the Stream
268289
public static <T extends @Nullable Object> StreamSubject assertThat(@Nullable Stream<T> actual) {
269290
return assert_().that(actual);
270291
}
271292

293+
/**
294+
* @since 1.4.0 (present in {@link Truth8} since before 1.0)
295+
*/
296+
@SuppressWarnings("Java7ApiChecker") // no more dangerous than wherever the user got the Stream
297+
public static IntStreamSubject assertThat(@Nullable IntStream actual) {
298+
return assert_().that(actual);
299+
}
300+
301+
/**
302+
* @since 1.4.0 (present in {@link Truth8} since before 1.0)
303+
*/
304+
@SuppressWarnings("Java7ApiChecker") // no more dangerous than wherever the user got the Stream
305+
public static LongStreamSubject assertThat(@Nullable LongStream actual) {
306+
return assert_().that(actual);
307+
}
308+
309+
// TODO(b/64757353): Add support for DoubleStream?
310+
272311
/**
273312
* An {@code AssertionError} that (a) always supports a cause, even under old versions of Android
274313
* and (b) omits "java.lang.AssertionError:" from the beginning of its toString() representation.

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

-8
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@
2626
import java.lang.reflect.Method;
2727
import java.lang.reflect.Modifier;
2828
import java.nio.file.Path;
29-
import java.util.OptionalDouble;
30-
import java.util.OptionalInt;
3129
import java.util.OptionalLong;
32-
import java.util.stream.IntStream;
33-
import java.util.stream.LongStream;
3430
import org.junit.Test;
3531
import org.junit.runner.RunWith;
3632
import org.junit.runners.JUnit4;
@@ -52,10 +48,6 @@ public void staticAssertThatMethodsMatchStandardSubjectBuilderInstanceMethods()
5248
FluentIterable.from(asList(StandardSubjectBuilder.class.getMethods()))
5349
.filter(input -> input.getName().equals("that"))
5450
// TODO: b/166630734 - Remove this when we add the assertThat overloads.
55-
.filter(input -> input.getParameterTypes()[0] != IntStream.class)
56-
.filter(input -> input.getParameterTypes()[0] != LongStream.class)
57-
.filter(input -> input.getParameterTypes()[0] != OptionalDouble.class)
58-
.filter(input -> input.getParameterTypes()[0] != OptionalInt.class)
5951
.filter(input -> input.getParameterTypes()[0] != OptionalLong.class)
6052
.filter(input -> input.getParameterTypes()[0] != Path.class)
6153
.transform(TruthAssertThatTest::methodToReturnTypeToken)

0 commit comments

Comments
 (0)
Please sign in to comment.