From 30720bd1486f270604050e860551d1c3e20428e8 Mon Sep 17 00:00:00 2001 From: Alan Russian Date: Tue, 19 Dec 2017 13:13:57 -0800 Subject: [PATCH] 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 --- .../test/flutter_driver_test.dart | 36 ++++----- packages/flutter_tools/test/base/io_test.dart | 4 +- .../test/commands/drive_test.dart | 3 +- packages/flutter_tools/test/compile_test.dart | 55 ++++++++------ .../test/ios/code_signing_test.dart | 75 ++++++++++--------- .../flutter_tools/test/ios/devices_test.dart | 17 +++-- packages/flutter_tools/test/ios/mac_test.dart | 4 +- .../test/ios/simulators_test.dart | 6 +- packages/flutter_tools/test/stop_test.dart | 4 +- 9 files changed, 112 insertions(+), 92 deletions(-) diff --git a/packages/flutter_driver/test/flutter_driver_test.dart b/packages/flutter_driver/test/flutter_driver_test.dart index f448f33dca..da9367142a 100644 --- a/packages/flutter_driver/test/flutter_driver_test.dart +++ b/packages/flutter_driver/test/flutter_driver_test.dart @@ -40,8 +40,8 @@ void main() { when(mockClient.getVM()).thenReturn(mockVM); when(mockVM.isolates).thenReturn([mockIsolate]); when(mockIsolate.loadRunnable()).thenReturn(mockIsolate); - when(mockIsolate.invokeExtension(any, any)) - .thenReturn(makeMockResponse({'status': 'ok'})); + when(mockIsolate.invokeExtension(any, any)).thenAnswer( + (Invocation invocation) => makeMockResponse({'status': 'ok'})); vmServiceConnectFunction = (String url) { return new Future.value( new VMServiceClientConnection(mockClient, mockPeer) @@ -56,16 +56,16 @@ void main() { test('connects to isolate paused at start', () async { final List connectionLog = []; - when(mockPeer.sendRequest('streamListen', any)).thenAnswer((_) { + when(mockPeer.sendRequest('streamListen', any)).thenAnswer((Invocation invocation) { connectionLog.add('streamListen'); return null; }); when(mockIsolate.pauseEvent).thenReturn(new MockVMPauseStartEvent()); - when(mockIsolate.resume()).thenAnswer((_) { + when(mockIsolate.resume()).thenAnswer((Invocation invocation) { connectionLog.add('resume'); return new Future.value(); }); - when(mockIsolate.onExtensionAdded).thenAnswer((_) { + when(mockIsolate.onExtensionAdded).thenAnswer((Invocation invocation) { connectionLog.add('onExtensionAdded'); return new Stream.fromIterable(['ext.flutter.driver']); }); @@ -78,7 +78,7 @@ void main() { test('connects to isolate paused mid-flight', () async { when(mockIsolate.pauseEvent).thenReturn(new MockVMPauseBreakpointEvent()); - when(mockIsolate.resume()).thenReturn(new Future.value()); + when(mockIsolate.resume()).thenAnswer((Invocation invocation) => new Future.value()); final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: ''); expect(driver, isNotNull); @@ -91,7 +91,7 @@ void main() { // just fine. test('connects despite losing the race to resume isolate', () async { when(mockIsolate.pauseEvent).thenReturn(new MockVMPauseBreakpointEvent()); - when(mockIsolate.resume()).thenAnswer((_) { + when(mockIsolate.resume()).thenAnswer((Invocation invocation) { // This needs to be wrapped in a closure to not be considered uncaught // by package:test return new Future.error(new rpc.RpcException(101, '')); @@ -124,14 +124,14 @@ void main() { }); test('checks the health of the driver extension', () async { - when(mockIsolate.invokeExtension(any, any)).thenReturn( - makeMockResponse({'status': 'ok'})); + when(mockIsolate.invokeExtension(any, any)).thenAnswer( + (Invocation invocation) => makeMockResponse({'status': 'ok'})); final Health result = await driver.checkHealth(); expect(result.status, HealthStatus.ok); }); test('closes connection', () async { - when(mockClient.close()).thenReturn(new Future.value()); + when(mockClient.close()).thenAnswer((Invocation invocation) => new Future.value()); await driver.close(); }); @@ -234,7 +234,7 @@ void main() { test('clears timeline', () async { bool clearWasCalled = false; when(mockPeer.sendRequest('_clearVMTimeline', argThat(equals({})))) - .thenAnswer((_) async { + .thenAnswer((Invocation invocation) async { clearWasCalled = true; return null; }); @@ -250,24 +250,24 @@ void main() { log = []; when(mockPeer.sendRequest('_clearVMTimeline', argThat(equals({})))) - .thenAnswer((_) async { + .thenAnswer((Invocation invocation) async { log.add('clear'); return null; }); when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals({'recordedStreams': '[all]'})))) - .thenAnswer((_) async { + .thenAnswer((Invocation invocation) async { log.add('startTracing'); return null; }); when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals({'recordedStreams': '[]'})))) - .thenAnswer((_) async { + .thenAnswer((Invocation invocation) async { log.add('stopTracing'); return null; }); - when(mockPeer.sendRequest('_getVMTimeline')).thenAnswer((_) async { + when(mockPeer.sendRequest('_getVMTimeline')).thenAnswer((Invocation invocation) async { log.add('download'); return { 'traceEvents': [ @@ -316,18 +316,18 @@ void main() { bool stopTracingCalled = false; when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals({'recordedStreams': '[Dart, GC, Compiler]'})))) - .thenAnswer((_) async { + .thenAnswer((Invocation invocation) async { startTracingCalled = true; return null; }); when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals({'recordedStreams': '[]'})))) - .thenAnswer((_) async { + .thenAnswer((Invocation invocation) async { stopTracingCalled = true; return null; }); - when(mockPeer.sendRequest('_getVMTimeline')).thenAnswer((_) async { + when(mockPeer.sendRequest('_getVMTimeline')).thenAnswer((Invocation invocation) async { return { 'traceEvents': [ { diff --git a/packages/flutter_tools/test/base/io_test.dart b/packages/flutter_tools/test/base/io_test.dart index 096eb797fb..506be74ba4 100644 --- a/packages/flutter_tools/test/base/io_test.dart +++ b/packages/flutter_tools/test/base/io_test.dart @@ -19,7 +19,7 @@ void main() { final ProcessSignal signalUnderTest = new ProcessSignal(mockSignal); final StreamController controller = new StreamController(); - when(mockSignal.watch()).thenReturn(controller.stream); + when(mockSignal.watch()).thenAnswer((Invocation invocation) => controller.stream); controller.add(mockSignal); expect(signalUnderTest, await signalUnderTest.watch().first); @@ -31,4 +31,4 @@ void main() { }); } -class MockIoProcessSignal extends Mock implements io.ProcessSignal {} \ No newline at end of file +class MockIoProcessSignal extends Mock implements io.ProcessSignal {} diff --git a/packages/flutter_tools/test/commands/drive_test.dart b/packages/flutter_tools/test/commands/drive_test.dart index b6d0e8be64..1e656049e1 100644 --- a/packages/flutter_tools/test/commands/drive_test.dart +++ b/packages/flutter_tools/test/commands/drive_test.dart @@ -279,7 +279,8 @@ void main() { testUsingContext('uses existing simulator', () async { withMockDevice(); when(mockDevice.name).thenReturn('mock-simulator'); - when(mockDevice.isLocalEmulator).thenReturn(new Future.value(true)); + when(mockDevice.isLocalEmulator) + .thenAnswer((Invocation invocation) => new Future.value(true)); final Device device = await findTargetDevice(); expect(device.name, 'mock-simulator'); diff --git a/packages/flutter_tools/test/compile_test.dart b/packages/flutter_tools/test/compile_test.dart index 500bc20b27..4a0e9143ad 100644 --- a/packages/flutter_tools/test/compile_test.dart +++ b/packages/flutter_tools/test/compile_test.dart @@ -27,21 +27,24 @@ void main() { mockFrontendServerStdIn = new MockStdIn(); mockFrontendServerStdErr = new MockStream(); - when(mockFrontendServer.stderr).thenReturn(mockFrontendServerStdErr); + when(mockFrontendServer.stderr) + .thenAnswer((Invocation invocation) => mockFrontendServerStdErr); final StreamController stdErrStreamController = new StreamController(); when(mockFrontendServerStdErr.transform(any)).thenReturn(stdErrStreamController.stream); when(mockFrontendServer.stdin).thenReturn(mockFrontendServerStdIn); - when(mockProcessManager.start(any)).thenReturn(new Future.value(mockFrontendServer)); + when(mockProcessManager.start(any)).thenAnswer( + (Invocation invocation) => new Future.value(mockFrontendServer)); when(mockFrontendServer.exitCode).thenReturn(0); }); testUsingContext('single dart successful compilation', () async { final BufferLogger logger = context[Logger]; - when(mockFrontendServer.stdout).thenReturn(new Stream>.fromFuture( - new Future>.value(UTF8.encode( - 'result abc\nline1\nline2\nabc /path/to/main.dart.dill' - )) - )); + when(mockFrontendServer.stdout) + .thenAnswer((Invocation invocation) => new Stream>.fromFuture( + new Future>.value(UTF8.encode( + 'result abc\nline1\nline2\nabc /path/to/main.dart.dill' + )) + )); final String output = await compile(sdkRoot: '/path/to/sdkroot', mainPath: '/path/to/main.dart' ); @@ -55,11 +58,12 @@ void main() { testUsingContext('single dart failed compilation', () async { final BufferLogger logger = context[Logger]; - when(mockFrontendServer.stdout).thenReturn(new Stream>.fromFuture( - new Future>.value(UTF8.encode( - 'result abc\nline1\nline2\nabc' - )) - )); + when(mockFrontendServer.stdout) + .thenAnswer((Invocation invocation) => new Stream>.fromFuture( + new Future>.value(UTF8.encode( + 'result abc\nline1\nline2\nabc' + )) + )); final String output = await compile(sdkRoot: '/path/to/sdkroot', mainPath: '/path/to/main.dart' @@ -88,12 +92,14 @@ void main() { mockFrontendServerStdErr = new MockStream(); when(mockFrontendServer.stdin).thenReturn(mockFrontendServerStdIn); - when(mockFrontendServer.stderr).thenReturn(mockFrontendServerStdErr); + when(mockFrontendServer.stderr) + .thenAnswer((Invocation invocation) => mockFrontendServerStdErr); stdErrStreamController = new StreamController(); - when(mockFrontendServerStdErr.transform(any)).thenReturn(stdErrStreamController.stream); + when(mockFrontendServerStdErr.transform(any)) + .thenAnswer((Invocation invocation) => stdErrStreamController.stream); - when(mockProcessManager.start(any)).thenReturn( - new Future.value(mockFrontendServer) + when(mockProcessManager.start(any)).thenAnswer( + (Invocation invocation) => new Future.value(mockFrontendServer) ); when(mockFrontendServer.exitCode).thenReturn(0); }); @@ -101,11 +107,12 @@ void main() { testUsingContext('single dart compile', () async { final BufferLogger logger = context[Logger]; - when(mockFrontendServer.stdout).thenReturn(new Stream>.fromFuture( - new Future>.value(UTF8.encode( - 'result abc\nline1\nline2\nabc /path/to/main.dart.dill' - )) - )); + when(mockFrontendServer.stdout) + .thenAnswer((Invocation invocation) => new Stream>.fromFuture( + new Future>.value(UTF8.encode( + 'result abc\nline1\nline2\nabc /path/to/main.dart.dill' + )) + )); final String output = await generator.recompile( '/path/to/main.dart', null /* invalidatedFiles */ @@ -122,7 +129,8 @@ void main() { final BufferLogger logger = context[Logger]; final StreamController> streamController = new StreamController>(); - when(mockFrontendServer.stdout).thenReturn(streamController.stream); + when(mockFrontendServer.stdout) + .thenAnswer((Invocation invocation) => streamController.stream); streamController.add(UTF8.encode('result abc\nline0\nline1\nabc /path/to/main.dart.dill\n')); await generator.recompile('/path/to/main.dart', null /* invalidatedFiles */); expect(mockFrontendServerStdIn.getAndClear(), 'compile /path/to/main.dart\n'); @@ -144,7 +152,8 @@ void main() { final BufferLogger logger = context[Logger]; final StreamController> streamController = new StreamController>(); - when(mockFrontendServer.stdout).thenReturn(streamController.stream); + when(mockFrontendServer.stdout) + .thenAnswer((Invocation invocation) => streamController.stream); streamController.add(UTF8.encode( 'result abc\nline0\nline1\nabc /path/to/main.dart.dill\n' )); diff --git a/packages/flutter_tools/test/ios/code_signing_test.dart b/packages/flutter_tools/test/ios/code_signing_test.dart index 1432e4eed6..3e701cc683 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 @@ void main() { when(mockProcessManager.start( argThat(contains('openssl')), environment: any, workingDirectory: any, - )).thenReturn(new Future.value(mockProcess)); + )).thenAnswer((Invocation invocation) => new Future.value(mockProcess)); when(mockProcess.stdin).thenReturn(mockStdIn); - when(mockProcess.stdout).thenReturn(new Stream>.fromFuture( - new Future>.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>.fromFuture( + new Future>.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 @@ void main() { when(mockProcessManager.start( argThat(contains('openssl')), environment: any, workingDirectory: any, - )).thenReturn(new Future.value(mockOpenSslProcess)); + )).thenAnswer((Invocation invocation) => new Future.value(mockOpenSslProcess)); when(mockOpenSslProcess.stdin).thenReturn(mockOpenSslStdIn); - when(mockOpenSslProcess.stdout).thenReturn(new Stream>.fromFuture( - new Future>.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>.fromFuture( + new Future>.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 @@ void main() { when(mockProcessManager.start( argThat(contains('openssl')), environment: any, workingDirectory: any, - )).thenReturn(new Future.value(mockOpenSslProcess)); + )).thenAnswer((Invocation invocation) => new Future.value(mockOpenSslProcess)); when(mockOpenSslProcess.stdin).thenReturn(mockOpenSslStdIn); - when(mockOpenSslProcess.stdout).thenReturn(new Stream>.fromFuture( - new Future>.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>.fromFuture( + new Future>.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 @@ void main() { when(mockProcessManager.start( argThat(contains('openssl')), environment: any, workingDirectory: any, - )).thenReturn(new Future.value(mockOpenSslProcess)); + )).thenAnswer((Invocation invocation) => new Future.value(mockOpenSslProcess)); when(mockOpenSslProcess.stdin).thenReturn(mockOpenSslStdIn); - when(mockOpenSslProcess.stdout).thenReturn(new Stream>.fromFuture( - new Future>.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>.fromFuture( + new Future>.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 @@ void main() { when(mockProcessManager.start( argThat(contains('openssl')), environment: any, workingDirectory: any, - )).thenReturn(new Future.value(mockOpenSslProcess)); + )).thenAnswer((Invocation invocation) => new Future.value(mockOpenSslProcess)); when(mockOpenSslProcess.stdin).thenReturn(mockOpenSslStdIn); - when(mockOpenSslProcess.stdout).thenReturn(new Stream>.fromFuture( - new Future>.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>.fromFuture( + new Future>.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 e589c1c5f3..61b3356998 100644 --- a/packages/flutter_tools/test/ios/devices_test.dart +++ b/packages/flutter_tools/test/ios/devices_test.dart @@ -44,7 +44,8 @@ void main() { testUsingContext('returns no devices if none are attached', () async { when(iMobileDevice.isInstalled).thenReturn(true); - when(iMobileDevice.getAvailableDeviceIDs()).thenReturn(new Future.value('')); + when(iMobileDevice.getAvailableDeviceIDs()) + .thenAnswer((Invocation invocation) => new Future.value('')); final List devices = await IOSDevice.getAttachedDevices(); expect(devices, isEmpty); }, overrides: { @@ -53,7 +54,8 @@ void main() { testUsingContext('returns attached devices', () async { when(iMobileDevice.isInstalled).thenReturn(true); - when(iMobileDevice.getAvailableDeviceIDs()).thenReturn(new Future.value(''' + when(iMobileDevice.getAvailableDeviceIDs()) + .thenAnswer((Invocation invocation) => new Future.value(''' 98206e7a4afd4aedaff06e687594e089dede3c44 f577a7903cc54959be2e34bc4f7f80b7009efcf4 ''')); @@ -80,18 +82,21 @@ f577a7903cc54959be2e34bc4f7f80b7009efcf4 }); 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>.fromIterable(>[''' + when(mockProcess.stdout).thenAnswer((Invocation invocation) => + new Stream>.fromIterable(>[''' Runner(Flutter)[297] : A is for ari Runner(libsystem_asl.dylib)[297] : libMobileGestalt MobileGestaltSupport.m:153: pid 123 (Runner) does not have sandbox access for frZQaeyWLUvLjeuEK43hmg and IS NOT appropriately entitled Runner(libsystem_asl.dylib)[297] : libMobileGestalt MobileGestalt.c:550: no access to InverseDeviceID (see ) Runner(Flutter)[297] : I is for ichigo Runner(UIKit)[297] : E is for enpitsu" '''.codeUnits])); - when(mockProcess.stderr).thenReturn(const Stream>.empty()); + when(mockProcess.stderr) + .thenAnswer((Invocation invocation) => const Stream>.empty()); // Delay return of exitCode until after stdout stream data, since it terminates the logger. - when(mockProcess.exitCode).thenReturn(new Future.delayed(Duration.ZERO, () => 0)); + when(mockProcess.exitCode) + .thenAnswer((Invocation invocation) => new Future.delayed(Duration.ZERO, () => 0)); return new Future.value(mockProcess); }); diff --git a/packages/flutter_tools/test/ios/mac_test.dart b/packages/flutter_tools/test/ios/mac_test.dart index 812c4a1ead..60f38db016 100644 --- a/packages/flutter_tools/test/ios/mac_test.dart +++ b/packages/flutter_tools/test/ios/mac_test.dart @@ -81,8 +81,8 @@ void main() { testUsingContext('idevicescreenshot captures and returns screenshot', () async { when(mockOutputFile.path).thenReturn(outputPath); - when(mockProcessManager.run(any, environment: null, workingDirectory: null)) - .thenReturn(new Future.value(new ProcessResult(4, 0, '', ''))); + when(mockProcessManager.run(any, environment: null, workingDirectory: null)).thenAnswer( + (Invocation invocation) => new Future.value(new ProcessResult(4, 0, '', ''))); await iMobileDevice.takeScreenshot(mockOutputFile); verify(mockProcessManager.run(['idevicescreenshot', outputPath], diff --git a/packages/flutter_tools/test/ios/simulators_test.dart b/packages/flutter_tools/test/ios/simulators_test.dart index 8cca0dbeb3..abdc4e037a 100644 --- a/packages/flutter_tools/test/ios/simulators_test.dart +++ b/packages/flutter_tools/test/ios/simulators_test.dart @@ -152,7 +152,7 @@ void main() { // 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.value(new ProcessResult(2, 0, '', '')) ); // Doesn't matter what the device is. @@ -206,7 +206,7 @@ void main() { setUp(() { mockProcessManager = new MockProcessManager(); when(mockProcessManager.start(any, environment: null, workingDirectory: null)) - .thenReturn(new Future.value(new MockProcess())); + .thenAnswer((Invocation invocation) => new Future.value(new MockProcess())); }); testUsingContext('uses tail on iOS versions prior to iOS 11', () async { @@ -240,7 +240,7 @@ void main() { setUp(() { mockProcessManager = new MockProcessManager(); when(mockProcessManager.start(any, environment: null, workingDirectory: null)) - .thenReturn(new Future.value(new MockProcess())); + .thenAnswer((Invocation invocation) => new Future.value(new MockProcess())); }); testUsingContext('uses tail on iOS versions prior to iOS 11', () async { diff --git a/packages/flutter_tools/test/stop_test.dart b/packages/flutter_tools/test/stop_test.dart index 8109418ce5..fab854e896 100644 --- a/packages/flutter_tools/test/stop_test.dart +++ b/packages/flutter_tools/test/stop_test.dart @@ -23,7 +23,7 @@ void main() { final StopCommand command = new StopCommand(); applyMocksToCommand(command); final MockAndroidDevice device = new MockAndroidDevice(); - when(device.stopApp(any)).thenReturn(new Future.value(true)); + when(device.stopApp(any)).thenAnswer((Invocation invocation) => new Future.value(true)); testDeviceManager.addDevice(device); await createTestCommandRunner(command).run(['stop']); }); @@ -32,7 +32,7 @@ void main() { final StopCommand command = new StopCommand(); applyMocksToCommand(command); final MockIOSDevice device = new MockIOSDevice(); - when(device.stopApp(any)).thenReturn(new Future.value(true)); + when(device.stopApp(any)).thenAnswer((Invocation invocation) => new Future.value(true)); testDeviceManager.addDevice(device); await createTestCommandRunner(command).run(['stop']);