Skip to content

Commit 3215c49

Browse files
authored
[Android] Fix FlutterTestRunner.java deprecations (flutter#138093)
Fixes deprecations causing unexpected standard error integration test failures: flutter#138061, flutter#138063, flutter#138067, flutter#138077. Note that the issue this fixes was the same that was the cause for reverting flutter#137191. I made this same fix in flutter#137967 and changed `Mac_android run_release_test` to run in presubmit to see a successful run for proof that this fix works.
1 parent 04fdec2 commit 3215c49

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/integration_test/android/src/main/java/dev/flutter/plugins/integration_test/FlutterTestRunner.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.util.Log;
88
import androidx.test.rule.ActivityTestRule;
99
import java.lang.reflect.Field;
10+
import java.lang.reflect.InvocationTargetException;
1011
import java.util.Map;
1112
import java.util.concurrent.ExecutionException;
1213
import org.junit.Rule;
@@ -20,7 +21,7 @@ public class FlutterTestRunner extends Runner {
2021

2122
private static final String TAG = "FlutterTestRunner";
2223

23-
final Class testClass;
24+
final Class<?> testClass;
2425
TestRule rule = null;
2526

2627
public FlutterTestRunner(Class<?> testClass) {
@@ -32,11 +33,13 @@ public FlutterTestRunner(Class<?> testClass) {
3233
for (Field field : fields) {
3334
if (field.isAnnotationPresent(Rule.class)) {
3435
try {
35-
Object instance = testClass.newInstance();
36+
Object instance = testClass.getDeclaredConstructor().newInstance();
3637
if (field.get(instance) instanceof ActivityTestRule) {
3738
rule = (TestRule) field.get(instance);
3839
break;
3940
}
41+
} catch (InvocationTargetException | NoSuchMethodException e) {
42+
throw new RuntimeException("Unable to contruct " + testClass.getName() + " object for testing");
4043
} catch (InstantiationException | IllegalAccessException e) {
4144
// This might occur if the developer did not make the rule public.
4245
// We could call field.setAccessible(true) but it seems better to throw.

0 commit comments

Comments
 (0)