Skip to content

fix: remove unnecessary 'public' modifiers from JUnit5 test classes/methods#362

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260529-050212-43fbd51e
Open

fix: remove unnecessary 'public' modifiers from JUnit5 test classes/methods#362
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260529-050212-43fbd51e

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 in accordance with JUnit5 best practices and SonarQube recommendations. Test classes and methods should use package-private visibility by default, improving code readability and following modern testing conventions.

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/WithStatementTest.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 WithStatementTest class declaration, 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 better readability. This directly addresses the code smell about unnecessary 'public' modifier on a JUnit5 test class.

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

Location: flex-squid/src/test/java/org/sonar/flex/grammar/lexical/SpacingNoLineBreakTest.java:30

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 'empty()' test method at line 30, changing it to package-private visibility. This fixes the static analysis warning about JUnit5 test methods having unnecessary 'public' modifiers, following the JUnit5 recommendation to use default package visibility for test methods.

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

Location: flex-squid/src/test/java/org/sonar/flex/grammar/lexical/SpacingNoLineBreakTest.java:36

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 'whitespace()' test method at line 36, changing it to package-private visibility. This fixes the static analysis warning about JUnit5 test methods having unnecessary 'public' modifiers, following the JUnit5 recommendation to use default package visibility for test methods.

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

Location: flex-squid/src/test/java/org/sonar/flex/grammar/lexical/SpacingNoLineBreakTest.java:45

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 'single_line_comment()' test method at line 45, changing it to package-private visibility. This fixes the static analysis warning about JUnit5 test methods having unnecessary 'public' modifiers, following the JUnit5 recommendation to use default package visibility for test methods.

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

Location: flex-squid/src/test/java/org/sonar/flex/grammar/lexical/SpacingNoLineBreakTest.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 'multi_line_comment()' test method at line 51, changing it to package-private visibility. This fixes the static analysis warning about JUnit5 test methods having unnecessary 'public' modifiers, following the JUnit5 recommendation to use default package visibility for test methods.

--- a/flex-squid/src/test/java/org/sonar/flex/grammar/lexical/SpacingNoLineBreakTest.java
+++ b/flex-squid/src/test/java/org/sonar/flex/grammar/lexical/SpacingNoLineBreakTest.java
@@ -51,1 +51,1 @@ public class SpacingNoLineBreakTest {
-  public void multi_line_comment() {
+  void multi_line_comment() {

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZggAC41xdvKFWvLKU-9 for java:S5786 rule
- AZggAC4AxdvKFWvLKU-s for java:S5786 rule
- AZggAC4AxdvKFWvLKU-t for java:S5786 rule
- AZggAC4AxdvKFWvLKU-u for java:S5786 rule
- AZggAC4AxdvKFWvLKU-v for java:S5786 rule

Generated by SonarQube Agent (task: 074f62f2-9a05-48de-a277-fc42b8a91dd1)
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