From 8283ce87e2abbae16c6e534f5c56e2753a3bd07f Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Thu, 3 Mar 2016 13:31:05 -0800 Subject: [PATCH] fix the stop command tests --- .../lib/src/commands/daemon.dart | 20 +++++++++---------- packages/flutter_tools/test/daemon_test.dart | 13 +++--------- packages/flutter_tools/test/src/context.dart | 7 +++++-- packages/flutter_tools/test/stop_test.dart | 19 ++++++++---------- 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index a98069d270..99fe8f3120 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -236,17 +236,17 @@ class AppDomain extends Domain { } Future start(Map args) async { - if (args['deviceId'] is! String) - throw "A 'deviceId' is required"; + if (args == null || args['deviceId'] is! String) + throw "deviceId is required"; Device device = await _getDevice(args['deviceId']); if (device == null) - throw "A 'projectDirectory' is required"; + throw "device '${args['deviceId']}' not found"; if (args['projectDirectory'] is! String) - throw "A 'projectDirectory' is required"; + throw "projectDirectory is required"; String projectDirectory = args['projectDirectory']; if (!FileSystemEntity.isDirectorySync(projectDirectory)) - throw "The '$projectDirectory' does not exist"; + throw "'$projectDirectory' does not exist"; // We change the current working directory for the duration of the `start` command. // TODO(devoncarew): Make flutter_tools work better with commands run from any directory. @@ -280,17 +280,17 @@ class AppDomain extends Domain { } Future stop(dynamic args) async { - if (args['deviceId'] is! String) - throw "A 'deviceId' is required"; + if (args == null || args['deviceId'] is! String) + throw "deviceId is required"; Device device = await _getDevice(args['deviceId']); if (device == null) - throw "A 'projectDirectory' is required"; + throw "device '${args['deviceId']}' not found"; if (args['projectDirectory'] is! String) - throw "A 'projectDirectory' is required"; + throw "projectDirectory is required"; String projectDirectory = args['projectDirectory']; if (!FileSystemEntity.isDirectorySync(projectDirectory)) - throw "The '$projectDirectory' does not exist"; + throw "'$projectDirectory' does not exist"; Directory cwd = Directory.current; Directory.current = new Directory(projectDirectory); diff --git a/packages/flutter_tools/test/daemon_test.dart b/packages/flutter_tools/test/daemon_test.dart index 5df8a089ae..9f986fc4f6 100644 --- a/packages/flutter_tools/test/daemon_test.dart +++ b/packages/flutter_tools/test/daemon_test.dart @@ -12,7 +12,6 @@ import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/doctor.dart'; import 'package:flutter_tools/src/globals.dart'; import 'package:flutter_tools/src/ios/mac.dart'; -import 'package:mockito/mockito.dart'; import 'package:test/test.dart'; import 'src/context.dart'; @@ -97,7 +96,7 @@ defineTests() { }); }); - _testUsingContext('daemon.stopAll', () async { + _testUsingContext('daemon.stop', () async { DaemonCommand command = new DaemonCommand(); applyMocksToCommand(command); @@ -110,16 +109,10 @@ defineTests() { notifyingLogger: notifyingLogger ); - MockDeviceStore mockDevices = command.devices; - - when(mockDevices.android.stopApp(any)).thenReturn(true); - when(mockDevices.iOS.stopApp(any)).thenReturn(false); - when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false); - - commands.add({'id': 0, 'method': 'app.stopAll'}); + commands.add({ 'id': 0, 'method': 'app.stop' }); Map response = await responses.stream.where(_notEvent).first; expect(response['id'], 0); - expect(response['result'], true); + expect(response['error'], contains('deviceId is required')); }); _testUsingContext('device.getDevices', () async { diff --git a/packages/flutter_tools/test/src/context.dart b/packages/flutter_tools/test/src/context.dart index 3683b10e7c..3ede26c92a 100644 --- a/packages/flutter_tools/test/src/context.dart +++ b/packages/flutter_tools/test/src/context.dart @@ -45,8 +45,11 @@ void testUsingContext(String description, dynamic testMethod(), { if (!overrides.containsKey(SimControl)) testContext[SimControl] = new MockSimControl(); - if (!overrides.containsKey(OperatingSystemUtils)) - testContext[OperatingSystemUtils] = new MockOperatingSystemUtils(); + if (!overrides.containsKey(OperatingSystemUtils)) { + MockOperatingSystemUtils os = new MockOperatingSystemUtils(); + when(os.isWindows).thenReturn(false); + testContext[OperatingSystemUtils] = os; + } if (!overrides.containsKey(IOSSimulatorUtils)) { MockIOSSimulatorUtils mock = new MockIOSSimulatorUtils(); diff --git a/packages/flutter_tools/test/stop_test.dart b/packages/flutter_tools/test/stop_test.dart index 82b733e182..112a9fc1ae 100644 --- a/packages/flutter_tools/test/stop_test.dart +++ b/packages/flutter_tools/test/stop_test.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:async'; + import 'package:flutter_tools/src/commands/stop.dart'; import 'package:mockito/mockito.dart'; import 'package:test/test.dart'; @@ -17,12 +19,9 @@ defineTests() { testUsingContext('returns 0 when Android is connected and ready to be stopped', () { StopCommand command = new StopCommand(); applyMocksToCommand(command); - MockDeviceStore mockDevices = command.devices; - - when(mockDevices.android.stopApp(any)).thenReturn(true); - when(mockDevices.iOS.stopApp(any)).thenReturn(false); - when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false); - + MockAndroidDevice device = new MockAndroidDevice(); + when(device.stopApp(any)).thenReturn(new Future.value(true)); + testDeviceManager.addDevice(device); return createTestCommandRunner(command).run(['stop']).then((int code) { expect(code, equals(0)); }); @@ -31,11 +30,9 @@ defineTests() { testUsingContext('returns 0 when iOS is connected and ready to be stopped', () { StopCommand command = new StopCommand(); applyMocksToCommand(command); - MockDeviceStore mockDevices = command.devices; - - when(mockDevices.android.stopApp(any)).thenReturn(false); - when(mockDevices.iOS.stopApp(any)).thenReturn(true); - when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false); + MockIOSDevice device = new MockIOSDevice(); + when(device.stopApp(any)).thenReturn(new Future.value(true)); + testDeviceManager.addDevice(device); return createTestCommandRunner(command).run(['stop']).then((int code) { expect(code, equals(0));