Skip to content

Commit

Permalink
Update docs to reflect that the Java 8 assertions have "moved" to the…
Browse files Browse the repository at this point in the history
… main `Truth` class.

This includes deprecating the old class.

This continues work on #746.

RELNOTES=Deprecated `Truth8`. All its functionality is now supported through the main `Truth` API.
PiperOrigin-RevId: 604762265
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Feb 6, 2024
1 parent 45782bd commit 1e9d4d8
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ protected String actualCustomStringRepresentation() {
return String.valueOf(actualList);
}

/**
* Obsolete factory instance. This factory was previously necessary for assertions like {@code
* assertWithMessage(...).about(intStreams()).that(stream)....}. Now, you can perform assertions
* like that without the {@code about(...)} call.
*/
public static Factory<IntStreamSubject, IntStream> intStreams() {
return IntStreamSubject::new;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ protected String actualCustomStringRepresentation() {
return String.valueOf(actualList);
}

/**
* Obsolete factory instance. This factory was previously necessary for assertions like {@code
* assertWithMessage(...).about(longStreams()).that(stream)....}. Now, you can perform assertions
* like that without the {@code about(...)} call.
*/
public static Factory<LongStreamSubject, LongStream> longStreams() {
return LongStreamSubject::new;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public void hasValue(double expected) {
}
}

/**
* Obsolete factory instance. This factory was previously necessary for assertions like {@code
* assertWithMessage(...).about(optionalDoubles()).that(optional)....}. Now, you can perform
* assertions like that without the {@code about(...)} call.
*/
public static Subject.Factory<OptionalDoubleSubject, OptionalDouble> optionalDoubles() {
return (metadata, subject) -> new OptionalDoubleSubject(metadata, subject, "optionalDouble");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public void hasValue(int expected) {
}
}

/**
* Obsolete factory instance. This factory was previously necessary for assertions like {@code
* assertWithMessage(...).about(optionalInts()).that(optional)....}. Now, you can perform
* assertions like that without the {@code about(...)} call.
*/
public static Subject.Factory<OptionalIntSubject, OptionalInt> optionalInts() {
return (metadata, subject) -> new OptionalIntSubject(metadata, subject, "optionalInt");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public void hasValue(long expected) {
}
}

/**
* Obsolete factory instance. This factory was previously necessary for assertions like {@code
* assertWithMessage(...).about(optionalLongs()).that(optional)....}. Now, you can perform
* assertions like that without the {@code about(...)} call.
*/
public static Subject.Factory<OptionalLongSubject, OptionalLong> optionalLongs() {
return (metadata, subject) -> new OptionalLongSubject(metadata, subject, "optionalLong");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public void hasValue(@Nullable Object expected) {
}
}

/**
* Obsolete factory instance. This factory was previously necessary for assertions like {@code
* assertWithMessage(...).about(paths()).that(path)....}. Now, you can perform assertions like
* that without the {@code about(...)} call.
*/
public static Subject.Factory<OptionalSubject, Optional<?>> optionals() {
return (metadata, subject) -> new OptionalSubject(metadata, subject, "optional");
}
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/com/google/common/truth/PathSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public final class PathSubject extends Subject {
super(failureMetadata, actual);
}

/**
* Obsolete factory instance. This factory was previously necessary for assertions like {@code
* assertWithMessage(...).about(intStreams()).that(stream)....}. Now, you can perform assertions
* like that without the {@code about(...)} call.
*/
public static Subject.Factory<PathSubject, Path> paths() {
return PathSubject::new;
}
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/com/google/common/truth/StreamSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ protected String actualCustomStringRepresentation() {
return String.valueOf(asList);
}

/**
* Obsolete factory instance. This factory was previously necessary for assertions like {@code
* assertWithMessage(...).about(streams()).that(stream)....}. Now, you can perform assertions like
* that without the {@code about(...)} call.
*/
public static Subject.Factory<StreamSubject, Stream<?>> streams() {
return StreamSubject::new;
}
Expand Down
19 changes: 4 additions & 15 deletions core/src/main/java/com/google/common/truth/Truth8.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,12 @@
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* The primary entry point for assertions about Java 8 types.
* The obsolete entry point for assertions about Java 8 types.
*
* <p>To use {@link Truth#assertWithMessage} with a Java 8 type, use {@code
* assertWithMessage(...).about(}{@link OptionalSubject#optionals optionals()}{@code ).that(...)}
* (or similarly for the other types).
*
* <p>Likewise, to use different failure strategies like {@link Expect}, use {@code
* expect.about(}{@link OptionalSubject#optionals optionals()}{@code ).that(...)}.
*
* <p>For more information about combining different messages, failure strategies, and subjects, see
* <a href="https://truth.dev/faq#full-chain">How do I specify a custom message/failure
* behavior/{@code Subject} type?</a> in the Truth FAQ.
* @deprecated Instead of this class's methods, use the identical methods declared in the main
* {@link Truth} class.
*/
@Deprecated
// The methods here are no more dangerous that wherever the user got the (e.g.) Stream.
@SuppressWarnings("Java7ApiChecker")
public final class Truth8 {
Expand Down Expand Up @@ -75,10 +68,6 @@ public static LongStreamSubject assertThat(@Nullable LongStream target) {
return assertAbout(LongStreamSubject.longStreams()).that(target);
}

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

// Not actually a Java 8 feature, but for now this is the best option since core Truth still has
// to support Java environments without java.nio.file such as Android and J2CL.
@GwtIncompatible
@J2ObjCIncompatible
@J2ktIncompatible
Expand Down

0 comments on commit 1e9d4d8

Please sign in to comment.