Skip to content

Commit 1f81827

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Copy Truth8.assertThat overloads for Path and OptionalLong to the main Truth class.
(split off from cl/603361985 because I was waiting on fixes to a couple projects) We'll post some migration suggestions as part of the release notes. This is one of the remaining loose ends of #746. RELNOTES=Added `Truth.assertThat(Path)` and `(OptionalLong)` overloads (copied from `Truth8`). PiperOrigin-RevId: 603713061
1 parent 9be8e77 commit 1f81827

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
import com.google.common.collect.Multimap;
2222
import com.google.common.collect.Multiset;
2323
import com.google.common.collect.Table;
24+
import com.google.j2objc.annotations.J2ObjCIncompatible;
2425
import java.math.BigDecimal;
26+
import java.nio.file.Path;
2527
import java.util.Map;
2628
import java.util.Optional;
2729
import java.util.OptionalDouble;
2830
import java.util.OptionalInt;
31+
import java.util.OptionalLong;
2932
import java.util.stream.IntStream;
3033
import java.util.stream.LongStream;
3134
import java.util.stream.Stream;
@@ -274,6 +277,14 @@ public static OptionalIntSubject assertThat(@Nullable OptionalInt actual) {
274277
return assert_().that(actual);
275278
}
276279

280+
/**
281+
* @since 1.4.0 (present in {@link Truth8} since before 1.0)
282+
*/
283+
@SuppressWarnings("Java7ApiChecker") // no more dangerous than wherever the user got the Stream
284+
public static OptionalLongSubject assertThat(@Nullable OptionalLong actual) {
285+
return assert_().that(actual);
286+
}
287+
277288
/**
278289
* @since 1.4.0 (present in {@link Truth8} since before 1.0)
279290
*/
@@ -308,6 +319,16 @@ public static LongStreamSubject assertThat(@Nullable LongStream actual) {
308319

309320
// TODO(b/64757353): Add support for DoubleStream?
310321

322+
/**
323+
* @since 1.4.0 (present in {@link Truth8} since before 1.0)
324+
*/
325+
@GwtIncompatible
326+
@J2ObjCIncompatible
327+
@J2ktIncompatible
328+
public static PathSubject assertThat(@Nullable Path actual) {
329+
return assert_().that(actual);
330+
}
331+
311332
/**
312333
* An {@code AssertionError} that (a) always supports a cause, even under old versions of Android
313334
* 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.nio.file.Path;
29-
import java.util.OptionalLong;
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] != OptionalLong.class)
52-
.filter(input -> input.getParameterTypes()[0] != Path.class)
5348
.transform(TruthAssertThatTest::methodToReturnTypeToken)
5449
.toSortedSet(Ordering.usingToString());
5550
ImmutableSortedSet<TypeToken<?>> truthTypes =

0 commit comments

Comments
 (0)