Skip to content

Commit

Permalink
Copy Truth8.assertThat overloads for Path and OptionalLong to t…
Browse files Browse the repository at this point in the history
…he 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
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Feb 2, 2024
1 parent 9be8e77 commit 1f81827
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
21 changes: 21 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 @@ -21,11 +21,14 @@
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;
import com.google.common.collect.Table;
import com.google.j2objc.annotations.J2ObjCIncompatible;
import java.math.BigDecimal;
import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;
Expand Down Expand Up @@ -274,6 +277,14 @@ 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 OptionalLongSubject assertThat(@Nullable OptionalLong actual) {
return assert_().that(actual);
}

/**
* @since 1.4.0 (present in {@link Truth8} since before 1.0)
*/
Expand Down Expand Up @@ -308,6 +319,16 @@ public static LongStreamSubject assertThat(@Nullable LongStream actual) {

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

/**
* @since 1.4.0 (present in {@link Truth8} since before 1.0)
*/
@GwtIncompatible
@J2ObjCIncompatible
@J2ktIncompatible
public static PathSubject assertThat(@Nullable Path 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.nio.file.Path;
import java.util.OptionalLong;
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] != OptionalLong.class)
.filter(input -> input.getParameterTypes()[0] != Path.class)
.transform(TruthAssertThatTest::methodToReturnTypeToken)
.toSortedSet(Ordering.usingToString());
ImmutableSortedSet<TypeToken<?>> truthTypes =
Expand Down

0 comments on commit 1f81827

Please sign in to comment.