Unverified Commit 6b92a93c authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Remove more mocks from error_handling_io and attach_test (#83504)

parent 5c92c5f2
......@@ -9,6 +9,7 @@ import 'dart:io';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/android/android_device.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/dds.dart';
import 'package:flutter_tools/src/base/file_system.dart';
......@@ -20,6 +21,7 @@ import 'package:flutter_tools/src/commands/attach.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/device_port_forwarder.dart';
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
import 'package:flutter_tools/src/ios/application_package.dart';
import 'package:flutter_tools/src/ios/devices.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/resident_runner.dart';
......@@ -77,14 +79,14 @@ void main() {
FakeDeviceLogReader fakeLogReader;
MockPortForwarder portForwarder;
MockDartDevelopmentService mockDds;
FakeDartDevelopmentService fakeDds;
MockAndroidDevice device;
setUp(() {
fakeLogReader = FakeDeviceLogReader();
portForwarder = MockPortForwarder();
device = MockAndroidDevice();
mockDds = MockDartDevelopmentService();
fakeDds = FakeDartDevelopmentService();
when(device.portForwarder)
.thenReturn(portForwarder);
when(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')))
......@@ -93,12 +95,7 @@ void main() {
.thenReturn(<ForwardedPort>[ForwardedPort(hostPort, devicePort)]);
when(portForwarder.unforward(any))
.thenAnswer((_) async {});
when(device.dds).thenReturn(mockDds);
final Completer<void> noopCompleter = Completer<void>();
when(mockDds.startDartDevelopmentService(any, any, false, any, logger: anyNamed('logger'))).thenReturn(null);
when(mockDds.uri).thenReturn(Uri.parse('http://localhost:8181'));
when(mockDds.done).thenAnswer((_) => noopCompleter.future);
when(device.dds).thenReturn(fakeDds);
// We cannot add the device to a device manager because that is
// only enabled by the context of each testUsingContext call.
//
......@@ -293,16 +290,14 @@ void main() {
const int hostPort = 42;
final FakeDeviceLogReader fakeLogReader = FakeDeviceLogReader();
final MockPortForwarder portForwarder = MockPortForwarder();
final MockDartDevelopmentService mockDds = MockDartDevelopmentService();
final FakeDartDevelopmentService fakeDds = FakeDartDevelopmentService();
final MockAndroidDevice device = MockAndroidDevice();
final MockHotRunner mockHotRunner = MockHotRunner();
final MockHotRunnerFactory mockHotRunnerFactory = MockHotRunnerFactory();
when(device.portForwarder)
.thenReturn(portForwarder);
when(device.dds)
.thenReturn(mockDds);
final Completer<void> noopCompleter = Completer<void>();
when(mockDds.done).thenAnswer((_) => noopCompleter.future);
.thenReturn(fakeDds);
when(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')))
.thenAnswer((_) async => hostPort);
when(portForwarder.forwardedPorts)
......@@ -324,8 +319,6 @@ void main() {
)).thenReturn(mockHotRunner);
when(mockHotRunner.exited).thenReturn(false);
when(mockHotRunner.isWaitingForObservatory).thenReturn(false);
when(mockDds.startDartDevelopmentService(any, any, false, any, logger: anyNamed('logger'))).thenReturn(null);
when(mockDds.uri).thenReturn(Uri.parse('http://localhost:8181'));
testDeviceManager.addDevice(device);
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
......@@ -378,18 +371,10 @@ void main() {
const int hostPort = 42;
final FakeDeviceLogReader fakeLogReader = FakeDeviceLogReader();
final MockPortForwarder portForwarder = MockPortForwarder();
final MockDartDevelopmentService mockDds = MockDartDevelopmentService();
final MockIOSDevice device = MockIOSDevice();
final FakeDartDevelopmentService mockDds = FakeDartDevelopmentService();
final FakeIOSDevice device = FakeIOSDevice(dds: mockDds, portForwarder: portForwarder, logReader: fakeLogReader);
final MockHotRunner mockHotRunner = MockHotRunner();
final MockHotRunnerFactory mockHotRunnerFactory = MockHotRunnerFactory();
when(device.portForwarder)
.thenReturn(portForwarder);
when(device.dds)
.thenReturn(mockDds);
final Completer<void> noopCompleter = Completer<void>();
when(mockDds.done).thenAnswer((_) => noopCompleter.future);
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
.thenAnswer((_) => fakeLogReader);
when(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')))
.thenAnswer((_) async => hostPort);
when(portForwarder.forwardedPorts)
......@@ -411,8 +396,6 @@ void main() {
)).thenReturn(mockHotRunner);
when(mockHotRunner.exited).thenReturn(false);
when(mockHotRunner.isWaitingForObservatory).thenReturn(false);
when(mockDds.startDartDevelopmentService(any, any, false, any, logger: anyNamed('logger'))).thenReturn(null);
when(mockDds.uri).thenReturn(Uri.parse('http://localhost:8181'));
testDeviceManager.addDevice(device);
......@@ -445,7 +428,7 @@ void main() {
setUp(() {
portForwarder = MockPortForwarder();
final MockDartDevelopmentService mockDds = MockDartDevelopmentService();
final FakeDartDevelopmentService fakeDds = FakeDartDevelopmentService();
device = MockAndroidDevice();
when(device.portForwarder)
......@@ -457,12 +440,7 @@ void main() {
when(portForwarder.unforward(any))
.thenAnswer((_) async {});
when(device.dds)
.thenReturn(mockDds);
when(mockDds.startDartDevelopmentService(any, any, any, any, logger: anyNamed('logger')))
.thenReturn(null);
when(mockDds.uri).thenReturn(Uri.parse('http://localhost:8181'));
final Completer<void> noopCompleter = Completer<void>();
when(mockDds.done).thenAnswer((_) => noopCompleter.future);
.thenReturn(fakeDds);
});
testUsingContext('succeeds in ipv4 mode', () async {
......@@ -596,7 +574,7 @@ void main() {
});
testUsingContext('fails when targeted device is not Android with --device-user', () async {
final MockIOSDevice device = MockIOSDevice();
final FakeIOSDevice device = FakeIOSDevice();
testDeviceManager.addDevice(device);
expect(createTestCommandRunner(AttachCommand()).run(<String>[
'attach',
......@@ -718,7 +696,6 @@ void main() {
class MockHotRunner extends Mock implements HotRunner {}
class MockHotRunnerFactory extends Mock implements HotRunnerFactory {}
class MockIOSDevice extends Mock implements IOSDevice {}
class MockPortForwarder extends Mock implements DevicePortForwarder {}
class StreamLogger extends Logger {
......@@ -927,7 +904,23 @@ class TestHotRunnerFactory extends HotRunnerFactory {
}
}
class MockDartDevelopmentService extends Mock implements DartDevelopmentService {}
class FakeDartDevelopmentService extends Fake implements DartDevelopmentService {
@override
Future<void> get done => noopCompleter.future;
final Completer<void> noopCompleter = Completer<void>();
@override
Future<void> startDartDevelopmentService(
Uri observatoryUri,
int hostPort,
bool ipv6,
bool disableServiceAuthCodes, {
@required Logger logger,
}) async {}
@override
Uri get uri => Uri.parse('http://localhost:8181');
}
class MockAndroidDevice extends Mock implements AndroidDevice {
@override
......@@ -945,3 +938,33 @@ class MockAndroidDevice extends Mock implements AndroidDevice {
@override
bool isSupportedForProject(FlutterProject flutterProject) => true;
}
class FakeIOSDevice extends Fake implements IOSDevice {
FakeIOSDevice({this.dds, this.portForwarder, this.logReader});
@override
final DevicePortForwarder portForwarder;
@override
final DartDevelopmentService dds;
final DeviceLogReader logReader;
@override
DeviceLogReader getLogReader({
IOSApp app,
bool includePastLogs = false,
}) => logReader;
@override
OverrideArtifacts get artifactOverrides => null;
@override
final String name = 'name';
@override
Future<TargetPlatform> get targetPlatform async => TargetPlatform.ios;
@override
final PlatformType platformType = PlatformType.ios;
}
......@@ -798,44 +798,39 @@ void main() {
group('toString() gives toString() of delegate', () {
testWithoutContext('ErrorHandlingFileSystem', () {
final MockFileSystem mockFileSystem = MockFileSystem();
final MemoryFileSystem delegate = MemoryFileSystem.test();
final FileSystem fs = ErrorHandlingFileSystem(
delegate: mockFileSystem,
delegate: delegate,
platform: const LocalPlatform(),
);
expect(mockFileSystem.toString(), isNotNull);
expect(fs.toString(), equals(mockFileSystem.toString()));
expect(delegate.toString(), isNotNull);
expect(fs.toString(), delegate.toString());
});
testWithoutContext('ErrorHandlingFile', () {
final MockFileSystem mockFileSystem = MockFileSystem();
final MemoryFileSystem delegate = MemoryFileSystem.test();
final FileSystem fs = ErrorHandlingFileSystem(
delegate: mockFileSystem,
delegate: delegate,
platform: const LocalPlatform(),
);
final MockFile mockFile = MockFile();
when(mockFileSystem.file(any)).thenReturn(mockFile);
final File file = delegate.file('file');
expect(mockFile.toString(), isNotNull);
expect(fs.file('file').toString(), equals(mockFile.toString()));
expect(file.toString(), isNotNull);
expect(fs.file('file').toString(), file.toString());
});
testWithoutContext('ErrorHandlingDirectory', () {
final MockFileSystem mockFileSystem = MockFileSystem();
final MemoryFileSystem delegate = MemoryFileSystem.test();
final FileSystem fs = ErrorHandlingFileSystem(
delegate: mockFileSystem,
delegate: delegate,
platform: const LocalPlatform(),
);
final MockDirectory mockDirectory = MockDirectory();
when(mockFileSystem.directory(any)).thenReturn(mockDirectory);
expect(mockDirectory.toString(), isNotNull);
expect(fs.directory('directory').toString(), equals(mockDirectory.toString()));
when(mockFileSystem.currentDirectory).thenReturn(mockDirectory);
final Directory directory = delegate.directory('directory')..createSync();
expect(fs.directory('directory').toString(), directory.toString());
delegate.currentDirectory = directory;
expect(fs.currentDirectory.toString(), equals(mockDirectory.toString()));
expect(fs.currentDirectory.toString(), delegate.currentDirectory.toString());
expect(fs.currentDirectory, isA<ErrorHandlingDirectory>());
});
});
......
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