Unverified Commit c533ab65 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove mocks from doctor test (#82494)

parent e3fd8dbf
......@@ -30,23 +30,13 @@ import 'package:flutter_tools/src/version.dart';
import 'package:flutter_tools/src/vscode/vscode.dart';
import 'package:flutter_tools/src/vscode/vscode_validator.dart';
import 'package:flutter_tools/src/web/workflow.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/test_flutter_command_runner.dart';
FakePlatform _kNoColorOutputPlatform() => FakePlatform(
localeName: 'en_US.UTF-8',
environment: <String, String>{},
stdoutSupportsAnsi: false,
);
final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
Platform: _kNoColorOutputPlatform,
};
final Platform macPlatform = FakePlatform(
operatingSystem: 'macos',
environment: <String, String>{'HOME': '/foo/bar'}
......@@ -88,7 +78,7 @@ void main() {
.firstWhere((ValidationMessage m) => m.message.startsWith('Flutter '));
expect(message.message, 'Flutter extension version 4.5.6');
expect(message.isError, isFalse);
}, overrides: noColorTerminalOverride);
});
testUsingContext('No IDE Validator includes expected installation messages', () async {
final ValidationResult result = await NoIdeValidator().validate();
......@@ -98,7 +88,7 @@ void main() {
result.messages.map((ValidationMessage vm) => vm.message),
UserMessages().noIdeInstallationInfo,
);
}, overrides: noColorTerminalOverride);
});
testUsingContext('vs code validator when 64bit installed', () async {
expect(VsCodeValidatorTestTargets.installedWithExtension64bit.title, 'VS Code, 64-bit edition');
......@@ -114,7 +104,7 @@ void main() {
message = result.messages
.firstWhere((ValidationMessage m) => m.message.startsWith('Flutter '));
expect(message.message, 'Flutter extension version 4.5.6');
}, overrides: noColorTerminalOverride);
});
testUsingContext('vs code validator when extension missing', () async {
final ValidationResult result = await VsCodeValidatorTestTargets.installedWithoutExtension.validate();
......@@ -131,21 +121,13 @@ void main() {
expect(message.message, startsWith('Flutter extension can be installed from'));
expect(message.contextUrl, 'https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter');
expect(message.isError, false);
}, overrides: noColorTerminalOverride);
});
group('device validator', () {
testWithoutContext('no devices', () async {
final MockDeviceManager mockDeviceManager = MockDeviceManager();
when(mockDeviceManager.getAllConnectedDevices()).thenAnswer(
(Invocation invocation) => Future<List<Device>>.value(<Device>[])
);
when(mockDeviceManager.getDeviceDiagnostics()).thenAnswer(
(Invocation invocation) => Future<List<String>>.value(<String>[])
);
final FakeDeviceManager deviceManager = FakeDeviceManager();
final DeviceValidator deviceValidator = DeviceValidator(
deviceManager: mockDeviceManager,
deviceManager: deviceManager,
userMessages: UserMessages(),
);
final ValidationResult result = await deviceValidator.validate();
......@@ -157,17 +139,11 @@ void main() {
});
testWithoutContext('diagnostic message', () async {
final MockDeviceManager mockDeviceManager = MockDeviceManager();
when(mockDeviceManager.getAllConnectedDevices()).thenAnswer(
(Invocation invocation) => Future<List<Device>>.value(<Device>[])
);
when(mockDeviceManager.getDeviceDiagnostics()).thenAnswer(
(Invocation invocation) => Future<List<String>>.value(<String>['Device locked'])
);
final FakeDeviceManager deviceManager = FakeDeviceManager()
..diagnostics = <String>['Device locked'];
final DeviceValidator deviceValidator = DeviceValidator(
deviceManager: mockDeviceManager,
deviceManager: deviceManager,
userMessages: UserMessages(),
);
final ValidationResult result = await deviceValidator.validate();
......@@ -179,24 +155,19 @@ void main() {
});
testWithoutContext('diagnostic message and devices', () async {
final MockDeviceManager mockDeviceManager = MockDeviceManager();
final MockDevice mockDevice = MockDevice();
when(mockDeviceManager.getAllConnectedDevices()).thenAnswer(
(_) => Future<List<Device>>.value(<Device>[mockDevice])
);
when(mockDeviceManager.getDeviceDiagnostics()).thenAnswer(
(_) => Future<List<String>>.value(<String>['Device locked'])
);
final FakeDevice device = FakeDevice();
final FakeDeviceManager deviceManager = FakeDeviceManager()
..devices = <Device>[device]
..diagnostics = <String>['Device locked'];
final DeviceValidator deviceValidator = DeviceValidator(
deviceManager: mockDeviceManager,
deviceManager: deviceManager,
userMessages: UserMessages(),
);
final ValidationResult result = await deviceValidator.validate();
expect(result.type, ValidationType.installed);
expect(result.messages, const <ValidationMessage>[
ValidationMessage('null (null) • device-id • android • null'),
ValidationMessage('name (mobile) • device-id • android • 1.2.3'),
ValidationMessage.hint('Device locked'),
]);
expect(result.statusInfo, '1 available');
......@@ -218,7 +189,6 @@ void main() {
));
}, overrides: <Type, Generator>{
DoctorValidatorsProvider: () => FakeDoctorValidatorsProvider(),
Platform: _kNoColorOutputPlatform,
});
});
......@@ -243,7 +213,6 @@ void main() {
));
}, overrides: <Type, Generator>{
DoctorValidatorsProvider: () => FakeDoctorValidatorsProvider(),
Platform: _kNoColorOutputPlatform,
Usage: () => testUsage,
});
......@@ -273,7 +242,6 @@ void main() {
),
]));
}, overrides: <Type, Generator>{
Platform: _kNoColorOutputPlatform,
Usage: () => testUsage,
});
......@@ -308,7 +276,6 @@ void main() {
),
]));
}, overrides: <Type, Generator>{
Platform: _kNoColorOutputPlatform,
Usage: () => testUsage,
});
......@@ -338,7 +305,6 @@ void main() {
),
]));
}, overrides: <Type, Generator>{
Platform: _kNoColorOutputPlatform,
Usage: () => testUsage,
});
});
......@@ -355,7 +321,7 @@ void main() {
'\n'
'• No issues found!\n'
));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate non-verbose output format for run with crash', () async {
expect(await FakeCrashingDoctor(logger).diagnose(verbose: false), isFalse);
......@@ -372,12 +338,12 @@ void main() {
'\n'
'! Doctor found issues in 1 category.\n'
));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate verbose output format contains trace for run with crash', () async {
expect(await FakeCrashingDoctor(logger).diagnose(verbose: true), isFalse);
expect(logger.statusText, contains('#0 CrashingValidator.validate'));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate non-verbose output format for run with an async crash', () async {
......@@ -404,7 +370,7 @@ void main() {
'\n'
'! Doctor found issues in 1 category.\n'
));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate non-verbose output format when only one category fails', () async {
......@@ -416,7 +382,7 @@ void main() {
'\n'
'! Doctor found issues in 1 category.\n'
));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate non-verbose output format for a passing run', () async {
expect(await FakePassingDoctor(logger).diagnose(verbose: false), isTrue);
......@@ -432,7 +398,7 @@ void main() {
'\n'
'! Doctor found issues in 2 categories.\n'
));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate non-verbose output format', () async {
expect(await FakeDoctor(logger).diagnose(verbose: false), isFalse);
......@@ -453,7 +419,7 @@ void main() {
'\n'
'! Doctor found issues in 4 categories.\n'
));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate verbose output format', () async {
expect(await FakeDoctor(logger).diagnose(verbose: true), isFalse);
......@@ -483,7 +449,7 @@ void main() {
'\n'
'! Doctor found issues in 4 categories.\n'
));
}, overrides: noColorTerminalOverride);
});
});
testUsingContext('validate non-verbose output wrapping', () async {
......@@ -517,8 +483,6 @@ void main() {
'! Doctor found issues in 4\n'
' categories.\n'
));
}, overrides: <Type, Generator>{
Platform: _kNoColorOutputPlatform,
});
testUsingContext('validate verbose output wrapping', () async {
......@@ -563,8 +527,6 @@ void main() {
'! Doctor found issues in 4\n'
' categories.\n'
));
}, overrides: <Type, Generator>{
Platform: _kNoColorOutputPlatform,
});
......@@ -582,7 +544,7 @@ void main() {
'\n'
'! Doctor found issues in 1 category.\n'
));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate merging assigns statusInfo and title', () async {
// There are two subvalidators. Only the second contains statusInfo.
......@@ -594,7 +556,7 @@ void main() {
'\n'
'• No issues found!\n'
));
}, overrides: noColorTerminalOverride);
});
});
group('grouped validator merging results', () {
......@@ -605,47 +567,47 @@ void main() {
testUsingContext('validate installed + installed = installed', () async {
expect(await FakeSmallGroupDoctor(logger, installed, installed).diagnose(), isTrue);
expect(logger.statusText, startsWith('[✓]'));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate installed + partial = partial', () async {
expect(await FakeSmallGroupDoctor(logger, installed, partial).diagnose(), isTrue);
expect(logger.statusText, startsWith('[!]'));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate installed + missing = partial', () async {
expect(await FakeSmallGroupDoctor(logger, installed, missing).diagnose(), isTrue);
expect(logger.statusText, startsWith('[!]'));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate partial + installed = partial', () async {
expect(await FakeSmallGroupDoctor(logger, partial, installed).diagnose(), isTrue);
expect(logger.statusText, startsWith('[!]'));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate partial + partial = partial', () async {
expect(await FakeSmallGroupDoctor(logger, partial, partial).diagnose(), isTrue);
expect(logger.statusText, startsWith('[!]'));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate partial + missing = partial', () async {
expect(await FakeSmallGroupDoctor(logger, partial, missing).diagnose(), isTrue);
expect(logger.statusText, startsWith('[!]'));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate missing + installed = partial', () async {
expect(await FakeSmallGroupDoctor(logger, missing, installed).diagnose(), isTrue);
expect(logger.statusText, startsWith('[!]'));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate missing + partial = partial', () async {
expect(await FakeSmallGroupDoctor(logger, missing, partial).diagnose(), isTrue);
expect(logger.statusText, startsWith('[!]'));
}, overrides: noColorTerminalOverride);
});
testUsingContext('validate missing + missing = missing', () async {
expect(await FakeSmallGroupDoctor(logger, missing, missing).diagnose(), isFalse);
expect(logger.statusText, startsWith('[✗]'));
}, overrides: noColorTerminalOverride);
});
});
testUsingContext('WebWorkflow is a part of validator workflows if enabled', () async {
......@@ -1042,13 +1004,39 @@ class VsCodeValidatorTestTargets extends VsCodeValidator {
static final String missingExtensions = globals.fs.path.join('test', 'data', 'vscode', 'notExtensions');
}
class MockDeviceManager extends Mock implements DeviceManager {}
class MockDevice extends Mock implements Device {
MockDevice() {
when(isSupported()).thenReturn(true);
when(id).thenReturn('device-id');
when(isLocalEmulator).thenAnswer((_) => Future<bool>.value(false));
when(targetPlatform).thenAnswer((_) => Future<TargetPlatform>.value(TargetPlatform.android));
when(targetPlatformDisplayName).thenAnswer((_) async => 'android');
}
class FakeDeviceManager extends Fake implements DeviceManager {
List<String> diagnostics = <String>[];
List<Device> devices = <Device>[];
@override
Future<List<Device>> getAllConnectedDevices() async => devices;
@override
Future<List<String>> getDeviceDiagnostics() async => diagnostics;
}
class FakeDevice extends Fake implements Device {
@override
String get name => 'name';
@override
String get id => 'device-id';
@override
Category get category => Category.mobile;
@override
bool isSupported() => true;
@override
Future<bool> get isLocalEmulator async => false;
@override
Future<String> get targetPlatformDisplayName async => 'android';
@override
Future<String> get sdkNameAndVersion async => '1.2.3';
@override
Future<TargetPlatform> get targetPlatform => Future<TargetPlatform>.value(TargetPlatform.android);
}
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