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

Recognize JUnit 5's @BeforeAll and @BeforeEach as initializers #73

Closed
michaelhixson opened this issue Dec 7, 2017 · 3 comments
Closed

Comments

@michaelhixson
Copy link
Contributor

NullAway should recognize JUnit 5's @BeforeAll and @BeforeEach as initializer annotations by default. Currently it recognizes JUnit 4's @Before and @BeforeClass, but in JUnit 5 these were renamed:

Since you provided the CustomInitializerAnnotations option, users can work around this by passing an argument to javac:

-XepOpt:NullAway:CustomInitializerAnnotations=org.junit.jupiter.api.BeforeAll,org.junit.jupiter.api.BeforeEach

...but I think it makes sense to support this by default so users don't have to do that.

Resolving this issue should be a matter of changing these lines:

static final ImmutableSet<String> DEFAULT_INITIALIZER_ANNOT =
ImmutableSet.of(
"org.junit.Before",
"org.junit.BeforeClass"); // + Anything with @Initializer as its "simple name"

to this:

static final ImmutableSet<String> DEFAULT_INITIALIZER_ANNOT =
    ImmutableSet.of(
        "org.junit.Before",
        "org.junit.BeforeClass",
        "org.junit.jupiter.api.BeforeAll",
        "org.junit.jupiter.api.BeforeEach");

Adding test cases could be awkward since you'd need to bring in a JUnit 5 dependency probably? Or you could not add tests.

@msridhar
Copy link
Collaborator

msridhar commented Dec 7, 2017

@michaelhixson looks like a good change. Could you submit a PR with the change? Tests not required.

@michaelhixson
Copy link
Contributor Author

@msridhar I'm not comfortable with signing the CLA, so I closed the PR. Sorry for the noise. I still think the change is a good idea though.

@msridhar
Copy link
Collaborator

@michaelhixson can you contact me 1-1 (email on my website, linked from my profile)? Wanted to follow up briefly on the CLA issues. Thanks!

msridhar added a commit that referenced this issue Dec 14, 2017
Support @beforeeach and @BeforeAll as initializer annotations, and @Inject and @lazyinit as excluded field annotations.

Fixes #73, #64
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

No branches or pull requests

2 participants