Skip to content

Replace try-catch-fail patterns with assertThatCode in ExplodedGraphWalkerTest#113

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260611-050241-45b01502
Open

Replace try-catch-fail patterns with assertThatCode in ExplodedGraphWalkerTest#113
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260611-050241-45b01502

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 5 issues are MINOR severity style violations in test code with straightforward fixes. Since no production code issues were available and the test improvements enhance code quality with low remediation effort, this batch represents good value for test file maintenance.

Refactors multiple test assertions in ExplodedGraphWalkerTest to use AssertJ's assertThatCode() instead of try-catch-fail anti-patterns, improving test code clarity and maintainability. This resolves 5 SonarQube S8714 issues that flag outdated exception assertion patterns in favor of modern, more readable assertion methods.

View Project in SonarCloud


Fixed Issues

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:321

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 hunks 2 and 4 that replace try-catch-fail patterns with assertThatCode(...).doesNotThrowAnyException(). This import is required to support the refactoring of all the try-catch-fail anti-patterns identified in the file.

--- 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:321

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 hunks 2 and 4 that replace try-catch-fail patterns with assertThatCode(...).doesNotThrowAnyException(). This import is required to support the refactoring of all the try-catch-fail anti-patterns identified in the file.

--- 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 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:343

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 hunks 2 and 4 that replace try-catch-fail patterns with assertThatCode(...).doesNotThrowAnyException(). This import is required to support the refactoring of all the try-catch-fail anti-patterns identified in the file.

--- 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 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:343

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 hunks 2 and 4 that replace try-catch-fail patterns with assertThatCode(...).doesNotThrowAnyException(). This import is required to support the refactoring of all the try-catch-fail anti-patterns identified in the file.

--- 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 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 hunks 2 and 4 that replace try-catch-fail patterns with assertThatCode(...).doesNotThrowAnyException(). This import is required to support the refactoring of all the try-catch-fail anti-patterns identified in the file.

--- 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;

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ6v0pMz6JKQzmjWaP0A for java:S8714 rule
- AZ6v0pMz6JKQzmjWaP0B for java:S8714 rule
- AZ6v0pMz6JKQzmjWaP0C for java:S8714 rule
- AZ6v0pMz6JKQzmjWaP0D for java:S8714 rule
- AZ6v0pMz6JKQzmjWaP0E for java:S8714 rule

Generated by SonarQube Agent (task: 31b8045e-3508-4981-9d44-4bd3e7bce6fe)
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