Skip to content
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

Extend ExpectedException's documentation and fix #687. #720

Merged
merged 3 commits into from
Oct 16, 2013

Conversation

stefanbirkner
Copy link
Contributor

No description provided.

@@ -199,19 +325,27 @@ private void optionallyHandleException(Throwable e, boolean handleException)
throws Throwable {
if (handleException) {
handleException(e);
} else {
} else if (!isExpectedException(e)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed this, which is the essential line of the pull. Nice.

@dsaff
Copy link
Member

dsaff commented Aug 20, 2013

I wonder how you'd feel about deprecating the explicit handleAssertion and handleAssumption methods, in favor of a single dontWrap(Matcher). (where the default dont-wrap matcher would be the current default of all AssertionErrors and AssumptionExceptions). This has two advantages:

  1. More flexible if people are using a framework that assigns meaning to some other exception.
  2. Hopefully takes up less "mental space" in the documentation and API--it's one method to change a particular setting, rather than 2 that configure 2 orthogonal ideas.

@stefanbirkner
Copy link
Contributor Author

I tried the dontWrap method, but unfortunately its makes the API and documentation harder to understand. Therefore I would propose to do without this method. I don't think that there are many people who need this improvement for their JUnit extensions. Do you know an extension, which uses an additional Exception for framework communication?

@stefanbirkner
Copy link
Contributor Author

I think we should revert 128553f. Whenever you have a test that uses ExpectedException together with assumeXXX or assertXXX, you can but the assume or assert before the thrown.expectXXX call and everything works like expected.

I recommend to add this to ExpectedException's documentation and revert the change. @dsaff How to you think about it?

@dsaff
Copy link
Member

dsaff commented Sep 3, 2013

Works for me, @stefanbirkner. Sorry for the delay in communication.

@stefanbirkner
Copy link
Contributor Author

@dsaff It's ready.

* public ExpectedException thrown= ExpectedException.none();
* <p>
* You can combine any of the presented expect-methods. The test is
* successful if all specifictions are met.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check spelling

@dsaff
Copy link
Member

dsaff commented Sep 16, 2013

Looking good. Added some minor changes to the javadoc.

private String missingExceptionMessage;

private ExpectedException() {
}

public ExpectedException handleAssertionErrors() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it's very unusual for us to remove abruptly a method that was already in a public release of JUnit. We should probably leave these in, deprecated, with no implementation and javadoc about how things have changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I restored the methods. They now throw an exception in order to notify the user about the deprecation.

@stefanbirkner
Copy link
Contributor Author

@dsaff I'd like to squash the new commits if everything is fine.

@dsaff
Copy link
Member

dsaff commented Sep 18, 2013

@stefanbirkner, I think it makes more sense to leave them as deprecated no-op methods: people who called them were explicitly requesting the behavior that will now be default, right?

@stefanbirkner
Copy link
Contributor Author

That's right. But people, who use this methods, are testing code that's throwing AssertionErrors or AssumptionViolatedExceptions. Therefore they have to adjust their tests, because the default behaviour of ExpectedException changed, too.

IMHO we have to choose between three alternatives:

  1. Change the methods to deprecated no-op methods: We have useless and irritating methods in ExpectedException's API, but all affected users still have to adjust their tests after upgrading to JUnit 4.12 (see explanation above).
  2. Remove the methods: Update to JUnit 4.12 causes compiler errors and users will be cursing us, because they have no idea what's wrong.
  3. Deprecate methods and let them throw errors: Update to JUnit 4.12 causes failing tests. People still will be cursing us, but we give them a hint about what we've done. Afterwards (~ a year) we can remove the methods, because all the people, which are updating regularly, have already removed calls to the method.

I still prefer alternative 3, because it's a good trade-off between lesser code to maintain and upsetting the users.

@dsaff
Copy link
Member

dsaff commented Oct 1, 2013

Sorry, I'm probably just dense tonight. Given this test:

    @Test
    public void catchIt() {
        thrown.handleAssertionErrors();
        thrown.expect(AssertionError.class);
        throw new AssertionError("the unexpected assertion error");
    }

It works in 4.11, and if handleAssertionErrors is a no-op, it works in 4.12, too, right?

@stefanbirkner
Copy link
Contributor Author

That's true. I was wrong with the first alternative. Nobody has to change his methods, if we use no-op methods. The correct first alternative is.

  1. Change the methods to deprecated no-op methods: We have useless and irritating methods in ExpectedException's API.

This means that we must decide, whether we would like to leave the methods forever or not.

@dsaff
Copy link
Member

dsaff commented Oct 4, 2013

@stefanbirkner, we don't actually have to decide today whether we would like to leave the methods forever.

However, it's generally considered kind to give users at least a revision of deprecation warnings before causing their tests to stop compiling. We should leave them in, deprecated, in this release. If no one complains, we can remove them in the next release.

@stefanbirkner
Copy link
Contributor Author

Done. Should i prepare the commits for merging?

@UrsMetz
Copy link
Contributor

UrsMetz commented Oct 5, 2013

Shouldn't we have test cases for the special exception type AssertionError as that Throwable is an edge case in the context of JUnit? There was a bug in 4.11 that when an AssertionError was expected but not thrown the test was not red but green, cf. pull request #583. So I think test covering the case when that exception is expected but not thrown should be included (for AssumptionViolationException there is such an test case). Maybe also the "green" cases (e. g. the expected exceptions are actually thrown) should be included.

@stefanbirkner
Copy link
Contributor Author

I'm not sure whether we need additional tests, because AssumptionViolationException and AssertionError are now handled like any other exception. Changing the AssertionError behaviour in 4.11 was not an accident but an explicit (bad) decision of mine.

@UrsMetz
Copy link
Contributor

UrsMetz commented Oct 6, 2013

@stefanbirkner I think we're talking about different changes in 4.11 :-): I'm referring to the bug described in #583 (that also you stumbled across according to your comment in the discussion there :-)).
I understand that viewed from the implementation side (now) AssertionError is not handled differently than any other Throwable but as

  1. AssertionError is still a special case in the context of JUnit tests and
  2. there was a bug that the ExpectedException rule didn't make a test fail when an expected AssertionError was not thrown (ExpectedException doesn't fail when an AssertionError is expected but not thrown #583)
    I think we should have at least a test case for the bug ExpectedException doesn't fail when an AssertionError is expected but not thrown #583. I included that test case in ExpectedException doesn't fail when an AssertionError is expected but not thrown #583 but I didn't find it in the version of ExpectedExceptionTest.java in the branch you want to merge.

@dsaff
Copy link
Member

dsaff commented Oct 13, 2013

@UrsMetz, did @stefanbirkner's latest test handle your concern?

@UrsMetz
Copy link
Contributor

UrsMetz commented Oct 15, 2013

@dsaff: my concern was handled by @stefanbirkner's last commit.

Describe every expect method with a single test.
Still fixes junit-team#121, but the original fix was superfluous. Added documentation
about handling assumes and asserts in conjunction with the
ExpectedException rule.
Improve readability and avoid duplicate code.
@stefanbirkner
Copy link
Contributor Author

@dsaff I squashed the commits. Everything should be ready for the merge.

dsaff pushed a commit that referenced this pull request Oct 16, 2013
Extend ExpectedException's documentation and fix #687.
@dsaff dsaff merged commit 0f623cd into junit-team:master Oct 16, 2013
@dsaff
Copy link
Member

dsaff commented Oct 16, 2013

Done! Thanks!

Can you make a note at https://github.com/junit-team/junit/wiki/4.12-release-notes

@stefanbirkner stefanbirkner deleted the expected-exception branch October 16, 2013 23:00
@stefanbirkner
Copy link
Contributor Author

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants