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

This is a fix for #83 support @Rule on methods #325

Merged
merged 1 commit into from Sep 23, 2011
Merged

This is a fix for #83 support @Rule on methods #325

merged 1 commit into from Sep 23, 2011

Conversation

matthewfarwell
Copy link
Contributor

Extend rules to support @rule public MethodRule someRule() { return new SomeRule(); }

Scala does not allow the creation of public fields. If you declare a field public, the field is created as private but with accessor methods.
To allow the use of @rule with Scala fields, this patch allows the addition
of @rule to methods. When BlockJUnit4ClassRunner retrieves the list of fields
that have the @rule annotation, it also searches for methods with @rule.
These methods are called and the values returned are added to the list of
TestRule.

@ClassRule has been similarly changed.

This is intended to be used as follows:

private ExpectedException thrown = rules.ExpectedException.none();

@rule public ExpectedException getThrown() {
return thrown;
}

or

@rule public Timeout getTimeout() {
return new Timeout(20);
}

The validation is exactly the same as for the fields, i.e the methods must be
public and return a TestRule/MethodRule. In the case of @ClassRule, the
methods must also be static.

Extend rules to support @rule public MethodRule someRule() { return new SomeRule(); }

Scala does not allow the creation of public fields. If you declare a field public, the field is created as private but with accessor methods.
To allow the use of @rule with Scala fields, this patch allows the addition
of @rule to methods. When BlockJUnit4ClassRunner retrieves the list of fields
that have the @rule annotation, it also searches for methods with @rule.
These methods are called and the values returned are added to the list of
TestRule.

@ClassRule has been similarly changed.

This is intended to be used as follows:

private ExpectedException thrown = rules.ExpectedException.none();

@rule public ExpectedException getThrown() {
    return thrown;
}

or

@rule public Timeout getTimeout() {
    return new Timeout(20);
}

The validation is exactly the same as for the fields, i.e the methods must be
public and return a TestRule/MethodRule. In the case of @ClassRule, the
methods must also be static.
@matthewfarwell
Copy link
Contributor Author

This is a merged commit with the changes from https://github.com/KentBeck/junit/pull/306. I've created the new pull request because I was having problems with the git rebase, but the changes are the same. I'll close the other one when it's no longer necessary.

This is merged into master.

dsaff added a commit that referenced this pull request Sep 23, 2011
@dsaff dsaff merged commit 1660ebd into junit-team:master Sep 23, 2011
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

2 participants