From 2a1d0fb47ca6c5948b4a1bba9b12e6c1b6f2cf12 Mon Sep 17 00:00:00 2001 From: cpovirk Date: Wed, 25 Jun 2025 09:28:08 -0700 Subject: [PATCH] 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 --- .../CheckedProviderSubjectTest.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/extensions/testlib/test/com/google/inject/testing/throwingproviders/CheckedProviderSubjectTest.java b/extensions/testlib/test/com/google/inject/testing/throwingproviders/CheckedProviderSubjectTest.java index 045dbf93c4..391d796651 100644 --- a/extensions/testlib/test/com/google/inject/testing/throwingproviders/CheckedProviderSubjectTest.java +++ b/extensions/testlib/test/com/google/inject/testing/throwingproviders/CheckedProviderSubjectTest.java @@ -1,6 +1,6 @@ package com.google.inject.testing.throwingproviders; -import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.ExpectFailure.assertThat; import static com.google.inject.testing.throwingproviders.CheckedProviderSubject.assertThat; import com.google.common.truth.ExpectFailure; @@ -81,20 +81,29 @@ public void thrownException_threwUnexpected_expectFailure() { Class unexpected = UnsupportedOperationException.class; CheckedProvider provider = CheckedProviders.throwing(StringCheckedProvider.class, unexpected); - String message = - String.format( - "value of : checkedProvider.get()'s exception\n" - + "expected instance of: %s\n" - + "but was instance of : %s\n" - + "with value : %s\n" - + "checkedProvider was : %s", - SummerException.class.getName(), - UnsupportedOperationException.class.getName(), - UnsupportedOperationException.class.getName(), - getThrowingProviderName(UnsupportedOperationException.class.getName())); - expectWhenTesting().that(provider).thrownException().isInstanceOf(expected); - assertThat(expect.getFailure()).hasMessageThat().isEqualTo(message); + AssertionError e = expect.getFailure(); + assertThat(e) + .factKeys() + .containsExactly( + "value of", + "expected instance of", + "but was instance of", + "with value", + "checkedProvider was"); + assertThat(e).factValue("value of").isEqualTo("checkedProvider.get()'s exception"); + assertThat(e) + .factValue("expected instance of") + .isAnyOf(SummerException.class.getName(), SummerException.class.getCanonicalName()); + assertThat(e) + .factValue("but was instance of") + .isAnyOf( + UnsupportedOperationException.class.getName(), + UnsupportedOperationException.class.getSimpleName()); + assertThat(e).factValue("with value").isEqualTo(UnsupportedOperationException.class.getName()); + assertThat(e) + .factValue("checkedProvider was") + .isEqualTo(getThrowingProviderName(UnsupportedOperationException.class.getName())); } @Test