Skip to content

Remove public modifiers from test classes and methods - #431

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260723-050307-424e4e84
Open

Remove public modifiers from test classes and methods#431
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260723-050307-424e4e84

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 177 SonarQube issues stem from the single rule java:S5786 regarding unnecessary public modifiers on test classes and methods. These 5 fixes were selected from the earliest creation dates across different test files to demonstrate consistent remediation of this uniform issue, enabling automated fixes to be applied systematically throughout the codebase.

This change removes unnecessary 'public' modifiers from 5 test classes and methods across the flex-squid test suite, aligning with JUnit5 conventions that recommend using package-private visibility for test code. This improves code readability and adheres to modern testing best practices without affecting functionality.

View Project in SonarCloud


Fixed Issues

java:S5786 - Remove this 'public' modifier. • INFOView issue

Location: flex-squid/src/test/java/org/sonar/flex/grammar/statements/BreakStatementTest.java:29

Why is this an issue?

JUnit5 is more tolerant regarding the visibility of test classes and methods than JUnit4, which required everything to be public. Test classes and methods can have any visibility except private. It is however recommended to use the default package visibility to improve readability.

What changed

Removes the 'public' modifier from the 'eos_is_semicolon()' test method at line 37, changing it to package-private (default) visibility. This addresses the same JUnit5 convention issue where test methods should use default package visibility rather than being declared public, improving readability and following JUnit5 best practices.

--- a/flex-squid/src/test/java/org/sonar/flex/grammar/statements/BreakStatementTest.java
+++ b/flex-squid/src/test/java/org/sonar/flex/grammar/statements/BreakStatementTest.java
@@ -37,1 +37,1 @@ public class BreakStatementTest {
-  public void eos_is_semicolon() {
+  void eos_is_semicolon() {
java:S5786 - Remove this 'public' modifier. • INFOView issue

Location: flex-squid/src/test/java/org/sonar/flex/grammar/statements/ThrowStatementTest.java:44

Why is this an issue?

JUnit5 is more tolerant regarding the visibility of test classes and methods than JUnit4, which required everything to be public. Test classes and methods can have any visibility except private. It is however recommended to use the default package visibility to improve readability.

What changed

Removes the 'public' modifier from the eos_before_right_curly_bracket() test method at line 44, changing it to package-default visibility. JUnit5 test methods should use default package visibility rather than 'public' for better readability and adherence to JUnit5 conventions.

--- a/flex-squid/src/test/java/org/sonar/flex/grammar/statements/ThrowStatementTest.java
+++ b/flex-squid/src/test/java/org/sonar/flex/grammar/statements/ThrowStatementTest.java
@@ -44,1 +44,1 @@ public class ThrowStatementTest {
-  public void eos_before_right_curly_bracket() {
+  void eos_before_right_curly_bracket() {
java:S5786 - Remove this 'public' modifier. • INFOView issue

Location: flex-squid/src/test/java/org/sonar/flex/grammar/statements/ThrowStatementTest.java:51

Why is this an issue?

JUnit5 is more tolerant regarding the visibility of test classes and methods than JUnit4, which required everything to be public. Test classes and methods can have any visibility except private. It is however recommended to use the default package visibility to improve readability.

What changed

Removes the 'public' modifier from the eos_is_end_of_input() test method at line 51, changing it to package-default visibility. JUnit5 test methods should use default package visibility rather than 'public' for better readability and adherence to JUnit5 conventions.

--- a/flex-squid/src/test/java/org/sonar/flex/grammar/statements/ThrowStatementTest.java
+++ b/flex-squid/src/test/java/org/sonar/flex/grammar/statements/ThrowStatementTest.java
@@ -51,1 +51,1 @@ public class ThrowStatementTest {
-  public void eos_is_end_of_input() {
+  void eos_is_end_of_input() {
java:S5786 - Remove this 'public' modifier. • INFOView issue

Location: flex-squid/src/test/java/org/sonar/flex/grammar/statements/BreakStatementTest.java:24

Why is this an issue?

JUnit5 is more tolerant regarding the visibility of test classes and methods than JUnit4, which required everything to be public. Test classes and methods can have any visibility except private. It is however recommended to use the default package visibility to improve readability.

What changed

Removes the 'public' modifier from the 'eos_is_line_terminator()' test method at line 29, changing it to package-private (default) visibility. JUnit5 test methods do not need to be public, and the recommended convention is to omit the public modifier.

--- a/flex-squid/src/test/java/org/sonar/flex/grammar/statements/BreakStatementTest.java
+++ b/flex-squid/src/test/java/org/sonar/flex/grammar/statements/BreakStatementTest.java
@@ -29,1 +29,1 @@ public class BreakStatementTest {
-  public void eos_is_line_terminator() {
+  void eos_is_line_terminator() {
java:S5786 - Remove this 'public' modifier. • INFOView issue

Location: flex-squid/src/test/java/org/sonar/flex/grammar/statements/ThrowStatementTest.java:24

Why is this an issue?

JUnit5 is more tolerant regarding the visibility of test classes and methods than JUnit4, which required everything to be public. Test classes and methods can have any visibility except private. It is however recommended to use the default package visibility to improve readability.

What changed

Removes the 'public' modifier from the ThrowStatementTest class declaration at line 24, changing it to package-default visibility. JUnit5 test classes do not need to be public, and the recommended convention is to use default package visibility for improved readability.

--- a/flex-squid/src/test/java/org/sonar/flex/grammar/statements/ThrowStatementTest.java
+++ b/flex-squid/src/test/java/org/sonar/flex/grammar/statements/ThrowStatementTest.java
@@ -24,1 +24,1 @@ import org.sonar.sslr.tests.Assertions;
-public class ThrowStatementTest {
+class ThrowStatementTest {

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZggAC6GxdvKFWvLKU_P for java:S5786 rule
- AZggAC6GxdvKFWvLKU_Q for java:S5786 rule
- AZggAC6GxdvKFWvLKU_R for java:S5786 rule
- AZggAC6mxdvKFWvLKU_a for java:S5786 rule
- AZggAC6mxdvKFWvLKU_W for java:S5786 rule

Generated by SonarQube Agent (task: 39103c9c-90bb-4ef1-831c-532f85ba518f)
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