Skip to content

ReflectionUtils.findMethods() returns duplicate methods, breaking certain use cases #2993

@jamieredding

Description

@jamieredding

I have a working test in Junit 5.8.2 that sees a method source on an interface, but that same method source can be seen from two interfaces that my test implements, because one interface implements the other interface.

After updating to 5.9.0 I now have an exception that "Several factory methods named [xxxx] were found in class [yyyy]"

Steps to reproduce

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.stream.Stream;

public class Junit5BugTest implements A, B {

    @ParameterizedTest
    @MethodSource("methodSource")
    void test(String param) {
        Assertions.assertTrue(true);
    }
}

interface A {
    static Stream<Arguments> methodSource() {
        return Stream.of(Arguments.arguments("abc"), Arguments.arguments("def"));
    }
}

interface B extends A {

}

Context

  • Used versions (Jupiter/Vintage/Platform): Junit Jupiter 5.9.0
  • Build Tool/IDE: IntelliJ IDEA 2022.2 (Ultimate Edition)
  • Java: OpenJDK Runtime Environment Temurin-17.0.3+7 (build 17.0.3+7)

Deliverables

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions