Unverified Commit 3215c492 authored by Camille Simon's avatar Camille Simon Committed by GitHub

[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.
parent 04fdec2c
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment