Skip to content

[java] Fix #5477: JUnit5TestShouldBePackagePrivate is not applied when @Test method is only present in parent class#6680

Merged
UncleOwen merged 4 commits into
pmd:mainfrom
UncleOwen:issue-5477-JUnit5TestShouldBePackagePrivate-is-not-applied-when-@Test-method-is-only-present-in-parent-class
May 22, 2026
Merged

[java] Fix #5477: JUnit5TestShouldBePackagePrivate is not applied when @Test method is only present in parent class#6680
UncleOwen merged 4 commits into
pmd:mainfrom
UncleOwen:issue-5477-JUnit5TestShouldBePackagePrivate-is-not-applied-when-@Test-method-is-only-present-in-parent-class

Conversation

@UncleOwen

@UncleOwen UncleOwen commented May 14, 2026

Copy link
Copy Markdown
Member

Describe the PR

Fixes JUnit5TestShouldBePackagePrivate by converting it from XPath to Java. That allows us to use the infrastructure introduced in #6604

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • [n/a] Added (in-code) documentation (if needed)

@UncleOwen UncleOwen force-pushed the issue-5477-JUnit5TestShouldBePackagePrivate-is-not-applied-when-@Test-method-is-only-present-in-parent-class branch from a9b1154 to 0564a30 Compare May 14, 2026 18:40
@pmd-actions-helper

pmd-actions-helper Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 34 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 15 errors and 9 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-05-21 16:01:36+00:00 for 9c0c203)

UncleOwen added a commit to UncleOwen/pmd that referenced this pull request May 15, 2026
UncleOwen added a commit to UncleOwen/pmd that referenced this pull request May 15, 2026
@UncleOwen UncleOwen force-pushed the issue-5477-JUnit5TestShouldBePackagePrivate-is-not-applied-when-@Test-method-is-only-present-in-parent-class branch 2 times, most recently from ff990e0 to 1d12872 Compare May 17, 2026 23:15
UncleOwen added 4 commits May 21, 2026 17:43
…tests.Junit5ParentWithTest

... because I plan to use it in tests for different rules
* Convert JUnit5TestShouldBePackagePrivateRule from XPath to Java
* Use new TestFrameworksUtil.isJUnit5Class() to make the rule aware of
superclasses
@UncleOwen UncleOwen force-pushed the issue-5477-JUnit5TestShouldBePackagePrivate-is-not-applied-when-@Test-method-is-only-present-in-parent-class branch from 1d12872 to 9c0c203 Compare May 21, 2026 15:45
@UncleOwen UncleOwen requested a review from zbynek May 21, 2026 16:01
@zbynek

zbynek commented May 21, 2026

Copy link
Copy Markdown
Contributor

This introduces a couple more usages of JUnit5 in naming - should we resolve #6682 first and apply the resulting naming in this PR? Or create a quick follow-up PR to make sure the rule that was not released yet gets a future-proof name from the start?

@UncleOwen

Copy link
Copy Markdown
Member Author

You're right. Adding something just to rename it days later doesn't make sense. Should I rename this to JUnitJupiterTestShouldBePackagePrivate? That's the naming scheme both of us preferred, right?

What do you mean with "a couple"? #6682 is only about rule names and properties. Were you thinking about renaming all the methods referring to junit5 as well?

@zbynek

zbynek commented May 21, 2026

Copy link
Copy Markdown
Contributor

What do you mean with "a couple"?

I just meant that previously it was the name of the rule, now it's also the name of a rule class and appears in some tests (e.g. Junit5ParentWithTest ) .

For 7.25 it would IMHO make sense to rename JUnitJupiterTestShouldBePackagePrivate to JUnitJupiterTestShouldBePackagePrivate (this PR) and maybe deprecate + rename JUnit5TestShouldBePackagePrivate (another PR?) -- renaming methods should probaly wait (could break API compatibility etc.).

@UncleOwen

Copy link
Copy Markdown
Member Author

Oh, right. This is an existing rule. (Shows how good I know my own PRs...)

In that case, let's not rename anything in this PR. Instead, let's create an issue for #6682 and rename all existing rules/properties at once. That way, there is no release with some rules renamed and some not.

@UncleOwen

Copy link
Copy Markdown
Member Author

I've added an issue for #6682. This PR is for an existing rule. Can we treat those two issues separately?

@UncleOwen UncleOwen merged commit 5db914f into pmd:main May 22, 2026
13 checks passed
@UncleOwen UncleOwen added this to the 7.25.0 milestone May 22, 2026
@UncleOwen UncleOwen deleted the issue-5477-JUnit5TestShouldBePackagePrivate-is-not-applied-when-@Test-method-is-only-present-in-parent-class branch May 22, 2026 17:51
@adangel adangel mentioned this pull request May 28, 2026
4 tasks
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.

[java] JUnit5TestShouldBePackagePrivate is not applied when @Test method is only present in parent class

2 participants