Change async stubbing to use thenAnswer. (#13521)

* Change async stubbing to use thenAnswer.

Mockito now prohibits calling thenReturn with Futures and Streams. dart-lang/mockito#79

* Update all Mockito deps to 3.0.0.

* Revert "Update all Mockito deps to 3.0.0."

This reverts commit e8ab9d37c33d3d7fe384abde64ea5b4d72623c75.

I did not correctly update the mockito dep, and there's no easy way to update to 3.0 alpha right now.

* Change thenAnswer((_) => to thenAnswer((invocation) =>

* Add Invocation type to thenAnswer lambdas
diff --git a/packages/flutter_tools/test/ios/code_signing_test.dart b/packages/flutter_tools/test/ios/code_signing_test.dart
index 1432e4e..3e701cc 100644
--- a/packages/flutter_tools/test/ios/code_signing_test.dart
+++ b/packages/flutter_tools/test/ios/code_signing_test.dart
@@ -120,15 +120,16 @@
 
       when(mockProcessManager.start(
         argThat(contains('openssl')), environment: any, workingDirectory: any,
-      )).thenReturn(new Future<Process>.value(mockProcess));
+      )).thenAnswer((Invocation invocation) => new Future<Process>.value(mockProcess));
 
       when(mockProcess.stdin).thenReturn(mockStdIn);
-      when(mockProcess.stdout).thenReturn(new Stream<List<int>>.fromFuture(
-        new Future<List<int>>.value(UTF8.encode(
-          'subject= /CN=iPhone Developer: Profile 1 (1111AAAA11)/OU=3333CCCC33/O=My Team/C=US'
-        ))
-      ));
-      when(mockProcess.stderr).thenReturn(mockStdErr);
+      when(mockProcess.stdout)
+          .thenAnswer((Invocation invocation) => new Stream<List<int>>.fromFuture(
+            new Future<List<int>>.value(UTF8.encode(
+              'subject= /CN=iPhone Developer: Profile 1 (1111AAAA11)/OU=3333CCCC33/O=My Team/C=US'
+            ))
+          ));
+      when(mockProcess.stderr).thenAnswer((Invocation invocation) => mockStdErr);
       when(mockProcess.exitCode).thenReturn(0);
 
       final String developmentTeam = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
@@ -178,15 +179,16 @@
 
       when(mockProcessManager.start(
         argThat(contains('openssl')), environment: any, workingDirectory: any,
-      )).thenReturn(new Future<Process>.value(mockOpenSslProcess));
+      )).thenAnswer((Invocation invocation) => new Future<Process>.value(mockOpenSslProcess));
 
       when(mockOpenSslProcess.stdin).thenReturn(mockOpenSslStdIn);
-      when(mockOpenSslProcess.stdout).thenReturn(new Stream<List<int>>.fromFuture(
-        new Future<List<int>>.value(UTF8.encode(
-          'subject= /CN=iPhone Developer: Profile 3 (3333CCCC33)/OU=4444DDDD44/O=My Team/C=US'
-        ))
-      ));
-      when(mockOpenSslProcess.stderr).thenReturn(mockOpenSslStdErr);
+      when(mockOpenSslProcess.stdout)
+          .thenAnswer((Invocation invocation) => new Stream<List<int>>.fromFuture(
+            new Future<List<int>>.value(UTF8.encode(
+              'subject= /CN=iPhone Developer: Profile 3 (3333CCCC33)/OU=4444DDDD44/O=My Team/C=US'
+            ))
+          ));
+      when(mockOpenSslProcess.stderr).thenAnswer((Invocation invocation) => mockOpenSslStdErr);
       when(mockOpenSslProcess.exitCode).thenReturn(0);
 
       final String developmentTeam = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
@@ -247,15 +249,16 @@
 
       when(mockProcessManager.start(
         argThat(contains('openssl')), environment: any, workingDirectory: any,
-      )).thenReturn(new Future<Process>.value(mockOpenSslProcess));
+      )).thenAnswer((Invocation invocation) => new Future<Process>.value(mockOpenSslProcess));
 
       when(mockOpenSslProcess.stdin).thenReturn(mockOpenSslStdIn);
-      when(mockOpenSslProcess.stdout).thenReturn(new Stream<List<int>>.fromFuture(
-        new Future<List<int>>.value(UTF8.encode(
-          'subject= /CN=iPhone Developer: Profile 1 (1111AAAA11)/OU=5555EEEE55/O=My Team/C=US'
-        )),
-      ));
-      when(mockOpenSslProcess.stderr).thenReturn(mockOpenSslStdErr);
+      when(mockOpenSslProcess.stdout)
+          .thenAnswer((Invocation invocation) => new Stream<List<int>>.fromFuture(
+            new Future<List<int>>.value(UTF8.encode(
+              'subject= /CN=iPhone Developer: Profile 1 (1111AAAA11)/OU=5555EEEE55/O=My Team/C=US'
+            )),
+          ));
+      when(mockOpenSslProcess.stderr).thenAnswer((Invocation invocation) => mockOpenSslStdErr);
       when(mockOpenSslProcess.exitCode).thenReturn(0);
 
       final String developmentTeam = await getCodeSigningIdentityDevelopmentTeam(iosApp: app, usesTerminalUi: false);
@@ -308,15 +311,16 @@
 
       when(mockProcessManager.start(
         argThat(contains('openssl')), environment: any, workingDirectory: any,
-      )).thenReturn(new Future<Process>.value(mockOpenSslProcess));
+      )).thenAnswer((Invocation invocation) => new Future<Process>.value(mockOpenSslProcess));
 
       when(mockOpenSslProcess.stdin).thenReturn(mockOpenSslStdIn);
-      when(mockOpenSslProcess.stdout).thenReturn(new Stream<List<int>>.fromFuture(
-        new Future<List<int>>.value(UTF8.encode(
-          'subject= /CN=iPhone Developer: Profile 3 (3333CCCC33)/OU=4444DDDD44/O=My Team/C=US'
-        ))
-      ));
-      when(mockOpenSslProcess.stderr).thenReturn(mockOpenSslStdErr);
+      when(mockOpenSslProcess.stdout)
+          .thenAnswer((Invocation invocation) => new Stream<List<int>>.fromFuture(
+            new Future<List<int>>.value(UTF8.encode(
+              'subject= /CN=iPhone Developer: Profile 3 (3333CCCC33)/OU=4444DDDD44/O=My Team/C=US'
+            ))
+          ));
+      when(mockOpenSslProcess.stderr).thenAnswer((Invocation invocation) => mockOpenSslStdErr);
       when(mockOpenSslProcess.exitCode).thenReturn(0);
       when(mockConfig.getValue('ios-signing-cert')).thenReturn('iPhone Developer: Profile 3 (3333CCCC33)');
 
@@ -376,15 +380,16 @@
 
       when(mockProcessManager.start(
         argThat(contains('openssl')), environment: any, workingDirectory: any,
-      )).thenReturn(new Future<Process>.value(mockOpenSslProcess));
+      )).thenAnswer((Invocation invocation) => new Future<Process>.value(mockOpenSslProcess));
 
       when(mockOpenSslProcess.stdin).thenReturn(mockOpenSslStdIn);
-      when(mockOpenSslProcess.stdout).thenReturn(new Stream<List<int>>.fromFuture(
-        new Future<List<int>>.value(UTF8.encode(
-          'subject= /CN=iPhone Developer: Profile 3 (3333CCCC33)/OU=4444DDDD44/O=My Team/C=US'
-        ))
-      ));
-      when(mockOpenSslProcess.stderr).thenReturn(mockOpenSslStdErr);
+      when(mockOpenSslProcess.stdout)
+          .thenAnswer((Invocation invocation) => new Stream<List<int>>.fromFuture(
+            new Future<List<int>>.value(UTF8.encode(
+              'subject= /CN=iPhone Developer: Profile 3 (3333CCCC33)/OU=4444DDDD44/O=My Team/C=US'
+            ))
+          ));
+      when(mockOpenSslProcess.stderr).thenAnswer((Invocation invocation) => mockOpenSslStdErr);
       when(mockOpenSslProcess.exitCode).thenReturn(0);
       when(mockConfig.getValue('ios-signing-cert')).thenReturn('iPhone Developer: Invalid Profile');
 
diff --git a/packages/flutter_tools/test/ios/devices_test.dart b/packages/flutter_tools/test/ios/devices_test.dart
index e589c1c..61b3356 100644
--- a/packages/flutter_tools/test/ios/devices_test.dart
+++ b/packages/flutter_tools/test/ios/devices_test.dart
@@ -44,7 +44,8 @@
 
     testUsingContext('returns no devices if none are attached', () async {
       when(iMobileDevice.isInstalled).thenReturn(true);
-      when(iMobileDevice.getAvailableDeviceIDs()).thenReturn(new Future<String>.value(''));
+      when(iMobileDevice.getAvailableDeviceIDs())
+          .thenAnswer((Invocation invocation) => new Future<String>.value(''));
       final List<IOSDevice> devices = await IOSDevice.getAttachedDevices();
       expect(devices, isEmpty);
     }, overrides: <Type, Generator>{
@@ -53,7 +54,8 @@
 
     testUsingContext('returns attached devices', () async {
       when(iMobileDevice.isInstalled).thenReturn(true);
-      when(iMobileDevice.getAvailableDeviceIDs()).thenReturn(new Future<String>.value('''
+      when(iMobileDevice.getAvailableDeviceIDs())
+          .thenAnswer((Invocation invocation) => new Future<String>.value('''
 98206e7a4afd4aedaff06e687594e089dede3c44
 f577a7903cc54959be2e34bc4f7f80b7009efcf4
 '''));
@@ -80,18 +82,21 @@
     });
 
     testUsingContext('suppresses non-Flutter lines from output', () async {
-      when(mockIMobileDevice.startLogger()).thenAnswer((_) {
+      when(mockIMobileDevice.startLogger()).thenAnswer((Invocation invocation) {
         final Process mockProcess = new MockProcess();
-        when(mockProcess.stdout).thenReturn(new Stream<List<int>>.fromIterable(<List<int>>['''
+        when(mockProcess.stdout).thenAnswer((Invocation invocation) =>
+            new Stream<List<int>>.fromIterable(<List<int>>['''
   Runner(Flutter)[297] <Notice>: A is for ari
   Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt MobileGestaltSupport.m:153: pid 123 (Runner) does not have sandbox access for frZQaeyWLUvLjeuEK43hmg and IS NOT appropriately entitled
   Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt MobileGestalt.c:550: no access to InverseDeviceID (see <rdar://problem/11744455>)
   Runner(Flutter)[297] <Notice>: I is for ichigo
   Runner(UIKit)[297] <Notice>: E is for enpitsu"
   '''.codeUnits]));
-        when(mockProcess.stderr).thenReturn(const Stream<List<int>>.empty());
+        when(mockProcess.stderr)
+            .thenAnswer((Invocation invocation) => const Stream<List<int>>.empty());
         // Delay return of exitCode until after stdout stream data, since it terminates the logger.
-        when(mockProcess.exitCode).thenReturn(new Future<int>.delayed(Duration.ZERO, () => 0));
+        when(mockProcess.exitCode)
+            .thenAnswer((Invocation invocation) => new Future<int>.delayed(Duration.ZERO, () => 0));
         return new Future<Process>.value(mockProcess);
       });
 
diff --git a/packages/flutter_tools/test/ios/mac_test.dart b/packages/flutter_tools/test/ios/mac_test.dart
index 812c4a1..60f38db 100644
--- a/packages/flutter_tools/test/ios/mac_test.dart
+++ b/packages/flutter_tools/test/ios/mac_test.dart
@@ -81,8 +81,8 @@
 
       testUsingContext('idevicescreenshot captures and returns screenshot', () async {
         when(mockOutputFile.path).thenReturn(outputPath);
-        when(mockProcessManager.run(any, environment: null, workingDirectory:  null))
-            .thenReturn(new Future<ProcessResult>.value(new ProcessResult(4, 0, '', '')));
+        when(mockProcessManager.run(any, environment: null, workingDirectory:  null)).thenAnswer(
+            (Invocation invocation) => new Future<ProcessResult>.value(new ProcessResult(4, 0, '', '')));
 
         await iMobileDevice.takeScreenshot(mockOutputFile);
         verify(mockProcessManager.run(<String>['idevicescreenshot', outputPath],
diff --git a/packages/flutter_tools/test/ios/simulators_test.dart b/packages/flutter_tools/test/ios/simulators_test.dart
index 8cca0db..abdc4e0 100644
--- a/packages/flutter_tools/test/ios/simulators_test.dart
+++ b/packages/flutter_tools/test/ios/simulators_test.dart
@@ -152,7 +152,7 @@
       // Let everything else return exit code 0 so process.dart doesn't crash.
       when(
         mockProcessManager.run(any, environment: null, workingDirectory:  null)
-      ).thenReturn(
+      ).thenAnswer((Invocation invocation) =>
         new Future<ProcessResult>.value(new ProcessResult(2, 0, '', ''))
       );
       // Doesn't matter what the device is.
@@ -206,7 +206,7 @@
     setUp(() {
       mockProcessManager = new MockProcessManager();
       when(mockProcessManager.start(any, environment: null, workingDirectory: null))
-        .thenReturn(new Future<Process>.value(new MockProcess()));
+        .thenAnswer((Invocation invocation) => new Future<Process>.value(new MockProcess()));
     });
 
     testUsingContext('uses tail on iOS versions prior to iOS 11', () async {
@@ -240,7 +240,7 @@
     setUp(() {
       mockProcessManager = new MockProcessManager();
       when(mockProcessManager.start(any, environment: null, workingDirectory: null))
-        .thenReturn(new Future<Process>.value(new MockProcess()));
+        .thenAnswer((Invocation invocation) => new Future<Process>.value(new MockProcess()));
     });
 
     testUsingContext('uses tail on iOS versions prior to iOS 11', () async {