Commit 30720bd1 authored by Alan Russian's avatar Alan Russian Committed by Yegor

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
parent 78ff7707
...@@ -40,8 +40,8 @@ void main() { ...@@ -40,8 +40,8 @@ void main() {
when(mockClient.getVM()).thenReturn(mockVM); when(mockClient.getVM()).thenReturn(mockVM);
when(mockVM.isolates).thenReturn(<VMRunnableIsolate>[mockIsolate]); when(mockVM.isolates).thenReturn(<VMRunnableIsolate>[mockIsolate]);
when(mockIsolate.loadRunnable()).thenReturn(mockIsolate); when(mockIsolate.loadRunnable()).thenReturn(mockIsolate);
when(mockIsolate.invokeExtension(any, any)) when(mockIsolate.invokeExtension(any, any)).thenAnswer(
.thenReturn(makeMockResponse(<String, dynamic>{'status': 'ok'})); (Invocation invocation) => makeMockResponse(<String, dynamic>{'status': 'ok'}));
vmServiceConnectFunction = (String url) { vmServiceConnectFunction = (String url) {
return new Future<VMServiceClientConnection>.value( return new Future<VMServiceClientConnection>.value(
new VMServiceClientConnection(mockClient, mockPeer) new VMServiceClientConnection(mockClient, mockPeer)
...@@ -56,16 +56,16 @@ void main() { ...@@ -56,16 +56,16 @@ void main() {
test('connects to isolate paused at start', () async { test('connects to isolate paused at start', () async {
final List<String> connectionLog = <String>[]; final List<String> connectionLog = <String>[];
when(mockPeer.sendRequest('streamListen', any)).thenAnswer((_) { when(mockPeer.sendRequest('streamListen', any)).thenAnswer((Invocation invocation) {
connectionLog.add('streamListen'); connectionLog.add('streamListen');
return null; return null;
}); });
when(mockIsolate.pauseEvent).thenReturn(new MockVMPauseStartEvent()); when(mockIsolate.pauseEvent).thenReturn(new MockVMPauseStartEvent());
when(mockIsolate.resume()).thenAnswer((_) { when(mockIsolate.resume()).thenAnswer((Invocation invocation) {
connectionLog.add('resume'); connectionLog.add('resume');
return new Future<Null>.value(); return new Future<Null>.value();
}); });
when(mockIsolate.onExtensionAdded).thenAnswer((_) { when(mockIsolate.onExtensionAdded).thenAnswer((Invocation invocation) {
connectionLog.add('onExtensionAdded'); connectionLog.add('onExtensionAdded');
return new Stream<String>.fromIterable(<String>['ext.flutter.driver']); return new Stream<String>.fromIterable(<String>['ext.flutter.driver']);
}); });
...@@ -78,7 +78,7 @@ void main() { ...@@ -78,7 +78,7 @@ void main() {
test('connects to isolate paused mid-flight', () async { test('connects to isolate paused mid-flight', () async {
when(mockIsolate.pauseEvent).thenReturn(new MockVMPauseBreakpointEvent()); when(mockIsolate.pauseEvent).thenReturn(new MockVMPauseBreakpointEvent());
when(mockIsolate.resume()).thenReturn(new Future<Null>.value()); when(mockIsolate.resume()).thenAnswer((Invocation invocation) => new Future<Null>.value());
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: ''); final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
expect(driver, isNotNull); expect(driver, isNotNull);
...@@ -91,7 +91,7 @@ void main() { ...@@ -91,7 +91,7 @@ void main() {
// just fine. // just fine.
test('connects despite losing the race to resume isolate', () async { test('connects despite losing the race to resume isolate', () async {
when(mockIsolate.pauseEvent).thenReturn(new MockVMPauseBreakpointEvent()); 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 // This needs to be wrapped in a closure to not be considered uncaught
// by package:test // by package:test
return new Future<Null>.error(new rpc.RpcException(101, '')); return new Future<Null>.error(new rpc.RpcException(101, ''));
...@@ -124,14 +124,14 @@ void main() { ...@@ -124,14 +124,14 @@ void main() {
}); });
test('checks the health of the driver extension', () async { test('checks the health of the driver extension', () async {
when(mockIsolate.invokeExtension(any, any)).thenReturn( when(mockIsolate.invokeExtension(any, any)).thenAnswer(
makeMockResponse(<String, dynamic>{'status': 'ok'})); (Invocation invocation) => makeMockResponse(<String, dynamic>{'status': 'ok'}));
final Health result = await driver.checkHealth(); final Health result = await driver.checkHealth();
expect(result.status, HealthStatus.ok); expect(result.status, HealthStatus.ok);
}); });
test('closes connection', () async { test('closes connection', () async {
when(mockClient.close()).thenReturn(new Future<Null>.value()); when(mockClient.close()).thenAnswer((Invocation invocation) => new Future<Null>.value());
await driver.close(); await driver.close();
}); });
...@@ -234,7 +234,7 @@ void main() { ...@@ -234,7 +234,7 @@ void main() {
test('clears timeline', () async { test('clears timeline', () async {
bool clearWasCalled = false; bool clearWasCalled = false;
when(mockPeer.sendRequest('_clearVMTimeline', argThat(equals(<String, dynamic>{})))) when(mockPeer.sendRequest('_clearVMTimeline', argThat(equals(<String, dynamic>{}))))
.thenAnswer((_) async { .thenAnswer((Invocation invocation) async {
clearWasCalled = true; clearWasCalled = true;
return null; return null;
}); });
...@@ -250,24 +250,24 @@ void main() { ...@@ -250,24 +250,24 @@ void main() {
log = <String>[]; log = <String>[];
when(mockPeer.sendRequest('_clearVMTimeline', argThat(equals(<String, dynamic>{})))) when(mockPeer.sendRequest('_clearVMTimeline', argThat(equals(<String, dynamic>{}))))
.thenAnswer((_) async { .thenAnswer((Invocation invocation) async {
log.add('clear'); log.add('clear');
return null; return null;
}); });
when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[all]'})))) when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[all]'}))))
.thenAnswer((_) async { .thenAnswer((Invocation invocation) async {
log.add('startTracing'); log.add('startTracing');
return null; return null;
}); });
when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[]'})))) when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[]'}))))
.thenAnswer((_) async { .thenAnswer((Invocation invocation) async {
log.add('stopTracing'); log.add('stopTracing');
return null; return null;
}); });
when(mockPeer.sendRequest('_getVMTimeline')).thenAnswer((_) async { when(mockPeer.sendRequest('_getVMTimeline')).thenAnswer((Invocation invocation) async {
log.add('download'); log.add('download');
return <String, dynamic> { return <String, dynamic> {
'traceEvents': <dynamic>[ 'traceEvents': <dynamic>[
...@@ -316,18 +316,18 @@ void main() { ...@@ -316,18 +316,18 @@ void main() {
bool stopTracingCalled = false; bool stopTracingCalled = false;
when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[Dart, GC, Compiler]'})))) when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[Dart, GC, Compiler]'}))))
.thenAnswer((_) async { .thenAnswer((Invocation invocation) async {
startTracingCalled = true; startTracingCalled = true;
return null; return null;
}); });
when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[]'})))) when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[]'}))))
.thenAnswer((_) async { .thenAnswer((Invocation invocation) async {
stopTracingCalled = true; stopTracingCalled = true;
return null; return null;
}); });
when(mockPeer.sendRequest('_getVMTimeline')).thenAnswer((_) async { when(mockPeer.sendRequest('_getVMTimeline')).thenAnswer((Invocation invocation) async {
return <String, dynamic> { return <String, dynamic> {
'traceEvents': <dynamic>[ 'traceEvents': <dynamic>[
<String, String>{ <String, String>{
......
...@@ -19,7 +19,7 @@ void main() { ...@@ -19,7 +19,7 @@ void main() {
final ProcessSignal signalUnderTest = new ProcessSignal(mockSignal); final ProcessSignal signalUnderTest = new ProcessSignal(mockSignal);
final StreamController<io.ProcessSignal> controller = new StreamController<io.ProcessSignal>(); final StreamController<io.ProcessSignal> controller = new StreamController<io.ProcessSignal>();
when(mockSignal.watch()).thenReturn(controller.stream); when(mockSignal.watch()).thenAnswer((Invocation invocation) => controller.stream);
controller.add(mockSignal); controller.add(mockSignal);
expect(signalUnderTest, await signalUnderTest.watch().first); expect(signalUnderTest, await signalUnderTest.watch().first);
...@@ -31,4 +31,4 @@ void main() { ...@@ -31,4 +31,4 @@ void main() {
}); });
} }
class MockIoProcessSignal extends Mock implements io.ProcessSignal {} class MockIoProcessSignal extends Mock implements io.ProcessSignal {}
\ No newline at end of file
...@@ -279,7 +279,8 @@ void main() { ...@@ -279,7 +279,8 @@ void main() {
testUsingContext('uses existing simulator', () async { testUsingContext('uses existing simulator', () async {
withMockDevice(); withMockDevice();
when(mockDevice.name).thenReturn('mock-simulator'); when(mockDevice.name).thenReturn('mock-simulator');
when(mockDevice.isLocalEmulator).thenReturn(new Future<bool>.value(true)); when(mockDevice.isLocalEmulator)
.thenAnswer((Invocation invocation) => new Future<bool>.value(true));
final Device device = await findTargetDevice(); final Device device = await findTargetDevice();
expect(device.name, 'mock-simulator'); expect(device.name, 'mock-simulator');
......
...@@ -27,21 +27,24 @@ void main() { ...@@ -27,21 +27,24 @@ void main() {
mockFrontendServerStdIn = new MockStdIn(); mockFrontendServerStdIn = new MockStdIn();
mockFrontendServerStdErr = new MockStream(); mockFrontendServerStdErr = new MockStream();
when(mockFrontendServer.stderr).thenReturn(mockFrontendServerStdErr); when(mockFrontendServer.stderr)
.thenAnswer((Invocation invocation) => mockFrontendServerStdErr);
final StreamController<String> stdErrStreamController = new StreamController<String>(); final StreamController<String> stdErrStreamController = new StreamController<String>();
when(mockFrontendServerStdErr.transform<String>(any)).thenReturn(stdErrStreamController.stream); when(mockFrontendServerStdErr.transform<String>(any)).thenReturn(stdErrStreamController.stream);
when(mockFrontendServer.stdin).thenReturn(mockFrontendServerStdIn); when(mockFrontendServer.stdin).thenReturn(mockFrontendServerStdIn);
when(mockProcessManager.start(any)).thenReturn(new Future<Process>.value(mockFrontendServer)); when(mockProcessManager.start(any)).thenAnswer(
(Invocation invocation) => new Future<Process>.value(mockFrontendServer));
when(mockFrontendServer.exitCode).thenReturn(0); when(mockFrontendServer.exitCode).thenReturn(0);
}); });
testUsingContext('single dart successful compilation', () async { testUsingContext('single dart successful compilation', () async {
final BufferLogger logger = context[Logger]; final BufferLogger logger = context[Logger];
when(mockFrontendServer.stdout).thenReturn(new Stream<List<int>>.fromFuture( when(mockFrontendServer.stdout)
new Future<List<int>>.value(UTF8.encode( .thenAnswer((Invocation invocation) => new Stream<List<int>>.fromFuture(
'result abc\nline1\nline2\nabc /path/to/main.dart.dill' new Future<List<int>>.value(UTF8.encode(
)) 'result abc\nline1\nline2\nabc /path/to/main.dart.dill'
)); ))
));
final String output = await compile(sdkRoot: '/path/to/sdkroot', final String output = await compile(sdkRoot: '/path/to/sdkroot',
mainPath: '/path/to/main.dart' mainPath: '/path/to/main.dart'
); );
...@@ -55,11 +58,12 @@ void main() { ...@@ -55,11 +58,12 @@ void main() {
testUsingContext('single dart failed compilation', () async { testUsingContext('single dart failed compilation', () async {
final BufferLogger logger = context[Logger]; final BufferLogger logger = context[Logger];
when(mockFrontendServer.stdout).thenReturn(new Stream<List<int>>.fromFuture( when(mockFrontendServer.stdout)
new Future<List<int>>.value(UTF8.encode( .thenAnswer((Invocation invocation) => new Stream<List<int>>.fromFuture(
'result abc\nline1\nline2\nabc' new Future<List<int>>.value(UTF8.encode(
)) 'result abc\nline1\nline2\nabc'
)); ))
));
final String output = await compile(sdkRoot: '/path/to/sdkroot', final String output = await compile(sdkRoot: '/path/to/sdkroot',
mainPath: '/path/to/main.dart' mainPath: '/path/to/main.dart'
...@@ -88,12 +92,14 @@ void main() { ...@@ -88,12 +92,14 @@ void main() {
mockFrontendServerStdErr = new MockStream(); mockFrontendServerStdErr = new MockStream();
when(mockFrontendServer.stdin).thenReturn(mockFrontendServerStdIn); when(mockFrontendServer.stdin).thenReturn(mockFrontendServerStdIn);
when(mockFrontendServer.stderr).thenReturn(mockFrontendServerStdErr); when(mockFrontendServer.stderr)
.thenAnswer((Invocation invocation) => mockFrontendServerStdErr);
stdErrStreamController = new StreamController<String>(); stdErrStreamController = new StreamController<String>();
when(mockFrontendServerStdErr.transform<String>(any)).thenReturn(stdErrStreamController.stream); when(mockFrontendServerStdErr.transform<String>(any))
.thenAnswer((Invocation invocation) => stdErrStreamController.stream);
when(mockProcessManager.start(any)).thenReturn( when(mockProcessManager.start(any)).thenAnswer(
new Future<Process>.value(mockFrontendServer) (Invocation invocation) => new Future<Process>.value(mockFrontendServer)
); );
when(mockFrontendServer.exitCode).thenReturn(0); when(mockFrontendServer.exitCode).thenReturn(0);
}); });
...@@ -101,11 +107,12 @@ void main() { ...@@ -101,11 +107,12 @@ void main() {
testUsingContext('single dart compile', () async { testUsingContext('single dart compile', () async {
final BufferLogger logger = context[Logger]; final BufferLogger logger = context[Logger];
when(mockFrontendServer.stdout).thenReturn(new Stream<List<int>>.fromFuture( when(mockFrontendServer.stdout)
new Future<List<int>>.value(UTF8.encode( .thenAnswer((Invocation invocation) => new Stream<List<int>>.fromFuture(
'result abc\nline1\nline2\nabc /path/to/main.dart.dill' new Future<List<int>>.value(UTF8.encode(
)) 'result abc\nline1\nline2\nabc /path/to/main.dart.dill'
)); ))
));
final String output = await generator.recompile( final String output = await generator.recompile(
'/path/to/main.dart', null /* invalidatedFiles */ '/path/to/main.dart', null /* invalidatedFiles */
...@@ -122,7 +129,8 @@ void main() { ...@@ -122,7 +129,8 @@ void main() {
final BufferLogger logger = context[Logger]; final BufferLogger logger = context[Logger];
final StreamController<List<int>> streamController = new StreamController<List<int>>(); final StreamController<List<int>> streamController = new StreamController<List<int>>();
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')); streamController.add(UTF8.encode('result abc\nline0\nline1\nabc /path/to/main.dart.dill\n'));
await generator.recompile('/path/to/main.dart', null /* invalidatedFiles */); await generator.recompile('/path/to/main.dart', null /* invalidatedFiles */);
expect(mockFrontendServerStdIn.getAndClear(), 'compile /path/to/main.dart\n'); expect(mockFrontendServerStdIn.getAndClear(), 'compile /path/to/main.dart\n');
...@@ -144,7 +152,8 @@ void main() { ...@@ -144,7 +152,8 @@ void main() {
final BufferLogger logger = context[Logger]; final BufferLogger logger = context[Logger];
final StreamController<List<int>> streamController = new StreamController<List<int>>(); final StreamController<List<int>> streamController = new StreamController<List<int>>();
when(mockFrontendServer.stdout).thenReturn(streamController.stream); when(mockFrontendServer.stdout)
.thenAnswer((Invocation invocation) => streamController.stream);
streamController.add(UTF8.encode( streamController.add(UTF8.encode(
'result abc\nline0\nline1\nabc /path/to/main.dart.dill\n' 'result abc\nline0\nline1\nabc /path/to/main.dart.dill\n'
)); ));
......
...@@ -120,15 +120,16 @@ void main() { ...@@ -120,15 +120,16 @@ void main() {
when(mockProcessManager.start( when(mockProcessManager.start(
argThat(contains('openssl')), environment: any, workingDirectory: any, 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.stdin).thenReturn(mockStdIn);
when(mockProcess.stdout).thenReturn(new Stream<List<int>>.fromFuture( when(mockProcess.stdout)
new Future<List<int>>.value(UTF8.encode( .thenAnswer((Invocation invocation) => new Stream<List<int>>.fromFuture(
'subject= /CN=iPhone Developer: Profile 1 (1111AAAA11)/OU=3333CCCC33/O=My Team/C=US' 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.stderr).thenAnswer((Invocation invocation) => mockStdErr);
when(mockProcess.exitCode).thenReturn(0); when(mockProcess.exitCode).thenReturn(0);
final String developmentTeam = await getCodeSigningIdentityDevelopmentTeam(iosApp: app); final String developmentTeam = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
...@@ -178,15 +179,16 @@ void main() { ...@@ -178,15 +179,16 @@ void main() {
when(mockProcessManager.start( when(mockProcessManager.start(
argThat(contains('openssl')), environment: any, workingDirectory: any, 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.stdin).thenReturn(mockOpenSslStdIn);
when(mockOpenSslProcess.stdout).thenReturn(new Stream<List<int>>.fromFuture( when(mockOpenSslProcess.stdout)
new Future<List<int>>.value(UTF8.encode( .thenAnswer((Invocation invocation) => new Stream<List<int>>.fromFuture(
'subject= /CN=iPhone Developer: Profile 3 (3333CCCC33)/OU=4444DDDD44/O=My Team/C=US' 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.stderr).thenAnswer((Invocation invocation) => mockOpenSslStdErr);
when(mockOpenSslProcess.exitCode).thenReturn(0); when(mockOpenSslProcess.exitCode).thenReturn(0);
final String developmentTeam = await getCodeSigningIdentityDevelopmentTeam(iosApp: app); final String developmentTeam = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
...@@ -247,15 +249,16 @@ void main() { ...@@ -247,15 +249,16 @@ void main() {
when(mockProcessManager.start( when(mockProcessManager.start(
argThat(contains('openssl')), environment: any, workingDirectory: any, 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.stdin).thenReturn(mockOpenSslStdIn);
when(mockOpenSslProcess.stdout).thenReturn(new Stream<List<int>>.fromFuture( when(mockOpenSslProcess.stdout)
new Future<List<int>>.value(UTF8.encode( .thenAnswer((Invocation invocation) => new Stream<List<int>>.fromFuture(
'subject= /CN=iPhone Developer: Profile 1 (1111AAAA11)/OU=5555EEEE55/O=My Team/C=US' 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.stderr).thenAnswer((Invocation invocation) => mockOpenSslStdErr);
when(mockOpenSslProcess.exitCode).thenReturn(0); when(mockOpenSslProcess.exitCode).thenReturn(0);
final String developmentTeam = await getCodeSigningIdentityDevelopmentTeam(iosApp: app, usesTerminalUi: false); final String developmentTeam = await getCodeSigningIdentityDevelopmentTeam(iosApp: app, usesTerminalUi: false);
...@@ -308,15 +311,16 @@ void main() { ...@@ -308,15 +311,16 @@ void main() {
when(mockProcessManager.start( when(mockProcessManager.start(
argThat(contains('openssl')), environment: any, workingDirectory: any, 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.stdin).thenReturn(mockOpenSslStdIn);
when(mockOpenSslProcess.stdout).thenReturn(new Stream<List<int>>.fromFuture( when(mockOpenSslProcess.stdout)
new Future<List<int>>.value(UTF8.encode( .thenAnswer((Invocation invocation) => new Stream<List<int>>.fromFuture(
'subject= /CN=iPhone Developer: Profile 3 (3333CCCC33)/OU=4444DDDD44/O=My Team/C=US' 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.stderr).thenAnswer((Invocation invocation) => mockOpenSslStdErr);
when(mockOpenSslProcess.exitCode).thenReturn(0); when(mockOpenSslProcess.exitCode).thenReturn(0);
when(mockConfig.getValue('ios-signing-cert')).thenReturn('iPhone Developer: Profile 3 (3333CCCC33)'); when(mockConfig.getValue('ios-signing-cert')).thenReturn('iPhone Developer: Profile 3 (3333CCCC33)');
...@@ -376,15 +380,16 @@ void main() { ...@@ -376,15 +380,16 @@ void main() {
when(mockProcessManager.start( when(mockProcessManager.start(
argThat(contains('openssl')), environment: any, workingDirectory: any, 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.stdin).thenReturn(mockOpenSslStdIn);
when(mockOpenSslProcess.stdout).thenReturn(new Stream<List<int>>.fromFuture( when(mockOpenSslProcess.stdout)
new Future<List<int>>.value(UTF8.encode( .thenAnswer((Invocation invocation) => new Stream<List<int>>.fromFuture(
'subject= /CN=iPhone Developer: Profile 3 (3333CCCC33)/OU=4444DDDD44/O=My Team/C=US' 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.stderr).thenAnswer((Invocation invocation) => mockOpenSslStdErr);
when(mockOpenSslProcess.exitCode).thenReturn(0); when(mockOpenSslProcess.exitCode).thenReturn(0);
when(mockConfig.getValue('ios-signing-cert')).thenReturn('iPhone Developer: Invalid Profile'); when(mockConfig.getValue('ios-signing-cert')).thenReturn('iPhone Developer: Invalid Profile');
......
...@@ -44,7 +44,8 @@ void main() { ...@@ -44,7 +44,8 @@ void main() {
testUsingContext('returns no devices if none are attached', () async { testUsingContext('returns no devices if none are attached', () async {
when(iMobileDevice.isInstalled).thenReturn(true); 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(); final List<IOSDevice> devices = await IOSDevice.getAttachedDevices();
expect(devices, isEmpty); expect(devices, isEmpty);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -53,7 +54,8 @@ void main() { ...@@ -53,7 +54,8 @@ void main() {
testUsingContext('returns attached devices', () async { testUsingContext('returns attached devices', () async {
when(iMobileDevice.isInstalled).thenReturn(true); when(iMobileDevice.isInstalled).thenReturn(true);
when(iMobileDevice.getAvailableDeviceIDs()).thenReturn(new Future<String>.value(''' when(iMobileDevice.getAvailableDeviceIDs())
.thenAnswer((Invocation invocation) => new Future<String>.value('''
98206e7a4afd4aedaff06e687594e089dede3c44 98206e7a4afd4aedaff06e687594e089dede3c44
f577a7903cc54959be2e34bc4f7f80b7009efcf4 f577a7903cc54959be2e34bc4f7f80b7009efcf4
''')); '''));
...@@ -80,18 +82,21 @@ f577a7903cc54959be2e34bc4f7f80b7009efcf4 ...@@ -80,18 +82,21 @@ f577a7903cc54959be2e34bc4f7f80b7009efcf4
}); });
testUsingContext('suppresses non-Flutter lines from output', () async { testUsingContext('suppresses non-Flutter lines from output', () async {
when(mockIMobileDevice.startLogger()).thenAnswer((_) { when(mockIMobileDevice.startLogger()).thenAnswer((Invocation invocation) {
final Process mockProcess = new MockProcess(); 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(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 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(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(Flutter)[297] <Notice>: I is for ichigo
Runner(UIKit)[297] <Notice>: E is for enpitsu" Runner(UIKit)[297] <Notice>: E is for enpitsu"
'''.codeUnits])); '''.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. // 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); return new Future<Process>.value(mockProcess);
}); });
......
...@@ -81,8 +81,8 @@ void main() { ...@@ -81,8 +81,8 @@ void main() {
testUsingContext('idevicescreenshot captures and returns screenshot', () async { testUsingContext('idevicescreenshot captures and returns screenshot', () async {
when(mockOutputFile.path).thenReturn(outputPath); when(mockOutputFile.path).thenReturn(outputPath);
when(mockProcessManager.run(any, environment: null, workingDirectory: null)) when(mockProcessManager.run(any, environment: null, workingDirectory: null)).thenAnswer(
.thenReturn(new Future<ProcessResult>.value(new ProcessResult(4, 0, '', ''))); (Invocation invocation) => new Future<ProcessResult>.value(new ProcessResult(4, 0, '', '')));
await iMobileDevice.takeScreenshot(mockOutputFile); await iMobileDevice.takeScreenshot(mockOutputFile);
verify(mockProcessManager.run(<String>['idevicescreenshot', outputPath], verify(mockProcessManager.run(<String>['idevicescreenshot', outputPath],
......
...@@ -152,7 +152,7 @@ void main() { ...@@ -152,7 +152,7 @@ void main() {
// Let everything else return exit code 0 so process.dart doesn't crash. // Let everything else return exit code 0 so process.dart doesn't crash.
when( when(
mockProcessManager.run(any, environment: null, workingDirectory: null) mockProcessManager.run(any, environment: null, workingDirectory: null)
).thenReturn( ).thenAnswer((Invocation invocation) =>
new Future<ProcessResult>.value(new ProcessResult(2, 0, '', '')) new Future<ProcessResult>.value(new ProcessResult(2, 0, '', ''))
); );
// Doesn't matter what the device is. // Doesn't matter what the device is.
...@@ -206,7 +206,7 @@ void main() { ...@@ -206,7 +206,7 @@ void main() {
setUp(() { setUp(() {
mockProcessManager = new MockProcessManager(); mockProcessManager = new MockProcessManager();
when(mockProcessManager.start(any, environment: null, workingDirectory: null)) 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 { testUsingContext('uses tail on iOS versions prior to iOS 11', () async {
...@@ -240,7 +240,7 @@ void main() { ...@@ -240,7 +240,7 @@ void main() {
setUp(() { setUp(() {
mockProcessManager = new MockProcessManager(); mockProcessManager = new MockProcessManager();
when(mockProcessManager.start(any, environment: null, workingDirectory: null)) 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 { testUsingContext('uses tail on iOS versions prior to iOS 11', () async {
......
...@@ -23,7 +23,7 @@ void main() { ...@@ -23,7 +23,7 @@ void main() {
final StopCommand command = new StopCommand(); final StopCommand command = new StopCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
final MockAndroidDevice device = new MockAndroidDevice(); final MockAndroidDevice device = new MockAndroidDevice();
when(device.stopApp(any)).thenReturn(new Future<bool>.value(true)); when(device.stopApp(any)).thenAnswer((Invocation invocation) => new Future<bool>.value(true));
testDeviceManager.addDevice(device); testDeviceManager.addDevice(device);
await createTestCommandRunner(command).run(<String>['stop']); await createTestCommandRunner(command).run(<String>['stop']);
}); });
...@@ -32,7 +32,7 @@ void main() { ...@@ -32,7 +32,7 @@ void main() {
final StopCommand command = new StopCommand(); final StopCommand command = new StopCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
final MockIOSDevice device = new MockIOSDevice(); final MockIOSDevice device = new MockIOSDevice();
when(device.stopApp(any)).thenReturn(new Future<bool>.value(true)); when(device.stopApp(any)).thenAnswer((Invocation invocation) => new Future<bool>.value(true));
testDeviceManager.addDevice(device); testDeviceManager.addDevice(device);
await createTestCommandRunner(command).run(<String>['stop']); await createTestCommandRunner(command).run(<String>['stop']);
......
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