-
Notifications
You must be signed in to change notification settings - Fork 17
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
ExpectedException#expect() should take Matcher<? extends Throwable> as its argument #12
Comments
junit-team/junit4#1073 should also be considered when discussing this issue. |
This is definitely an improvement. The problem with instanceof and not(instanceof(...)) is that instanceof has the wrong signature, which will be fixed in Hamcrest eventually |
@npryce Should I open a pull request with the suggested changes? Considering the discussion in #11 and junit-team/junit4#1150: I'm not sure whether the changes would just be a small step in the "migration process" to having hamcrest-junit extend the "new" assertion-library-agnostic version of |
@UrsMetz I'm happy to do that. But for similar reasons to that bug, I believe that |
I just had a look at the code of |
FYI: The JUnit team just updated |
BTW, the title of this bug is wrong. You should mot modify |
This is a "re-post" of an issue originally opened at Junit: junit-team/junit4#610. As JUnit is going to depreciate and eventually remove
ExpectedException
I'm re-raising it hear in order to start a discussion whether this change should be made:Consider the following test:
When you have something like this in a test it can be quite hard to figure out why the test fails.
At the moment
ExpectedException#expect
takes aMatcher<?>
as its argument. By changing it to take only arguments of the typeMatcher<? extends Throwable>
the compiler could spot the mistake in the test given above.I tried the code changes needed for the suggested change in the API with the current master (92a3f73) and all tests pass.
I understand that these changes break the API and non-generic
Matcher
s won't work with the new signature of the method but is there any other reason not to haveExpectedException#expect
only take arguments of the typeMatcher<? extends Throwable>
?Apart from the exclusion of non-generic
Matcher
s the only downside I see is that now you have to specify the generic type: That is you have to write for exampleinstead of
The text was updated successfully, but these errors were encountered: