testFramework: Handle inherited test methods in `Retries.getMethodFromClass()`
authorEldar Abusalimov <Eldar.Abusalimov@jetbrains.com>
Mon, 3 Oct 2022 00:43:17 +0000 (02:43 +0200)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Mon, 3 Oct 2022 02:20:14 +0000 (02:20 +0000)
GitOrigin-RevId: 52169a94ff682a90e8cd349159403348f15e4345

platform/testFramework/bootstrap/src/com/intellij/tests/Retries.java

index 45eb9c09ec9cf99ec7357a069ab8d50216f6eef9..5ace7535be7d9ce480d7eeda1393f6990970879f 100644 (file)
@@ -12,7 +12,6 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Optional;
 import java.util.Set;
-import java.util.stream.Collectors;
 
 /**
  * TeamCity note: <a href="https://www.jetbrains.com/help/teamcity/2021.1/build-failure-conditions.html#test-retry">test retry support</a> should be enabled for previously failed tests to be muted
@@ -61,15 +60,17 @@ public final class Retries {
   }
 
   private static Optional<Method> getMethodFromClass(Class<?> clazz, String methodName) {
-    @SuppressWarnings("SSBasedInspection")
-    var methods = Arrays.stream(clazz.getDeclaredMethods())
-      .filter(method -> methodName.equals(method.getName())).toList();
-    if (methods.size() == 1) {
-      return Optional.of(methods.get(0));
-    }
-    else {
-      return Optional.empty();
+    for (; clazz != null && clazz != Object.class; clazz = clazz.getSuperclass()) {
+      var methods = Arrays.stream(clazz.getDeclaredMethods())
+        .filter(method -> methodName.equals(method.getName()) && method.getParameterCount() == 0).toList();
+      if (methods.size() > 1) {
+        break;
+      }
+      if (methods.size() == 1) {
+        return Optional.of(methods.get(0));
+      }
     }
+    return Optional.empty();
   }
 
   public static void testFinished(Test test, boolean isSuccessful) {