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
Comment From: rstoyanchev
Seems reasonable outside of spring-test.
Comment From: sbrannen
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?
Comment From: sbrannen
Reopening for the potential inclusion of a Checkstyle rule to prevent this in the future.
Comment From: sbrannen
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.
Comment From: sbrannen
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?
Comment From: sbrannen
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.Assertandorg.junit.Assumein 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.
Comment From: sbrannen
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.
Comment From: sbrannen
Closing this issue since the new Checkstyle rules will be addressed in #22962.