Unverified Commit 3f380ca5 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Swap mockito import for test/fake (#74847)

parent c05f623c
...@@ -74,14 +74,14 @@ void main() { ...@@ -74,14 +74,14 @@ void main() {
const int devicePort = 499; const int devicePort = 499;
const int hostPort = 42; const int hostPort = 42;
FakeDeviceLogReader mockLogReader; FakeDeviceLogReader fakeLogReader;
MockPortForwarder portForwarder; MockPortForwarder portForwarder;
MockDartDevelopmentService mockDds; MockDartDevelopmentService mockDds;
MockAndroidDevice device; MockAndroidDevice device;
MockHttpClient httpClient; MockHttpClient httpClient;
setUp(() { setUp(() {
mockLogReader = FakeDeviceLogReader(); fakeLogReader = FakeDeviceLogReader();
portForwarder = MockPortForwarder(); portForwarder = MockPortForwarder();
device = MockAndroidDevice(); device = MockAndroidDevice();
mockDds = MockDartDevelopmentService(); mockDds = MockDartDevelopmentService();
...@@ -114,16 +114,16 @@ void main() { ...@@ -114,16 +114,16 @@ void main() {
}); });
tearDown(() { tearDown(() {
mockLogReader.dispose(); fakeLogReader.dispose();
}); });
testUsingContext('finds observatory port and forwards', () async { testUsingContext('finds observatory port and forwards', () async {
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs'))) when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
.thenAnswer((_) { .thenAnswer((_) {
// Now that the reader is used, start writing messages to it. // Now that the reader is used, start writing messages to it.
mockLogReader.addLine('Foo'); fakeLogReader.addLine('Foo');
mockLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort'); fakeLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
return mockLogReader; return fakeLogReader;
}); });
testDeviceManager.addDevice(device); testDeviceManager.addDevice(device);
final Completer<void> completer = Completer<void>(); final Completer<void> completer = Completer<void>();
...@@ -138,7 +138,7 @@ void main() { ...@@ -138,7 +138,7 @@ void main() {
verify( verify(
portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')), portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')),
).called(1); ).called(1);
await mockLogReader.dispose(); await fakeLogReader.dispose();
await expectLoggerInterruptEndsTask(task, logger); await expectLoggerInterruptEndsTask(task, logger);
await loggerSubscription.cancel(); await loggerSubscription.cancel();
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -151,10 +151,10 @@ void main() { ...@@ -151,10 +151,10 @@ void main() {
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs'))) when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
.thenAnswer((_) { .thenAnswer((_) {
// Now that the reader is used, start writing messages to it. // Now that the reader is used, start writing messages to it.
mockLogReader.addLine('Foo'); fakeLogReader.addLine('Foo');
mockLogReader.addLine('Observatory listening on http:/:/127.0.0.1:$devicePort'); fakeLogReader.addLine('Observatory listening on http:/:/127.0.0.1:$devicePort');
mockLogReader.dispose(); fakeLogReader.dispose();
return mockLogReader; return fakeLogReader;
}); });
testDeviceManager.addDevice(device); testDeviceManager.addDevice(device);
expect(createTestCommandRunner(AttachCommand()).run(<String>['attach']), expect(createTestCommandRunner(AttachCommand()).run(<String>['attach']),
...@@ -169,9 +169,9 @@ void main() { ...@@ -169,9 +169,9 @@ void main() {
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs'))) when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
.thenAnswer((_) { .thenAnswer((_) {
// Now that the reader is used, start writing messages to it. // Now that the reader is used, start writing messages to it.
mockLogReader.addLine('Foo'); fakeLogReader.addLine('Foo');
mockLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort'); fakeLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
return mockLogReader; return fakeLogReader;
}); });
testDeviceManager.addDevice(device); testDeviceManager.addDevice(device);
...@@ -249,9 +249,9 @@ void main() { ...@@ -249,9 +249,9 @@ void main() {
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs'))) when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
.thenAnswer((_) { .thenAnswer((_) {
// Now that the reader is used, start writing messages to it. // Now that the reader is used, start writing messages to it.
mockLogReader.addLine('Foo'); fakeLogReader.addLine('Foo');
mockLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort'); fakeLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
return mockLogReader; return fakeLogReader;
}); });
testDeviceManager.addDevice(device); testDeviceManager.addDevice(device);
...@@ -272,9 +272,9 @@ void main() { ...@@ -272,9 +272,9 @@ void main() {
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs'))) when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
.thenAnswer((_) { .thenAnswer((_) {
// Now that the reader is used, start writing messages to it. // Now that the reader is used, start writing messages to it.
mockLogReader.addLine('Foo'); fakeLogReader.addLine('Foo');
mockLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort'); fakeLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
return mockLogReader; return fakeLogReader;
}); });
testDeviceManager.addDevice(device); testDeviceManager.addDevice(device);
...@@ -295,7 +295,7 @@ void main() { ...@@ -295,7 +295,7 @@ void main() {
testUsingContext('selects specified target', () async { testUsingContext('selects specified target', () async {
const int devicePort = 499; const int devicePort = 499;
const int hostPort = 42; const int hostPort = 42;
final FakeDeviceLogReader mockLogReader = FakeDeviceLogReader(); final FakeDeviceLogReader fakeLogReader = FakeDeviceLogReader();
final MockPortForwarder portForwarder = MockPortForwarder(); final MockPortForwarder portForwarder = MockPortForwarder();
final MockDartDevelopmentService mockDds = MockDartDevelopmentService(); final MockDartDevelopmentService mockDds = MockDartDevelopmentService();
final MockAndroidDevice device = MockAndroidDevice(); final MockAndroidDevice device = MockAndroidDevice();
...@@ -332,10 +332,10 @@ void main() { ...@@ -332,10 +332,10 @@ void main() {
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs'))) when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
.thenAnswer((_) { .thenAnswer((_) {
// Now that the reader is used, start writing messages to it. // Now that the reader is used, start writing messages to it.
mockLogReader.addLine('Foo'); fakeLogReader.addLine('Foo');
mockLogReader.addLine( fakeLogReader.addLine(
'Observatory listening on http://127.0.0.1:$devicePort'); 'Observatory listening on http://127.0.0.1:$devicePort');
return mockLogReader; return fakeLogReader;
}); });
final File foo = globals.fs.file('lib/foo.dart') final File foo = globals.fs.file('lib/foo.dart')
..createSync(); ..createSync();
...@@ -377,7 +377,7 @@ void main() { ...@@ -377,7 +377,7 @@ void main() {
testUsingContext('fallbacks to protocol observatory if MDNS failed on iOS', () async { testUsingContext('fallbacks to protocol observatory if MDNS failed on iOS', () async {
const int devicePort = 499; const int devicePort = 499;
const int hostPort = 42; const int hostPort = 42;
final FakeDeviceLogReader mockLogReader = FakeDeviceLogReader(); final FakeDeviceLogReader fakeLogReader = FakeDeviceLogReader();
final MockPortForwarder portForwarder = MockPortForwarder(); final MockPortForwarder portForwarder = MockPortForwarder();
final MockDartDevelopmentService mockDds = MockDartDevelopmentService(); final MockDartDevelopmentService mockDds = MockDartDevelopmentService();
final MockIOSDevice device = MockIOSDevice(); final MockIOSDevice device = MockIOSDevice();
...@@ -390,7 +390,7 @@ void main() { ...@@ -390,7 +390,7 @@ void main() {
final Completer<void> noopCompleter = Completer<void>(); final Completer<void> noopCompleter = Completer<void>();
when(mockDds.done).thenAnswer((_) => noopCompleter.future); when(mockDds.done).thenAnswer((_) => noopCompleter.future);
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs'))) when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
.thenAnswer((_) => mockLogReader); .thenAnswer((_) => fakeLogReader);
when(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort'))) when(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')))
.thenAnswer((_) async => hostPort); .thenAnswer((_) async => hostPort);
when(portForwarder.forwardedPorts) when(portForwarder.forwardedPorts)
......
...@@ -12,7 +12,7 @@ import 'package:flutter_tools/src/base/logger.dart'; ...@@ -12,7 +12,7 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/user_messages.dart'; import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/fake_process_manager.dart'; import '../../src/fake_process_manager.dart';
......
...@@ -241,7 +241,7 @@ flutter: ...@@ -241,7 +241,7 @@ flutter:
]), ]),
id: 'emulator-5555', id: 'emulator-5555',
androidConsoleSocketFactory: (String host, int port) async => androidConsoleSocketFactory: (String host, int port) async =>
MockWorkingAndroidConsoleSocket('dummyEmulatorId'), FakeWorkingAndroidConsoleSocket('dummyEmulatorId'),
); );
expect(await device.emulatorId, equals('dummyEmulatorId')); expect(await device.emulatorId, equals('dummyEmulatorId'));
...@@ -313,7 +313,7 @@ flutter: ...@@ -313,7 +313,7 @@ flutter:
) )
]), ]),
androidConsoleSocketFactory: (String host, int port) async => androidConsoleSocketFactory: (String host, int port) async =>
MockUnresponsiveAndroidConsoleSocket(), FakeUnresponsiveAndroidConsoleSocket(),
); );
expect(await device.emulatorId, isNull); expect(await device.emulatorId, isNull);
...@@ -328,7 +328,7 @@ flutter: ...@@ -328,7 +328,7 @@ flutter:
) )
]), ]),
androidConsoleSocketFactory: (String host, int port) async => androidConsoleSocketFactory: (String host, int port) async =>
MockDisconnectingAndroidConsoleSocket() FakeDisconnectingAndroidConsoleSocket()
); );
expect(await device.emulatorId, isNull); expect(await device.emulatorId, isNull);
...@@ -480,7 +480,6 @@ AndroidDevice setUpAndroidDevice({ ...@@ -480,7 +480,6 @@ AndroidDevice setUpAndroidDevice({
} }
class MockAndroidSdk extends Mock implements AndroidSdk {} class MockAndroidSdk extends Mock implements AndroidSdk {}
class MockProcessManager extends Mock implements ProcessManager {}
const String kAdbShellGetprop = ''' const String kAdbShellGetprop = '''
[dalvik.vm.dex2oat-Xms]: [64m] [dalvik.vm.dex2oat-Xms]: [64m]
...@@ -642,8 +641,8 @@ const String kAdbShellGetprop = ''' ...@@ -642,8 +641,8 @@ const String kAdbShellGetprop = '''
/// A mock Android Console that presents a connection banner and responds to /// A mock Android Console that presents a connection banner and responds to
/// "avd name" requests with the supplied name. /// "avd name" requests with the supplied name.
class MockWorkingAndroidConsoleSocket extends Fake implements Socket { class FakeWorkingAndroidConsoleSocket extends Fake implements Socket {
MockWorkingAndroidConsoleSocket(this.avdName) { FakeWorkingAndroidConsoleSocket(this.avdName) {
_controller.add('Android Console: Welcome!\n'); _controller.add('Android Console: Welcome!\n');
// Include OK in the same packet here. In the response to "avd name" // Include OK in the same packet here. In the response to "avd name"
// it's sent alone to ensure both are handled. // it's sent alone to ensure both are handled.
...@@ -674,7 +673,7 @@ class MockWorkingAndroidConsoleSocket extends Fake implements Socket { ...@@ -674,7 +673,7 @@ class MockWorkingAndroidConsoleSocket extends Fake implements Socket {
} }
/// An Android console socket that drops all input and returns no output. /// An Android console socket that drops all input and returns no output.
class MockUnresponsiveAndroidConsoleSocket extends Fake implements Socket { class FakeUnresponsiveAndroidConsoleSocket extends Fake implements Socket {
final StreamController<String> _controller = StreamController<String>(); final StreamController<String> _controller = StreamController<String>();
@override @override
...@@ -688,8 +687,8 @@ class MockUnresponsiveAndroidConsoleSocket extends Fake implements Socket { ...@@ -688,8 +687,8 @@ class MockUnresponsiveAndroidConsoleSocket extends Fake implements Socket {
} }
/// An Android console socket that drops all input and returns no output. /// An Android console socket that drops all input and returns no output.
class MockDisconnectingAndroidConsoleSocket extends Fake implements Socket { class FakeDisconnectingAndroidConsoleSocket extends Fake implements Socket {
MockDisconnectingAndroidConsoleSocket() { FakeDisconnectingAndroidConsoleSocket() {
_controller.add('Android Console: Welcome!\n'); _controller.add('Android Console: Welcome!\n');
// Include OK in the same packet here. In the response to "avd name" // Include OK in the same packet here. In the response to "avd name"
// it's sent alone to ensure both are handled. // it's sent alone to ensure both are handled.
......
...@@ -11,7 +11,7 @@ import 'package:flutter_tools/src/application_package.dart'; ...@@ -11,7 +11,7 @@ import 'package:flutter_tools/src/application_package.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
......
...@@ -18,8 +18,8 @@ import 'package:flutter_tools/src/device.dart'; ...@@ -18,8 +18,8 @@ import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import 'package:test/fake.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
......
...@@ -15,9 +15,9 @@ import 'package:flutter_tools/src/convert.dart'; ...@@ -15,9 +15,9 @@ import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/drive/drive_service.dart'; import 'package:flutter_tools/src/drive/drive_service.dart';
import 'package:flutter_tools/src/vmservice.dart'; import 'package:flutter_tools/src/vmservice.dart';
import 'package:mockito/mockito.dart';
import 'package:package_config/package_config_types.dart'; import 'package:package_config/package_config_types.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import 'package:test/fake.dart';
import 'package:vm_service/vm_service.dart' as vm_service; import 'package:vm_service/vm_service.dart' as vm_service;
import '../../src/common.dart'; import '../../src/common.dart';
......
...@@ -64,17 +64,17 @@ void main() { ...@@ -64,17 +64,17 @@ void main() {
group('Observatory and DDS setup', () { group('Observatory and DDS setup', () {
Platform fakePlatform; Platform fakePlatform;
ProcessManager mockProcessManager; ProcessManager fakeProcessManager;
FlutterPlatform flutterPlatform; FlutterPlatform flutterPlatform;
final Map<Type, Generator> contextOverrides = <Type, Generator>{ final Map<Type, Generator> contextOverrides = <Type, Generator>{
Platform: () => fakePlatform, Platform: () => fakePlatform,
ProcessManager: () => mockProcessManager, ProcessManager: () => fakeProcessManager,
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
}; };
setUp(() { setUp(() {
fakePlatform = FakePlatform(operatingSystem: 'linux', environment: <String, String>{}); fakePlatform = FakePlatform(operatingSystem: 'linux', environment: <String, String>{});
mockProcessManager = FakeProcessManager.list(<FakeCommand>[ fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand( const FakeCommand(
command: <String>[ command: <String>[
'/', '/',
......
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