Factor out some common object mocking in tests
Hi there,
This PR is to address issue #14768, which involves reducing repeated mock object creation in tests.
I mistakenly closed PR #15256 and then discovered that I do not have permission to reopen it, receiving the message this branch was force pushed or recreated. I'm not sure if I should reopen the original or create this new PR
Although my issue submission mentioned 4 separate draft PRs, I combined them into this PR, since they all address the same problem.
@jesperronn Please feel free to let me know if there is anything I need to change. I look forward to your suggestions.
Thanks for the cleanup, @gzhao9. I think there is already a
MockSecurityContextHolderStrategyavailable inspring-security-core. Can you please enhance that instead?I think it would be reasonable to add the default constructor and one that takes a
SecurityContextto that class.Please also run
./gradlew format && ./gradlew checkbefore committing next. It appears there are some formatting issues that those two tasks will help you work through.When you are done, will you please change your commits to be more descriptive in the following way. For each commit, describe what you've done and include the issue number like so:
Use MockSecurityContextHolderStrategy Issue gh-14768For the final commit, please use
Closes gh-14768instead as this integrates with our build system to close the issue automatically.
I found MockSecurityContextHolderStrategy in spring-security-core. However, since they are not in the same package, I would need to change the dependency if I want to reference MockSecurityContextHolderStrategy in org.springframework.security.authorization.method. I believe adding new dependencies should be considered carefully. Therefore, I only added a private method in each test class.
I first focus on each file code modification. I will rebase commits when there is no need to modify the code or format.
Thanks for the updates, @gzhao9! I think there are two other items from the review that haven't been addressed yet. Are you able to do those as well?
Thanks for the updates, @gzhao9! I think there are two other items from the review that haven't been addressed yet. Are you able to do those as well?
I have modified the code as required.
Thanks, @gzhao9! This is now merged into main.