mocks.dart 1.98 KB
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter_tools/src/android/android_device.dart';
6 7 8
import 'package:flutter_tools/src/application_package.dart';
import 'package:flutter_tools/src/build_configuration.dart';
import 'package:flutter_tools/src/device.dart';
9 10
import 'package:flutter_tools/src/ios/devices.dart';
import 'package:flutter_tools/src/ios/simulators.dart';
11
import 'package:flutter_tools/src/runner/flutter_command.dart';
12
import 'package:flutter_tools/src/toolchain.dart';
13
import 'package:mockito/mockito.dart';
14 15 16 17

class MockApplicationPackageStore extends ApplicationPackageStore {
  MockApplicationPackageStore() : super(
    android: new AndroidApk(localPath: '/mock/path/to/android/SkyShell.apk'),
18 19 20 21 22
    iOS: new IOSApp(
      iosProjectDir: '/mock/path/to/iOS/SkyShell.app',
      iosProjectBundleId: 'io.flutter.ios.mock'
    )
  );
23 24
}

25 26 27 28 29 30 31
class MockCompiler extends Mock implements Compiler {
}

class MockToolchain extends Toolchain {
  MockToolchain() : super(compiler: new MockCompiler());
}

32
class MockAndroidDevice extends Mock implements AndroidDevice {
33
  TargetPlatform get platform => TargetPlatform.android;
34
  bool isSupported() => true;
35 36 37
}

class MockIOSDevice extends Mock implements IOSDevice {
38
  TargetPlatform get platform => TargetPlatform.iOS;
39
  bool isSupported() => true;
40 41 42
}

class MockIOSSimulator extends Mock implements IOSSimulator {
43
  TargetPlatform get platform => TargetPlatform.iOSSimulator;
44
  bool isSupported() => true;
45 46 47 48 49 50 51 52 53
}

class MockDeviceStore extends DeviceStore {
  MockDeviceStore() : super(
    android: new MockAndroidDevice(),
    iOS: new MockIOSDevice(),
    iOSSimulator: new MockIOSSimulator());
}

54
void applyMocksToCommand(FlutterCommand command) {
55 56
  command
    ..applicationPackages = new MockApplicationPackageStore()
57
    ..toolchain = new MockToolchain()
58 59
    ..devices = new MockDeviceStore()
    ..projectRootValidator = () => true;
60
}