Skip to content

Commit c6999dc

Browse files
committed
Remove declaringClassName from MethodSelector
1 parent 31128d6 commit c6999dc

File tree

2 files changed

+11
-45
lines changed

2 files changed

+11
-45
lines changed

junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/MethodSelector.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public final class MethodSelector implements DiscoverySelector {
6464
private final String className;
6565
private final String methodName;
6666
private final String parameterTypeNames;
67-
private final @Nullable String declaringClassName;
6867

6968
private volatile @Nullable Class<?> javaClass;
7069

@@ -76,19 +75,22 @@ public final class MethodSelector implements DiscoverySelector {
7675
* @since 1.10
7776
*/
7877
MethodSelector(@Nullable ClassLoader classLoader, String className, String methodName, String parameterTypeNames) {
79-
this(classLoader, className, methodName, parameterTypeNames, null);
78+
this.classLoader = classLoader;
79+
this.className = className;
80+
this.methodName = methodName;
81+
this.parameterTypeNames = parameterTypeNames;
8082
}
8183

8284
MethodSelector(Class<?> javaClass, String methodName, String parameterTypeNames) {
83-
this(javaClass.getClassLoader(), javaClass.getName(), methodName, parameterTypeNames, null);
85+
this(javaClass.getClassLoader(), javaClass.getName(), methodName, parameterTypeNames);
8486
this.javaClass = javaClass;
8587
}
8688

8789
/**
8890
* @since 1.10
8991
*/
9092
MethodSelector(@Nullable ClassLoader classLoader, String className, String methodName, Class<?>... parameterTypes) {
91-
this(classLoader, className, methodName, ClassUtils.nullSafeToString(Class::getTypeName, parameterTypes), null);
93+
this(classLoader, className, methodName, ClassUtils.nullSafeToString(Class::getTypeName, parameterTypes));
9294
this.parameterTypes = parameterTypes.clone();
9395
}
9496

@@ -97,7 +99,7 @@ public final class MethodSelector implements DiscoverySelector {
9799
*/
98100
MethodSelector(Class<?> javaClass, String methodName, Class<?>... parameterTypes) {
99101
this(javaClass.getClassLoader(), javaClass.getName(), methodName,
100-
ClassUtils.nullSafeToString(Class::getTypeName, parameterTypes), null);
102+
ClassUtils.nullSafeToString(Class::getTypeName, parameterTypes));
101103
this.javaClass = javaClass;
102104
this.parameterTypes = parameterTypes.clone();
103105
}
@@ -108,21 +110,12 @@ public final class MethodSelector implements DiscoverySelector {
108110

109111
private MethodSelector(Class<?> javaClass, Method method, Class<?>... parameterTypes) {
110112
this(javaClass.getClassLoader(), javaClass.getName(), method.getName(),
111-
ClassUtils.nullSafeToString(Class::getTypeName, parameterTypes), method.getDeclaringClass().getName());
113+
ClassUtils.nullSafeToString(Class::getTypeName, parameterTypes));
112114
this.javaClass = javaClass;
113115
this.javaMethod = method;
114116
this.parameterTypes = parameterTypes;
115117
}
116118

117-
private MethodSelector(@Nullable ClassLoader classLoader, String className, String methodName,
118-
String parameterTypeNames, @Nullable String declaringClassName) {
119-
this.classLoader = classLoader;
120-
this.className = className;
121-
this.methodName = methodName;
122-
this.parameterTypeNames = parameterTypeNames;
123-
this.declaringClassName = className.equals(declaringClassName) ? null : declaringClassName;
124-
}
125-
126119
/**
127120
* Get the {@link ClassLoader} used to load the specified class.
128121
*
@@ -278,8 +271,7 @@ public boolean equals(Object o) {
278271
MethodSelector that = (MethodSelector) o;
279272
return Objects.equals(this.className, that.className)//
280273
&& Objects.equals(this.methodName, that.methodName)//
281-
&& Objects.equals(this.parameterTypeNames, that.parameterTypeNames)//
282-
&& Objects.equals(this.declaringClassName, that.declaringClassName);
274+
&& Objects.equals(this.parameterTypeNames, that.parameterTypeNames);
283275
}
284276

285277
/**
@@ -288,7 +280,7 @@ public boolean equals(Object o) {
288280
@API(status = STABLE, since = "1.3")
289281
@Override
290282
public int hashCode() {
291-
return Objects.hash(this.className, this.methodName, this.parameterTypeNames, this.declaringClassName);
283+
return Objects.hash(this.className, this.methodName, this.parameterTypeNames);
292284
}
293285

294286
@Override

platform-tests/src/test/java/org/junit/platform/engine/discovery/MethodSelectorTests.java

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,7 @@ void usesClassClassLoader() {
8282
assertThat(selector.getClassLoader()).isNotNull().isSameAs(getClass().getClassLoader());
8383
}
8484

85-
@Test
86-
void distinguishesDeclaringClass() throws Exception {
87-
var parentMethodSelector = new MethodSelector(TestCase.class,
88-
ParentTestCase.class.getDeclaredMethod("method", int.class, boolean.class));
89-
var childMethodSelector = new MethodSelector(TestCase.class,
90-
TestCase.class.getDeclaredMethod("method", int.class, boolean.class));
91-
92-
assertThat(parentMethodSelector).isNotEqualTo(childMethodSelector);
93-
assertThat(childMethodSelector).isNotEqualTo(parentMethodSelector);
94-
}
95-
96-
@Test
97-
void ignoresDeclaringClassWhenEqualToClassname() throws Exception {
98-
var selectorByMethod = new MethodSelector(TestCase.class,
99-
TestCase.class.getDeclaredMethod("method", int.class, boolean.class));
100-
var selectorByName = new MethodSelector(TestCase.class, "method", int.class, boolean.class);
101-
assertThat(selectorByMethod).isEqualTo(selectorByName);
102-
}
103-
104-
private static class ParentTestCase {
105-
106-
@SuppressWarnings("unused")
107-
private void method(int num, boolean flag) {
108-
}
109-
}
110-
111-
private static class TestCase extends ParentTestCase {
85+
private static class TestCase {
11286

11387
@SuppressWarnings("unused")
11488
void method(int num, boolean flag) {

0 commit comments

Comments
 (0)