A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/4975 below:

[java] UnusedPrivateMethod false positive when using @MethodSource on a @Nested test · Issue #4975 · pmd/pmd · GitHub

Affects PMD Version:
7.0.0

Rule:
UnusedPrivateMethod

Please provide the rule name and a link to the rule documentation:
https://docs.pmd-code.org/latest/pmd_rules_java_bestpractices.html#unusedprivatemethod

Description:
I'm using java 21, with maven-pmd-plugin 3.22.0 (should be using the default PMD 7.0.0)

i am geting a false positive result for UnusedPrivateMethod when a private method is being used as part of @ParameterizedTest @MethodSource argument.

The method is only used as part of the @MethodSource annotation.

I've removed all business sensitive context out of the test, but otherwise this is the exact structure of our test.

Code Sample demonstrating the issue:

class BaseTest {
    @Nested
    class ExampleTest {

        @ParameterizedTest
        @MethodSource("getStrings")
        void exampleTestUsingPrivateMethod(
                List<String> strings) {
            // insert code
        }

        private static Stream<Arguments> getStrings() {
            Stream<Arguments> tests = Stream.of(
                    Arguments.of(List.of("TEST", "TEST_1")),
                    Arguments.of(List.of("TEST_2", "TEST_3"))
            );

            return Stream.of(tests)
                    .reduce(Stream::concat)
                    .orElseGet(Stream::empty);
        }
    }
}

Expected outcome:

I have been using this rule against this block of code in prior version to PMD 7.0.0 and it has been working (i.e. not complaining)

PMD reports a violation at line

Rule:UnusedPrivateMethod Priority:3 Avoid unused private methods such as 'getStrings()'..

However, the method is used

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Maven


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4