-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Matching on exact class type, not a subtype #1230
Comments
Thanks. I am always a little nervous to add new APIs, especially to
Its functionality is probably not quite as compelling as The big question, as you point out, is how many (One thing for us to remember with a new method is to cover it with static analysis: At least " (I want to say that I was just thinking about this exact proposal for some reason earlier in the week... Ah, it must have been related to the idea that the failure message would ideally say something like |
Ooo a chainable method that qualifies the assertion like Can't be that hard to put a synthetic For now I'm just leaving a comment with |
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 traditionalisInstanceOf
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?The text was updated successfully, but these errors were encountered: