Skip to content

fix: remove unnecessary public modifiers from JUnit5 test classes and methods#364

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260530-050215-4bfef160
Open

fix: remove unnecessary public modifiers from JUnit5 test classes and methods#364
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260530-050215-4bfef160

Conversation

@sonarqube-agent
Copy link
Copy Markdown
Contributor

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

Removes the 'public' modifier from test classes and methods across multiple test files to comply with JUnit5 best practices and SonarQube rule S5786. Test classes and methods don't require public visibility and using package-default visibility improves code clarity and follows 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/lexical/SpacingNoLineBreakTest.java:25

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 'SpacingNoLineBreakTest' at line 25, changing it to package-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/lexical/SpacingNoLineBreakTest.java
+++ b/flex-squid/src/test/java/org/sonar/flex/grammar/lexical/SpacingNoLineBreakTest.java
@@ -25,1 +25,1 @@ import static org.sonar.sslr.tests.Assertions.assertThat;
-public class SpacingNoLineBreakTest {
+class SpacingNoLineBreakTest {
java:S5786 - Remove this 'public' modifier. • INFOView issue

Location: flex-squid/src/test/java/org/sonar/flex/grammar/statements/ReturnStatementTest.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 'eos_is_line_terminator()' at line 29, changing it to package-private visibility. JUnit5 test methods don't need to be public, and the recommended convention is to use default (package) visibility for better readability.

--- 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
@@ -29,1 +29,1 @@ public class ReturnStatementTest {
-  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/ReturnStatementTest.java:37

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 'eos_is_semicolon()' at line 37, changing it to package-private visibility. JUnit5 test methods don't need to be public, and the recommended convention is to use default (package) visibility for better readability.

--- 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
@@ -37,1 +37,1 @@ public class ReturnStatementTest {
-  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/ReturnStatementTest.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 test method 'eos_before_right_curly_bracket()' at line 44, changing it to package-private visibility. JUnit5 test methods don't need to be public, and the recommended convention is to use default (package) visibility for better readability.

--- 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
@@ -44,1 +44,1 @@ public class ReturnStatementTest {
-  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/ReturnStatementTest.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 test method 'eos_is_end_of_input()' at line 51, changing it to package-private visibility. JUnit5 test methods don't need to be public, and the recommended convention is to use default (package) visibility for better readability.

--- 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
@@ -51,1 +51,1 @@ public class ReturnStatementTest {
-  public void eos_is_end_of_input() {
+  void eos_is_end_of_input() {

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZggAC4hxdvKFWvLKU-2 for java:S5786 rule
- AZggAC4hxdvKFWvLKU-3 for java:S5786 rule
- AZggAC4hxdvKFWvLKU-1 for java:S5786 rule
- AZggAC4hxdvKFWvLKU-4 for java:S5786 rule
- AZggAC4AxdvKFWvLKU-w for java:S5786 rule

Generated by SonarQube Agent (task: 6a3cb6a9-ff0e-4052-b17b-fc13f96957e6)
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