Skip to content

Remove unnecessary 'public' modifier from JUnit 5 test methods and classes#7649

Open
Vest wants to merge 1 commit into
PCGen:masterfrom
Vest:remove-public-from-test-methods
Open

Remove unnecessary 'public' modifier from JUnit 5 test methods and classes#7649
Vest wants to merge 1 commit into
PCGen:masterfrom
Vest:remove-public-from-test-methods

Conversation

@Vest

@Vest Vest commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Removes the redundant public modifier from @Test, @ParameterizedTest, @BeforeEach, @AfterEach, @BeforeAll, and @AfterAll methods across all test source sets
  • Removes public from top-level concrete test class declarations
  • Fixes Sonar rule S5786 ("Remove this 'public' modifier") across the codebase

JUnit 5 discovers tests by annotation, not by visibility — public on test methods and classes is noise, not a requirement.

Scope: 903 files changed in PCGen-base, PCGen-Formula, and the main code module (test, testcommon, slowtest, itest source sets).

Preserved (not changed):

  • @Override methods — visibility must not narrow the parent's declaration
  • abstract base test classes — may be subclassed from other packages
  • Helper/mock classes without @Test annotations — used across packages

Test plan

  • ./gradlew :PCGen-base:test :PCGen-Formula:test test passes
  • Test count unchanged: 18,490 before and after

…asses

Sonar rule S5786 flags 'public' as redundant on JUnit 5 test/lifecycle
methods and on concrete test class declarations, since the JUnit 5
platform discovers tests by annotation, not visibility.

903 concrete test classes updated across PCGen-base, PCGen-Formula,
and the main code module.  The script preserved:
- @OverRide methods (visibility must not narrow the parent)
- abstract base test classes (may be subclassed across packages)
- helper/mock classes with no @test annotations (used across packages)

Test count unchanged: 18,490 before and after.
@Vest

Vest commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Since we use JUnit 6, I think, we must be modern - all tests don't need "public" anymore (thanks to Sonar).
Less letters in the code, easier to read :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant