Skip to content

Commit

Permalink
Hide ExpectationGatherer.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=164284459
  • Loading branch information
cpovirk authored and ronshapiro committed Aug 7, 2017
1 parent 3b355a1 commit 27f01d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
16 changes: 15 additions & 1 deletion core/src/main/java/com/google/common/truth/Expect.java
Expand Up @@ -30,7 +30,15 @@
import org.junit.runners.model.Statement; import org.junit.runners.model.Statement;


@GwtIncompatible("JUnit4") @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 { public static class ExpectationGatherer extends AbstractFailureStrategy {
private final List<ExpectationFailure> messages = new ArrayList<ExpectationFailure>(); private final List<ExpectationFailure> messages = new ArrayList<ExpectationFailure>();
private final boolean showStackTrace; private final boolean showStackTrace;
Expand Down Expand Up @@ -131,6 +139,12 @@ public static Expect create() {
return create(new ExpectationGatherer()); 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) { public static Expect create(ExpectationGatherer gatherer) {
return new Expect(gatherer); return new Expect(gatherer);
} }
Expand Down
Expand Up @@ -17,9 +17,9 @@


import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;


import com.google.common.truth.Expect.ExpectationGatherer;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.Description; import org.junit.runner.Description;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
Expand All @@ -30,25 +30,21 @@
public class ExpectFailureWithStackTraceTest { public class ExpectFailureWithStackTraceTest {
private static final String METHOD_NAME = "ExpectFailureWithStackTraceTest.expectTwoFailures"; private static final String METHOD_NAME = "ExpectFailureWithStackTraceTest.expectTwoFailures";


@Rule @Rule public final FailingExpect failToExpect = new FailingExpect();
public final Expect failToExpect =
new FailingExpect(new ExpectationGatherer(true /* showStackTrace */));


@Test @Test
public void expectTwoFailures() { public void expectTwoFailures() {
failToExpect.that(4).isNotEqualTo(4); failToExpect.delegate.that(4).isNotEqualTo(4);
failToExpect.that("abc").contains("x"); failToExpect.delegate.that("abc").contains("x");
} }


/** Expect class that can examine the error message */ /** Expect class that can examine the error message */
public static class FailingExpect extends Expect { public static class FailingExpect implements TestRule {
protected FailingExpect(ExpectationGatherer gatherer) { final Expect delegate = Expect.createAndEnableStackTrace();
super(gatherer);
}


@Override @Override
public Statement apply(Statement base, Description description) { public Statement apply(Statement base, Description description) {
final Statement s = super.apply(base, description); final Statement s = delegate.apply(base, description);
return new Statement() { return new Statement() {
@Override @Override
public void evaluate() throws Throwable { public void evaluate() throws Throwable {
Expand Down

0 comments on commit 27f01d0

Please sign in to comment.