Commit 8283ce87 authored by Devon Carew's avatar Devon Carew

fix the stop command tests

parent 932b09c3
...@@ -236,17 +236,17 @@ class AppDomain extends Domain { ...@@ -236,17 +236,17 @@ class AppDomain extends Domain {
} }
Future<dynamic> start(Map<String, dynamic> args) async { Future<dynamic> start(Map<String, dynamic> args) async {
if (args['deviceId'] is! String) if (args == null || args['deviceId'] is! String)
throw "A 'deviceId' is required"; throw "deviceId is required";
Device device = await _getDevice(args['deviceId']); Device device = await _getDevice(args['deviceId']);
if (device == null) if (device == null)
throw "A 'projectDirectory' is required"; throw "device '${args['deviceId']}' not found";
if (args['projectDirectory'] is! String) if (args['projectDirectory'] is! String)
throw "A 'projectDirectory' is required"; throw "projectDirectory is required";
String projectDirectory = args['projectDirectory']; String projectDirectory = args['projectDirectory'];
if (!FileSystemEntity.isDirectorySync(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. // 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. // TODO(devoncarew): Make flutter_tools work better with commands run from any directory.
...@@ -280,17 +280,17 @@ class AppDomain extends Domain { ...@@ -280,17 +280,17 @@ class AppDomain extends Domain {
} }
Future<bool> stop(dynamic args) async { Future<bool> stop(dynamic args) async {
if (args['deviceId'] is! String) if (args == null || args['deviceId'] is! String)
throw "A 'deviceId' is required"; throw "deviceId is required";
Device device = await _getDevice(args['deviceId']); Device device = await _getDevice(args['deviceId']);
if (device == null) if (device == null)
throw "A 'projectDirectory' is required"; throw "device '${args['deviceId']}' not found";
if (args['projectDirectory'] is! String) if (args['projectDirectory'] is! String)
throw "A 'projectDirectory' is required"; throw "projectDirectory is required";
String projectDirectory = args['projectDirectory']; String projectDirectory = args['projectDirectory'];
if (!FileSystemEntity.isDirectorySync(projectDirectory)) if (!FileSystemEntity.isDirectorySync(projectDirectory))
throw "The '$projectDirectory' does not exist"; throw "'$projectDirectory' does not exist";
Directory cwd = Directory.current; Directory cwd = Directory.current;
Directory.current = new Directory(projectDirectory); Directory.current = new Directory(projectDirectory);
......
...@@ -12,7 +12,6 @@ import 'package:flutter_tools/src/device.dart'; ...@@ -12,7 +12,6 @@ import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/doctor.dart'; import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/globals.dart'; import 'package:flutter_tools/src/globals.dart';
import 'package:flutter_tools/src/ios/mac.dart'; import 'package:flutter_tools/src/ios/mac.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'src/context.dart'; import 'src/context.dart';
...@@ -97,7 +96,7 @@ defineTests() { ...@@ -97,7 +96,7 @@ defineTests() {
}); });
}); });
_testUsingContext('daemon.stopAll', () async { _testUsingContext('daemon.stop', () async {
DaemonCommand command = new DaemonCommand(); DaemonCommand command = new DaemonCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
...@@ -110,16 +109,10 @@ defineTests() { ...@@ -110,16 +109,10 @@ defineTests() {
notifyingLogger: notifyingLogger notifyingLogger: notifyingLogger
); );
MockDeviceStore mockDevices = command.devices; commands.add(<String, dynamic>{ 'id': 0, 'method': 'app.stop' });
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'});
Map response = await responses.stream.where(_notEvent).first; Map response = await responses.stream.where(_notEvent).first;
expect(response['id'], 0); expect(response['id'], 0);
expect(response['result'], true); expect(response['error'], contains('deviceId is required'));
}); });
_testUsingContext('device.getDevices', () async { _testUsingContext('device.getDevices', () async {
......
...@@ -45,8 +45,11 @@ void testUsingContext(String description, dynamic testMethod(), { ...@@ -45,8 +45,11 @@ void testUsingContext(String description, dynamic testMethod(), {
if (!overrides.containsKey(SimControl)) if (!overrides.containsKey(SimControl))
testContext[SimControl] = new MockSimControl(); testContext[SimControl] = new MockSimControl();
if (!overrides.containsKey(OperatingSystemUtils)) if (!overrides.containsKey(OperatingSystemUtils)) {
testContext[OperatingSystemUtils] = new MockOperatingSystemUtils(); MockOperatingSystemUtils os = new MockOperatingSystemUtils();
when(os.isWindows).thenReturn(false);
testContext[OperatingSystemUtils] = os;
}
if (!overrides.containsKey(IOSSimulatorUtils)) { if (!overrides.containsKey(IOSSimulatorUtils)) {
MockIOSSimulatorUtils mock = new MockIOSSimulatorUtils(); MockIOSSimulatorUtils mock = new MockIOSSimulatorUtils();
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async';
import 'package:flutter_tools/src/commands/stop.dart'; import 'package:flutter_tools/src/commands/stop.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
...@@ -17,12 +19,9 @@ defineTests() { ...@@ -17,12 +19,9 @@ defineTests() {
testUsingContext('returns 0 when Android is connected and ready to be stopped', () { testUsingContext('returns 0 when Android is connected and ready to be stopped', () {
StopCommand command = new StopCommand(); StopCommand command = new StopCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
MockDeviceStore mockDevices = command.devices; MockAndroidDevice device = new MockAndroidDevice();
when(device.stopApp(any)).thenReturn(new Future.value(true));
when(mockDevices.android.stopApp(any)).thenReturn(true); testDeviceManager.addDevice(device);
when(mockDevices.iOS.stopApp(any)).thenReturn(false);
when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false);
return createTestCommandRunner(command).run(['stop']).then((int code) { return createTestCommandRunner(command).run(['stop']).then((int code) {
expect(code, equals(0)); expect(code, equals(0));
}); });
...@@ -31,11 +30,9 @@ defineTests() { ...@@ -31,11 +30,9 @@ defineTests() {
testUsingContext('returns 0 when iOS is connected and ready to be stopped', () { testUsingContext('returns 0 when iOS is connected and ready to be stopped', () {
StopCommand command = new StopCommand(); StopCommand command = new StopCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
MockDeviceStore mockDevices = command.devices; MockIOSDevice device = new MockIOSDevice();
when(device.stopApp(any)).thenReturn(new Future.value(true));
when(mockDevices.android.stopApp(any)).thenReturn(false); testDeviceManager.addDevice(device);
when(mockDevices.iOS.stopApp(any)).thenReturn(true);
when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false);
return createTestCommandRunner(command).run(['stop']).then((int code) { return createTestCommandRunner(command).run(['stop']).then((int code) {
expect(code, equals(0)); expect(code, equals(0));
......
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