Skip to content

Commit 2a1d0fb

Browse files
cpovirkGuice Team
authored andcommitted
Prepare for changes in how Truth prints class names.
Truth will soon: - print only the simple name for some well-known classes (e.g., print "NullPointerException" instead of "java.lang.NullPointerException") - print the canonical name where available instead of the binary name (e.g., print "com.google.Foo.BarException" instead of "com.google.Foo$BarException" This CL updates callers to accept both versions. RELNOTES=n/a PiperOrigin-RevId: 775721999
1 parent 5e17283 commit 2a1d0fb

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

extensions/testlib/test/com/google/inject/testing/throwingproviders/CheckedProviderSubjectTest.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.google.inject.testing.throwingproviders;
22

3-
import static com.google.common.truth.Truth.assertThat;
3+
import static com.google.common.truth.ExpectFailure.assertThat;
44
import static com.google.inject.testing.throwingproviders.CheckedProviderSubject.assertThat;
55

66
import com.google.common.truth.ExpectFailure;
@@ -81,20 +81,29 @@ public void thrownException_threwUnexpected_expectFailure() {
8181
Class<? extends Throwable> unexpected = UnsupportedOperationException.class;
8282
CheckedProvider<String> provider =
8383
CheckedProviders.throwing(StringCheckedProvider.class, unexpected);
84-
String message =
85-
String.format(
86-
"value of : checkedProvider.get()'s exception\n"
87-
+ "expected instance of: %s\n"
88-
+ "but was instance of : %s\n"
89-
+ "with value : %s\n"
90-
+ "checkedProvider was : %s",
91-
SummerException.class.getName(),
92-
UnsupportedOperationException.class.getName(),
93-
UnsupportedOperationException.class.getName(),
94-
getThrowingProviderName(UnsupportedOperationException.class.getName()));
95-
9684
expectWhenTesting().that(provider).thrownException().isInstanceOf(expected);
97-
assertThat(expect.getFailure()).hasMessageThat().isEqualTo(message);
85+
AssertionError e = expect.getFailure();
86+
assertThat(e)
87+
.factKeys()
88+
.containsExactly(
89+
"value of",
90+
"expected instance of",
91+
"but was instance of",
92+
"with value",
93+
"checkedProvider was");
94+
assertThat(e).factValue("value of").isEqualTo("checkedProvider.get()'s exception");
95+
assertThat(e)
96+
.factValue("expected instance of")
97+
.isAnyOf(SummerException.class.getName(), SummerException.class.getCanonicalName());
98+
assertThat(e)
99+
.factValue("but was instance of")
100+
.isAnyOf(
101+
UnsupportedOperationException.class.getName(),
102+
UnsupportedOperationException.class.getSimpleName());
103+
assertThat(e).factValue("with value").isEqualTo(UnsupportedOperationException.class.getName());
104+
assertThat(e)
105+
.factValue("checkedProvider was")
106+
.isEqualTo(getThrowingProviderName(UnsupportedOperationException.class.getName()));
98107
}
99108

100109
@Test

0 commit comments

Comments
 (0)