From 227b559edd0ccd0ca0d3daa72693bcb720240b86 Mon Sep 17 00:00:00 2001 From: cpovirk Date: Wed, 19 Jun 2019 12:44:15 -0700 Subject: [PATCH] Deprecate `Optional*Subject.hasValueThat()` and the overload of `StandardSubjectBuilder.fail(...)` that accepts a message. Relnotes: Deprecated the overload of `StandardSubjectBuilder.fail(...)` that accepts a message. Instead of `assert_().fail(...)`, use `assertWithMessage(...).fail()`. Similarly, instead of `expect.fail(...)`, use `expect.withMessage(...).fail()`, and so forth. Deprecated `Optional*Subject.hasValueThat()`. Instead of `assertThat(optional).hasValueThat()....`, use `assertThat(optional.getAs*())....`. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=254050317 --- .../google/common/truth/StandardSubjectBuilder.java | 11 +++++++++-- .../google/common/truth/OptionalDoubleSubject.java | 6 +++++- .../com/google/common/truth/OptionalIntSubject.java | 6 +++++- .../com/google/common/truth/OptionalLongSubject.java | 6 +++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java b/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java index 7ffdf5b24..568efd7b8 100644 --- a/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java +++ b/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java @@ -220,12 +220,19 @@ public final CustomSubjectB return factory.createSubjectBuilder(metadata()); } - /** Triggers the failure strategy with an empty failure message */ + /** Triggers the failure strategy with an empty failure message. */ public final void fail() { doFail(""); } - /** Triggers the failure strategy with the given failure message */ + /** + * Triggers the failure strategy with the given failure message. + * + * @deprecated Instead of {@code assert_().fail(...)}, use {@code assertWithMessage(...).fail()}. + * Similarly, instead of {@code expect.fail(...)}, use {@code expect.withMessage(...).fail()}, + * and so forth. + */ + @Deprecated public final void fail(@NullableDecl String format, Object /*@NullableDeclType*/... args) { doFail(lenientFormat(format, args)); } diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java b/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java index 36b625f15..371e87d43 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java @@ -81,7 +81,11 @@ public void hasValue(double expected) { /** * Prepares for a check regarding the value contained within the {@link OptionalDouble}. Fails * immediately if the subject is empty. - */ + * + * @deprecated Instead of {@code assertThat(optional).hasValueThat()....}, use {@code + * assertThat(optional.getAsDouble())....}. + */ + @Deprecated public DoubleSubject hasValueThat() { if (actual == null || !actual.isPresent()) { isPresent(); // fails diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java b/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java index 1edfaaad6..9692cd78b 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java @@ -74,7 +74,11 @@ public void hasValue(int expected) { /** * Prepares for a check regarding the value contained within the {@link OptionalInt}. Fails * immediately if the subject is empty. - */ + * + * @deprecated Instead of {@code assertThat(optional).hasValueThat()....}, use {@code + * assertThat(optional.getAsInt())....}. + */ + @Deprecated public IntegerSubject hasValueThat() { if (actual == null || !actual.isPresent()) { isPresent(); // fails diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java b/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java index 532448d3f..5c6dcfced 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java @@ -74,7 +74,11 @@ public void hasValue(long expected) { /** * Prepares for a check regarding the value contained within the {@link OptionalLong}. Fails * immediately if the subject is empty. - */ + * + * @deprecated Instead of {@code assertThat(optional).hasValueThat()....}, use {@code + * assertThat(optional.getAsLong())....}. + */ + @Deprecated public LongSubject hasValueThat() { if (actual == null || !actual.isPresent()) { isPresent(); // fails