Skip to content

fix: remove unnecessary public modifiers from test classes#365

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260531-050202-e6d2acf4
Open

fix: remove unnecessary public modifiers from test classes#365
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260531-050202-e6d2acf4

Conversation

@sonarqube-agent
Copy link
Copy Markdown
Contributor

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

Removes unnecessary 'public' modifiers from test classes and methods across ExpressionStatementTest, ForStatementTest, and ReturnStatementTest to comply with JUnit5 conventions and resolve SonarQube code quality warnings. Test classes and methods should use package-private visibility by default for better encapsulation and consistency with modern testing practices.

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/ExpressionStatementTest.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 ExpressionStatementTest class declaration at line 24, changing it to package-private visibility. This follows JUnit5 conventions where test classes should use default package visibility instead of being declared public.

--- a/flex-squid/src/test/java/org/sonar/flex/grammar/statements/ExpressionStatementTest.java
+++ b/flex-squid/src/test/java/org/sonar/flex/grammar/statements/ExpressionStatementTest.java
@@ -24,1 +24,1 @@ import org.sonar.sslr.tests.Assertions;
-public class ExpressionStatementTest {
+class ExpressionStatementTest {
java:S5786 - Remove this 'public' modifier. • INFOView issue

Location: flex-squid/src/test/java/org/sonar/flex/grammar/statements/ExpressionStatementTest.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 test() method at line 29, changing it to package-private visibility. This follows JUnit5 conventions where test methods should use default package visibility instead of being declared public.

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

Location: flex-squid/src/test/java/org/sonar/flex/grammar/statements/ForStatementTest.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 test() method at line 29, changing it to package-private (default) visibility. This follows the JUnit5 convention that test methods should use default package visibility instead of being declared public.

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

Location: flex-squid/src/test/java/org/sonar/flex/grammar/statements/ReturnStatementTest.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 test class 'ReturnStatementTest' at line 24, changing it to package-private (default) visibility. This directly fixes the static analysis warning (java:S5786) that JUnit5 test classes should use default package visibility instead of 'public'.

--- a/flex-squid/src/test/java/org/sonar/flex/grammar/statements/ReturnStatementTest.java
+++ b/flex-squid/src/test/java/org/sonar/flex/grammar/statements/ReturnStatementTest.java
@@ -24,1 +24,1 @@ import org.sonar.sslr.tests.Assertions;
-public class ReturnStatementTest {
+class ReturnStatementTest {
java:S5786 - Remove this 'public' modifier. • INFOView issue

Location: flex-squid/src/test/java/org/sonar/flex/grammar/statements/ForStatementTest.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 ForStatementTest class declaration at line 24, changing it to package-private (default) visibility. This follows the JUnit5 convention that test classes should use default package visibility instead of being declared public.

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

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZggAC4rxdvKFWvLKU-6 for java:S5786 rule
- AZggAC4rxdvKFWvLKU-7 for java:S5786 rule
- AZggAC4LxdvKFWvLKU-x for java:S5786 rule
- AZggAC4LxdvKFWvLKU-y for java:S5786 rule
- AZggAC4hxdvKFWvLKU-5 for java:S5786 rule

Generated by SonarQube Agent (task: 6dea2c97-d00a-47ae-b340-0d2b058284d7)
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