Skip to content

Commit

Permalink
Ensure ReflectionUtils.findMethods() returns distinct methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Aug 4, 2022
1 parent aa9615e commit 87cda98
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
2 changes: 2 additions & 0 deletions documentation/src/docs/asciidoc/release-notes/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ authors as well as build tool and IDE vendors.

include::{includedir}/link-attributes.adoc[]

include::{basedir}/release-notes-5.9.1.adoc[]

include::{basedir}/release-notes-5.9.0.adoc[]

include::{basedir}/release-notes-5.8.2.adoc[]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[[release-notes-5.9.1]]
== 5.9.1

*Date of Release:* ❓

*Scope:* Minor bug fixes since 5.9.0

For a complete list of all _closed_ issues and pull requests for this release, consult the
link:{junit5-repo}+/milestone/63?closed=1+[5.9.1] milestone page in the JUnit repository
on GitHub.


[[release-notes-5.9.1-junit-platform]]
=== JUnit Platform

==== Bug Fixes

* `ReflectionSupport.findMethods(...)` now returns a distinct set of methods.

==== Deprecations and Breaking Changes

* ❓

==== New Features and Improvements

* ❓


[[release-notes-5.9.1-junit-jupiter]]
=== JUnit Jupiter

==== Bug Fixes

* A `@ParameterizedTest` method configured with a `@MethodSource` annotation that
references a factory method inherited from multiple interfaces no longer fails with an
exception stating that multiple factory methods with the same name were found.

==== Deprecations and Breaking Changes

* ❓

==== New Features and Improvements

* ❓


[[release-notes-5.9.1-junit-vintage]]
=== JUnit Vintage

==== Bug Fixes

* ❓

==== Deprecations and Breaking Changes

* ❓

==== New Features and Improvements

* ❓
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ public static Optional<Method> findMethod(Class<?> clazz, String methodName, Cla
}

/**
* Find all {@linkplain Method methods} of the supplied class or interface
* that match the specified {@code predicate}.
* Find all distinct {@linkplain Method methods} of the supplied class or
* interface that match the specified {@code predicate}.
*
* <p>The results will not contain instance methods that are <em>overridden</em>
* or {@code static} methods that are <em>hidden</em>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,7 @@ public static List<Method> findMethods(Class<?> clazz, Predicate<Method> predica
// @formatter:off
return findAllMethodsInHierarchy(clazz, traversalMode).stream()
.filter(predicate)
.distinct()
// unmodifiable since returned by public, non-internal method(s)
.collect(toUnmodifiableList());
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,16 @@ private static void assertOneFooMethodIn(Class<?> clazz) {
assertThat(findMethods(clazz, isFooMethod)).hasSize(1);
}

/**
* @since 1.9.1
* @see https://github.com/junit-team/junit5/issues/2993
*/
@Test
void findMethodsFindsDistinctMethodsDeclaredInMultipleInterfaces() {
Predicate<Method> isStringsMethod = method -> method.getName().equals("strings");
assertThat(findMethods(DoubleInheritedInterfaceMethodTestCase.class, isStringsMethod)).hasSize(1);
}

@Test
void findMethodsInObject() {
var methods = findMethods(Object.class, method -> true);
Expand Down Expand Up @@ -1427,6 +1437,21 @@ void methodWithMultidimensionalObjectArray(Double[][][][][] data) {
void methodWithParameterizedMap(Map<String, String> map) {
}

interface StringsInterface1 {
static Stream<String> strings() {
return Stream.of("abc", "def");
}
}

interface StringsInterface2 extends StringsInterface1 {
}

/**
* Inherits strings() from interfaces StringsInterface1 and StringsInterface2.
*/
static class DoubleInheritedInterfaceMethodTestCase implements StringsInterface1, StringsInterface2 {
}

interface Generic<X, Y, Z extends X> {

X foo();
Expand Down

0 comments on commit 87cda98

Please sign in to comment.