Skip to content

Replace try-catch-fail patterns with AssertJ assertions in ExplodedGraphWalkerTest#114

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260612-050242-00fb7ec4
Open

Replace try-catch-fail patterns with AssertJ assertions in ExplodedGraphWalkerTest#114
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260612-050242-00fb7ec4

Conversation

@sonarqube-agent

Copy link
Copy Markdown
Contributor

This PR was automatically created by the Remediation Agent's Scheduled backlog remediation feature.

Why these issues? All five SonarQube issues are MINOR severity, style-oriented rules located in test files rather than production code. The changes modernize test assertions to use idiomatic AssertJ patterns, which improves code clarity without affecting functionality.

Replaces five instances of try-catch-fail patterns with proper AssertJ assertion methods (assertThatCode().doesNotThrowAnyException() and assertThatThrownBy()) in the test file. This improves test code readability and maintainability by using modern assertion APIs that more clearly express intent.

View Project in SonarCloud


Fixed Issues

java:S8714 - Use assertDoesNotThrow() instead of try/catch and fail() in the catch block. • MINORView issue

Location: sonar-java-symbolic-execution:java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java:302

Why is this an issue?

Modern assertion libraries have made the clunky try-fail-catch pattern obsolete by introducing cleaner alternatives. For example, starting with JUnit 5, JUnit Jupiter provides assertThrows and assertDoesNotThrow. AssertJ offers similar methods.

What changed

Adds the import for assertThatCode from AssertJ, which is needed by other hunks that replace try-catch-fail patterns with assertThatCode(...).doesNotThrowAnyException(). This directly supports fixing the issue at line 302 where a try-catch with fail() in the catch block was used to verify no exception is thrown.

--- a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java
+++ b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java
@@ -67,0 +68,1 @@ import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
java:S8714 - Use assertThrows() instead of try/catch and fail() in the try block. • MINORView issue

Location: sonar-java-symbolic-execution:java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java:362

Why is this an issue?

Modern assertion libraries have made the clunky try-fail-catch pattern obsolete by introducing cleaner alternatives. For example, starting with JUnit 5, JUnit Jupiter provides assertThrows and assertDoesNotThrow. AssertJ offers similar methods.

What changed

Removes the import of fail from AssertJ, since all usages of fail() in try-catch blocks have been replaced with proper assertion methods (assertThatCode and assertThatThrownBy). This cleanup supports all five issues where try-catch-fail patterns were flagged as code smells.

--- a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java
+++ b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java
@@ -69,1 +69,0 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.assertj.core.api.Assertions.fail;
java:S8714 - Use assertThrows() instead of try/catch and fail() in the try block. • MINORView issue

Location: sonar-java-symbolic-execution:java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java:362

Why is this an issue?

Modern assertion libraries have made the clunky try-fail-catch pattern obsolete by introducing cleaner alternatives. For example, starting with JUnit 5, JUnit Jupiter provides assertThrows and assertDoesNotThrow. AssertJ offers similar methods.

What changed

Removes the import of fail from AssertJ, since all usages of fail() in try-catch blocks have been replaced with proper assertion methods (assertThatCode and assertThatThrownBy). This cleanup supports all five issues where try-catch-fail patterns were flagged as code smells.

--- a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java
+++ b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java
@@ -69,1 +69,0 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.assertj.core.api.Assertions.fail;
java:S8714 - Use assertThrows() instead of try/catch and fail() in the try block. • MINORView issue

Location: sonar-java-symbolic-execution:java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java:392

Why is this an issue?

Modern assertion libraries have made the clunky try-fail-catch pattern obsolete by introducing cleaner alternatives. For example, starting with JUnit 5, JUnit Jupiter provides assertThrows and assertDoesNotThrow. AssertJ offers similar methods.

What changed

Removes the import of fail from AssertJ, since all usages of fail() in try-catch blocks have been replaced with proper assertion methods (assertThatCode and assertThatThrownBy). This cleanup supports all five issues where try-catch-fail patterns were flagged as code smells.

--- a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java
+++ b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java
@@ -69,1 +69,0 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.assertj.core.api.Assertions.fail;
java:S8714 - Use assertThrows() instead of try/catch and fail() in the try block. • MINORView issue

Location: sonar-java-symbolic-execution:java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java:392

Why is this an issue?

Modern assertion libraries have made the clunky try-fail-catch pattern obsolete by introducing cleaner alternatives. For example, starting with JUnit 5, JUnit Jupiter provides assertThrows and assertDoesNotThrow. AssertJ offers similar methods.

What changed

Removes the import of fail from AssertJ, since all usages of fail() in try-catch blocks have been replaced with proper assertion methods (assertThatCode and assertThatThrownBy). This cleanup supports all five issues where try-catch-fail patterns were flagged as code smells.

--- a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java
+++ b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/ExplodedGraphWalkerTest.java
@@ -69,1 +69,0 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.assertj.core.api.Assertions.fail;

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ6v0pMz6JKQzmjWaPz_ for java:S8714 rule
- AZ6v0pMz6JKQzmjWaP0F for java:S8714 rule
- AZ6v0pMz6JKQzmjWaP0G for java:S8714 rule
- AZ6v0pMz6JKQzmjWaP0H for java:S8714 rule
- AZ6v0pMz6JKQzmjWaP0I for java:S8714 rule

Generated by SonarQube Agent (task: 6e2bc1c1-aa9c-43b2-9b2a-a3cd8f680fff)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant