-
Notifications
You must be signed in to change notification settings - Fork 267
Description
I'm testing some library APIs which throw various exceptions that are documented as part of its API contract. However, some of the exceptions are subtypes of each other. I want to assert that an exception subject is an instance of a precise type and not some subtype.
Now I can do assertThat(e.getClass()).isEqualTo(SomeException.class);, sure, but that does not communicate my intent well. An innocent passer-by might see that, assume I don't know the Truth APIs well, and helpfully rewrite that into a traditional isInstanceOf not realizing that they're actually relaxing the constraint.
AssertJ has isExactlyInstanceOf which is pretty spot on here, and I think communicates intent well. I tried quickly thinking of other names but didn't find any that compelling (hasClassEqualTo 🤢).
Thoughts? Find anyone doing assertThat(x.getClass()) in google3?