From 3215c492c8fbfd7fb2b6f078ee19386c4ee65b0a Mon Sep 17 00:00:00 2001 From: Camille Simon <43054281+camsim99@users.noreply.github.com> Date: Wed, 8 Nov 2023 21:10:48 +0000 Subject: [PATCH] [Android] Fix `FlutterTestRunner.java` deprecations (#138093) Fixes deprecations causing unexpected standard error integration test failures: https://github.com/flutter/flutter/issues/138061, https://github.com/flutter/flutter/issues/138063, https://github.com/flutter/flutter/issues/138067, https://github.com/flutter/flutter/pull/138077. Note that the issue this fixes was the same that was the cause for reverting https://github.com/flutter/flutter/pull/137191. I made this same fix in https://github.com/flutter/flutter/pull/137967 and changed `Mac_android run_release_test` to run in presubmit to see a successful run for proof that this fix works. --- .../plugins/integration_test/FlutterTestRunner.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/integration_test/android/src/main/java/dev/flutter/plugins/integration_test/FlutterTestRunner.java b/packages/integration_test/android/src/main/java/dev/flutter/plugins/integration_test/FlutterTestRunner.java index 8aca3cdce4..84a9b2353e 100644 --- a/packages/integration_test/android/src/main/java/dev/flutter/plugins/integration_test/FlutterTestRunner.java +++ b/packages/integration_test/android/src/main/java/dev/flutter/plugins/integration_test/FlutterTestRunner.java @@ -7,6 +7,7 @@ package dev.flutter.plugins.integration_test; import android.util.Log; import androidx.test.rule.ActivityTestRule; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.util.Map; import java.util.concurrent.ExecutionException; import org.junit.Rule; @@ -20,7 +21,7 @@ public class FlutterTestRunner extends Runner { private static final String TAG = "FlutterTestRunner"; - final Class testClass; + final Class testClass; TestRule rule = null; public FlutterTestRunner(Class testClass) { @@ -32,11 +33,13 @@ public class FlutterTestRunner extends Runner { for (Field field : fields) { if (field.isAnnotationPresent(Rule.class)) { try { - Object instance = testClass.newInstance(); + Object instance = testClass.getDeclaredConstructor().newInstance(); if (field.get(instance) instanceof ActivityTestRule) { rule = (TestRule) field.get(instance); break; } + } catch (InvocationTargetException | NoSuchMethodException e) { + throw new RuntimeException("Unable to contruct " + testClass.getName() + " object for testing"); } catch (InstantiationException | IllegalAccessException e) { // This might occur if the developer did not make the rule public. // We could call field.setAccessible(true) but it seems better to throw.