Add test for new `Expect` "value of" support.
(followup to cl/487936519)
RELNOTES=n/a
@@ -17,6 +17,8 @@ package com.google.common.truth;
import static com.google.common.truth.ExpectFailure.assertThat;
import static com.google.common.truth.ExpectFailure.expectFailure;
+import static org.junit.Assert.assertThrows;
+import static org.junit.runner.Description.createTestDescription;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.collect.ImmutableList;
@@ -24,6 +26,7 @@ import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
+import org.junit.runners.model.Statement;
/** Tests for {@link ActualValueInference}. */
@GwtIncompatible // Inference doesn't work under GWT.
@@ -180,6 +183,26 @@ public final class ActualValueInferenceTest {
assertThat(failure).factKeys().doesNotContain("value of");
}
+ @Test
+ public void expect() {
+ Expect expect = Expect.create();
+ Statement testMethod =
+ new Statement() {
+ @Override
+ public void evaluate() {
+ expect.that(staticNoArg()).isEqualTo("b");
+ }
+ };
+ Statement wrapped = expect.apply(testMethod, createTestDescription("MyTest", "myMethod"));
+ AssertionError failure = assertThrows(AssertionError.class, wrapped::evaluate);
+ /*
+ * We can't use factValue here because Expect throws a plain wrapper AssertionError, not the
+ * original ErrorWithFacts. We could in theory change that someday, perhaps as part of a
+ * followup to https://github.com/google/truth/issues/543, but it seems unlikely.
+ */
+ assertThat(failure).hasMessageThat().contains("staticNoArg()");
+ }
+
static String staticNoArg() {
return "a";
}
