From 27f01d02f518d164cea84ea37d62ae351c689c87 Mon Sep 17 00:00:00 2001 From: cpovirk Date: Fri, 4 Aug 2017 11:11:31 -0700 Subject: [PATCH] Hide ExpectationGatherer. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=164284459 --- .../java/com/google/common/truth/Expect.java | 16 +++++++++++++++- .../truth/ExpectFailureWithStackTraceTest.java | 18 +++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/com/google/common/truth/Expect.java b/core/src/main/java/com/google/common/truth/Expect.java index fcc4466f1..9b83f1bca 100644 --- a/core/src/main/java/com/google/common/truth/Expect.java +++ b/core/src/main/java/com/google/common/truth/Expect.java @@ -30,7 +30,15 @@ import org.junit.runners.model.Statement; @GwtIncompatible("JUnit4") -public class Expect extends TestVerb implements TestRule { +public final class Expect extends TestVerb implements TestRule { + /** + * @deprecated To provide your own failure handling, use {@code new TestVerb(new + * AbstractFailureStrategy() { ... })} instead of {@code Expect.create(new + * ExpectationGatherer() { ... })}. Or, if you're testing that assertions on a custom {@code + * Subject} fail (using {@code ExpectationGatherer} to capture the failures), use {@link + * ExpectFailure}. + */ + @Deprecated public static class ExpectationGatherer extends AbstractFailureStrategy { private final List messages = new ArrayList(); private final boolean showStackTrace; @@ -131,6 +139,12 @@ public static Expect create() { return create(new ExpectationGatherer()); } + /** + * @deprecated To provide your own failure handling, use {@code new TestVerb(new + * AbstractFailureStrategy() { ... })} instead of {@code Expect.create(new + * ExpectationGatherer() { ... })}. + */ + @Deprecated public static Expect create(ExpectationGatherer gatherer) { return new Expect(gatherer); } diff --git a/core/src/test/java/com/google/common/truth/ExpectFailureWithStackTraceTest.java b/core/src/test/java/com/google/common/truth/ExpectFailureWithStackTraceTest.java index 619883fd5..5a31c62d2 100644 --- a/core/src/test/java/com/google/common/truth/ExpectFailureWithStackTraceTest.java +++ b/core/src/test/java/com/google/common/truth/ExpectFailureWithStackTraceTest.java @@ -17,9 +17,9 @@ import static com.google.common.truth.Truth.assertThat; -import com.google.common.truth.Expect.ExpectationGatherer; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -30,25 +30,21 @@ public class ExpectFailureWithStackTraceTest { private static final String METHOD_NAME = "ExpectFailureWithStackTraceTest.expectTwoFailures"; - @Rule - public final Expect failToExpect = - new FailingExpect(new ExpectationGatherer(true /* showStackTrace */)); + @Rule public final FailingExpect failToExpect = new FailingExpect(); @Test public void expectTwoFailures() { - failToExpect.that(4).isNotEqualTo(4); - failToExpect.that("abc").contains("x"); + failToExpect.delegate.that(4).isNotEqualTo(4); + failToExpect.delegate.that("abc").contains("x"); } /** Expect class that can examine the error message */ - public static class FailingExpect extends Expect { - protected FailingExpect(ExpectationGatherer gatherer) { - super(gatherer); - } + public static class FailingExpect implements TestRule { + final Expect delegate = Expect.createAndEnableStackTrace(); @Override public Statement apply(Statement base, Description description) { - final Statement s = super.apply(base, description); + final Statement s = delegate.apply(base, description); return new Statement() { @Override public void evaluate() throws Throwable {