Replace try-catch with assertDoesNotThrow in SuppressWarningFilterSeTest#115
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
Replace try-catch with assertDoesNotThrow in SuppressWarningFilterSeTest#115sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZ6v0pNt6JKQzmjWaP0J for java:S8714 rule Generated by SonarQube Agent (task: 57c6b129-5e48-47d3-a7e0-938c85cc2aa5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaced a try-catch block with assertDoesNotThrow() in a test method to improve readability and follow JUnit best practices. This also removes the unnecessary InvocationTargetException import that was only used in the deprecated pattern.
View Project in SonarCloud
Fixed Issues
java:S8714 - Use assertDoesNotThrow() instead of try/catch and fail() in the catch block. • MINOR • View issue
Location:
sonar-java-symbolic-execution:java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/filters/SuppressWarningFilterSeTest.java:165Why is this an issue?
Modern assertion libraries have made the clunky
try-fail-catchpattern obsolete by introducing cleaner alternatives. For example, starting with JUnit 5, JUnit Jupiter providesassertThrowsandassertDoesNotThrow. AssertJ offers similar methods.What changed
Removes the import of
InvocationTargetExceptionwhich is no longer needed after replacing the try-catch block withassertDoesNotThrow. The try-catch pattern that caughtInvocationTargetException(among other exceptions) and calledFail.fail()has been eliminated, so this import is no longer necessary.SonarQube Remediation Agent uses AI. Check for mistakes.