Skip to content

HeaderResultMatchers should not import org.junit.Assert #22932

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

Closed
philwebb opened this issue May 9, 2019 · 8 comments
Closed

HeaderResultMatchers should not import org.junit.Assert #22932

philwebb opened this issue May 9, 2019 · 8 comments
Assignees
Labels
in: test Issues in the test module type: regression A bug that is also a regression
Milestone

Comments

@philwebb
Copy link
Member

philwebb commented May 9, 2019

It looks like HeaderResultMatchers is accidentally importing org.junit.Assert.assertNotNull rather than our own org.springframework.test.util.AssertionErrors.

I wonder if we can put a checkstyle rule to prevent junit imports in src/main

@rstoyanchev
Copy link
Contributor

Seems reasonable outside of spring-test.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 9, 2019
@sbrannen sbrannen added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 11, 2019
@sbrannen
Copy link
Member

I agree.

I'll fix the import and implement assertNotNull() in our own AssertionErrors.

As for the checkstyle rule only applied to src/main, @philwebb do you want to do that, or shall I pick that up as well?

@sbrannen sbrannen added this to the 5.2 M3 milestone May 11, 2019
@sbrannen sbrannen self-assigned this May 11, 2019
@sbrannen sbrannen modified the milestones: 5.2 M3, 5.1.8 May 11, 2019
@sbrannen sbrannen added in: test Issues in the test module type: bug A general bug and removed type: task A general task labels May 11, 2019
@sbrannen
Copy link
Member

Reopening for the potential inclusion of a Checkstyle rule to prevent this in the future.

@sbrannen sbrannen reopened this May 11, 2019
sbrannen added a commit that referenced this issue May 11, 2019
@sbrannen
Copy link
Member

Seems reasonable outside of spring-test.

You're right that we cannot disallow the use of JUnit in general in src/main in spring-test, but we should likely forbid the use of org.junit.Assert in src/main in spring-test if it's feasible with Checkstyle.

@sbrannen
Copy link
Member

Recently I've seen code like Assert.assertEquals(...);

So I've also been considering introducing a Checkstyle rule that forbids non-static imports of org.junit.Assert and org.junit.Assume in test classes, since we really should be consistently using static imports for those methods.

@philwebb would you like to tackle that one, too?

@sbrannen
Copy link
Member

Recently I've seen code like Assert.assertEquals(...);

So I've also been considering introducing a Checkstyle rule that forbids non-static imports of org.junit.Assert and org.junit.Assume in test classes, since we really should be consistently using static imports for those methods.

@philwebb would you like to tackle that one, too?

Never mind: I'm tackling that one on my own.

sbrannen added a commit to sbrannen/spring-framework that referenced this issue May 12, 2019
This commit configures Checkstyle to enforces static imports for JUnit 4
assertions and assumptions.

See spring-projectsgh-22932
@jhoeller jhoeller added type: enhancement A general enhancement and removed type: bug A general bug labels May 13, 2019
@sbrannen sbrannen added type: bug A general bug type: regression A bug that is also a regression and removed type: enhancement A general enhancement labels May 13, 2019
@sbrannen
Copy link
Member

Seems reasonable outside of spring-test.

Actually, now that I think about it... it shouldn't be possible for any project other than spring-test to use JUnit APIs in src/main since all other projects don't have junit:junit as a compile-time dependency.

@sbrannen
Copy link
Member

Closing this issue since the new Checkstyle rules will be addressed in #22962.

@snicoll snicoll removed the type: bug A general bug label May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

6 participants