You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm testing a testing library which aside from hurting my brain I have a need to assert on the suppressed exceptions which are coming out attached to the exceptions my library throws.
This is a Java 7 feature, so I'm not sure how you'd go about exposing it without requiring that I do Truth8.assertThat(throwable), but being able to do this is far more useful than how exactly it works. Especially given that I no longer have access to the underlying Throwable from the subject to do something like assertThat(throwable.suppressed[0]).isSameInstanceAs(other).
The text was updated successfully, but these errors were encountered:
Thanks. I am shocked that I don't recall ever hearing a request for this before. Maybe I've just forgotten, but I at least don't think it's been a common request: Inside Google, assertions on the suppressed exceptions of a Throwable (manual ones, using getSuppressed()) appear to be less than a tenth of a percent as common as assertThat(Throwable) is.
We should someday have a look at what those people are doing. We have at least a couple decisions:
"Does it have a suppressed exception like X?" vs. "Return an IterableSubject with information about all suppressed exceptions"
Expose a suppressed-exception API solely in terms of Throwable or (also?) in terms of Class / String message?
suppressedExceptions(), suppressedExceptionTypes(), suppressedExceptionMessages() --
and/or maybe we'd provide Correspondence instances to let you operate directly on suppressedExceptions()?
Maybe enough users have only one suppressed exception that we can afford to provide ThrowableSubject suppressedException() that throws if there's more than one?
Yet another possibility is to go down this road:
publicMultipleSuppressedExceptionComparisonhasSuppressedExceptionThat() {
returnnewMultipleSuppressedExceptionComparison();
}
publicstaticfinalclassMultipleSuppressedExceptionComparison {
publicvoidisEqualTo(Throwableexpected) { ... }
publicvoidhasMessage(Stringmessage) { ... }
// or, to support regex, contains, etc.:publicMultipleSuppressedExceptionMessageComparisonhasMessageThat() { ... }
// similarly for causes, exception types, etc.
}
Such a "subject" (though not a true Subject) that stands in for multiple "actual values" is a line we haven't crossed so far.
I think I'm beginning to recall why we decided to wait for demand before pursuing this :)
(On the plus side, if we found API solutions that we're happy with, I'm fairly confident that we could hack reflective or other calls to getSuppressed() in so that this could live in ThrowableSubject itself.)
I'm testing a testing library which aside from hurting my brain I have a need to assert on the suppressed exceptions which are coming out attached to the exceptions my library throws.
This is a Java 7 feature, so I'm not sure how you'd go about exposing it without requiring that I do
Truth8.assertThat(throwable)
, but being able to do this is far more useful than how exactly it works. Especially given that I no longer have access to the underlyingThrowable
from the subject to do something likeassertThat(throwable.suppressed[0]).isSameInstanceAs(other)
.The text was updated successfully, but these errors were encountered: