Unverified Commit 23e41734 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Swap Mocks to Fakes in config_test (#76274)

parent 86d6d17a
...@@ -19,8 +19,8 @@ import 'package:flutter_tools/src/commands/build_linux.dart'; ...@@ -19,8 +19,8 @@ import 'package:flutter_tools/src/commands/build_linux.dart';
import 'package:flutter_tools/src/features.dart'; import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart'; import 'package:flutter_tools/src/reporting/reporting.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';
......
...@@ -17,15 +17,15 @@ import 'package:flutter_tools/src/commands/config.dart'; ...@@ -17,15 +17,15 @@ import 'package:flutter_tools/src/commands/config.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/reporting/reporting.dart'; import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:flutter_tools/src/version.dart'; import 'package:flutter_tools/src/version.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';
void main() { void main() {
MockAndroidStudio mockAndroidStudio; FakeAndroidStudio fakeAndroidStudio;
MockAndroidSdk mockAndroidSdk; FakeAndroidSdk fakeAndroidSdk;
MockFlutterVersion mockFlutterVersion; FakeFlutterVersion fakeFlutterVersion;
TestUsage testUsage; TestUsage testUsage;
setUpAll(() { setUpAll(() {
...@@ -33,9 +33,9 @@ void main() { ...@@ -33,9 +33,9 @@ void main() {
}); });
setUp(() { setUp(() {
mockAndroidStudio = MockAndroidStudio(); fakeAndroidStudio = FakeAndroidStudio();
mockAndroidSdk = MockAndroidSdk(); fakeAndroidSdk = FakeAndroidSdk();
mockFlutterVersion = MockFlutterVersion(); fakeFlutterVersion = FakeFlutterVersion();
testUsage = TestUsage(); testUsage = TestUsage();
}); });
...@@ -61,8 +61,8 @@ void main() { ...@@ -61,8 +61,8 @@ void main() {
expect(jsonObject['android-sdk'], isNotNull); expect(jsonObject['android-sdk'], isNotNull);
verifyNoAnalytics(); verifyNoAnalytics();
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidStudio: () => mockAndroidStudio, AndroidStudio: () => fakeAndroidStudio,
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => fakeAndroidSdk,
Usage: () => testUsage, Usage: () => testUsage,
}); });
...@@ -134,8 +134,8 @@ void main() { ...@@ -134,8 +134,8 @@ void main() {
expect(globals.config.getValue('enable-macos-desktop'), false); expect(globals.config.getValue('enable-macos-desktop'), false);
verifyNoAnalytics(); verifyNoAnalytics();
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidStudio: () => mockAndroidStudio, AndroidStudio: () => fakeAndroidStudio,
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => fakeAndroidSdk,
Usage: () => testUsage, Usage: () => testUsage,
}); });
...@@ -157,7 +157,7 @@ void main() { ...@@ -157,7 +157,7 @@ void main() {
}); });
testUsingContext('displays which config settings are available on stable', () async { testUsingContext('displays which config settings are available on stable', () async {
when(mockFlutterVersion.channel).thenReturn('stable'); fakeFlutterVersion.channel = 'stable';
final ConfigCommand configCommand = ConfigCommand(); final ConfigCommand configCommand = ConfigCommand();
final CommandRunner<void> commandRunner = createTestCommandRunner(configCommand); final CommandRunner<void> commandRunner = createTestCommandRunner(configCommand);
...@@ -191,9 +191,9 @@ void main() { ...@@ -191,9 +191,9 @@ void main() {
); );
verifyNoAnalytics(); verifyNoAnalytics();
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidStudio: () => mockAndroidStudio, AndroidStudio: () => fakeAndroidStudio,
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => fakeAndroidSdk,
FlutterVersion: () => mockFlutterVersion, FlutterVersion: () => fakeFlutterVersion,
Usage: () => testUsage, Usage: () => testUsage,
}); });
...@@ -265,14 +265,23 @@ void main() { ...@@ -265,14 +265,23 @@ void main() {
}); });
} }
class MockAndroidStudio extends Mock implements AndroidStudio, Comparable<AndroidStudio> { class FakeAndroidStudio extends Fake implements AndroidStudio, Comparable<AndroidStudio> {
@override @override
String get directory => 'path/to/android/stdio'; String get directory => 'path/to/android/stdio';
} }
class MockAndroidSdk extends Mock implements AndroidSdk { class FakeAndroidSdk extends Fake implements AndroidSdk {
@override @override
Directory get directory => globals.fs.directory('path/to/android/sdk'); Directory get directory => globals.fs.directory('path/to/android/sdk');
} }
class MockFlutterVersion extends Mock implements FlutterVersion {} class FakeFlutterVersion extends Fake implements FlutterVersion {
@override
String channel;
@override
void ensureVersionFile() {}
@override
Future<void> checkFlutterVersionFreshness() async {}
}
...@@ -15,7 +15,7 @@ import 'package:flutter_tools/src/base/os.dart'; ...@@ -15,7 +15,7 @@ import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/terminal.dart'; import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/fake_http_client.dart'; import '../src/fake_http_client.dart';
...@@ -25,7 +25,7 @@ final Platform testPlatform = FakePlatform(environment: const <String, String>{} ...@@ -25,7 +25,7 @@ final Platform testPlatform = FakePlatform(environment: const <String, String>{}
void main() { void main() {
testWithoutContext('ArtifactUpdater can download a zip archive', () async { testWithoutContext('ArtifactUpdater can download a zip archive', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater( final ArtifactUpdater artifactUpdater = ArtifactUpdater(
...@@ -48,7 +48,7 @@ void main() { ...@@ -48,7 +48,7 @@ void main() {
}); });
testWithoutContext('ArtifactUpdater can download a zip archive and delete stale files', () async { testWithoutContext('ArtifactUpdater can download a zip archive and delete stale files', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater( final ArtifactUpdater artifactUpdater = ArtifactUpdater(
...@@ -78,7 +78,7 @@ void main() { ...@@ -78,7 +78,7 @@ void main() {
testWithoutContext('ArtifactUpdater will not validate the md5 hash if the ' testWithoutContext('ArtifactUpdater will not validate the md5 hash if the '
'x-goog-hash header is present but missing an md5 entry', () async { 'x-goog-hash header is present but missing an md5 entry', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
...@@ -109,7 +109,7 @@ void main() { ...@@ -109,7 +109,7 @@ void main() {
testWithoutContext('ArtifactUpdater will validate the md5 hash if the ' testWithoutContext('ArtifactUpdater will validate the md5 hash if the '
'x-goog-hash header is present', () async { 'x-goog-hash header is present', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
...@@ -144,7 +144,7 @@ void main() { ...@@ -144,7 +144,7 @@ void main() {
testWithoutContext('ArtifactUpdater will validate the md5 hash if the ' testWithoutContext('ArtifactUpdater will validate the md5 hash if the '
'x-goog-hash header is present and throw if it does not match', () async { 'x-goog-hash header is present and throw if it does not match', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
...@@ -184,7 +184,7 @@ void main() { ...@@ -184,7 +184,7 @@ void main() {
}); });
testWithoutContext('ArtifactUpdater will restart the status ticker if it needs to retry the download', () async { testWithoutContext('ArtifactUpdater will restart the status ticker if it needs to retry the download', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final Logger logger = StdoutLogger( final Logger logger = StdoutLogger(
terminal: Terminal.test(supportsColor: true), terminal: Terminal.test(supportsColor: true),
...@@ -214,7 +214,7 @@ void main() { ...@@ -214,7 +214,7 @@ void main() {
}); });
testWithoutContext('ArtifactUpdater will re-attempt on a non-200 response', () async { testWithoutContext('ArtifactUpdater will re-attempt on a non-200 response', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
...@@ -242,7 +242,7 @@ void main() { ...@@ -242,7 +242,7 @@ void main() {
}); });
testWithoutContext('ArtifactUpdater will tool exit on an ArgumentError from http client with base url override', () async { testWithoutContext('ArtifactUpdater will tool exit on an ArgumentError from http client with base url override', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater( final ArtifactUpdater artifactUpdater = ArtifactUpdater(
...@@ -272,7 +272,7 @@ void main() { ...@@ -272,7 +272,7 @@ void main() {
}); });
testWithoutContext('ArtifactUpdater will rethrow on an ArgumentError from http client without base url override', () async { testWithoutContext('ArtifactUpdater will rethrow on an ArgumentError from http client without base url override', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater( final ArtifactUpdater artifactUpdater = ArtifactUpdater(
...@@ -298,7 +298,7 @@ void main() { ...@@ -298,7 +298,7 @@ void main() {
}); });
testWithoutContext('ArtifactUpdater will re-download a file if unzipping fails', () async { testWithoutContext('ArtifactUpdater will re-download a file if unzipping fails', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater( final ArtifactUpdater artifactUpdater = ArtifactUpdater(
...@@ -322,7 +322,7 @@ void main() { ...@@ -322,7 +322,7 @@ void main() {
}); });
testWithoutContext('ArtifactUpdater will de-download a file if unzipping fails on windows', () async { testWithoutContext('ArtifactUpdater will de-download a file if unzipping fails on windows', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(windows: true); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils(windows: true);
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater( final ArtifactUpdater artifactUpdater = ArtifactUpdater(
...@@ -346,7 +346,7 @@ void main() { ...@@ -346,7 +346,7 @@ void main() {
}); });
testWithoutContext('ArtifactUpdater will bail with a tool exit if unzipping fails more than twice', () async { testWithoutContext('ArtifactUpdater will bail with a tool exit if unzipping fails more than twice', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater( final ArtifactUpdater artifactUpdater = ArtifactUpdater(
...@@ -370,7 +370,7 @@ void main() { ...@@ -370,7 +370,7 @@ void main() {
}); });
testWithoutContext('ArtifactUpdater will bail if unzipping fails more than twice on Windows', () async { testWithoutContext('ArtifactUpdater will bail if unzipping fails more than twice on Windows', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(windows: true); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils(windows: true);
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater( final ArtifactUpdater artifactUpdater = ArtifactUpdater(
...@@ -394,7 +394,7 @@ void main() { ...@@ -394,7 +394,7 @@ void main() {
}); });
testWithoutContext('ArtifactUpdater can download a tar archive', () async { testWithoutContext('ArtifactUpdater can download a tar archive', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater( final ArtifactUpdater artifactUpdater = ArtifactUpdater(
...@@ -416,7 +416,7 @@ void main() { ...@@ -416,7 +416,7 @@ void main() {
}); });
testWithoutContext('ArtifactUpdater will delete downloaded files if they exist.', () async { testWithoutContext('ArtifactUpdater will delete downloaded files if they exist.', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater( final ArtifactUpdater artifactUpdater = ArtifactUpdater(
...@@ -441,8 +441,8 @@ void main() { ...@@ -441,8 +441,8 @@ void main() {
}); });
} }
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils { class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
MockOperatingSystemUtils({this.windows = false}); FakeOperatingSystemUtils({this.windows = false});
int failures = 0; int failures = 0;
final bool windows; final bool windows;
......
...@@ -9,7 +9,7 @@ import 'dart:io' as io; ...@@ -9,7 +9,7 @@ import 'dart:io' as io;
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/signals.dart'; import 'package:flutter_tools/src/base/signals.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
......
...@@ -26,7 +26,7 @@ void main() { ...@@ -26,7 +26,7 @@ void main() {
final Map<Type, Generator> overrides = <Type, Generator>{ final Map<Type, Generator> overrides = <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(), FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
PlistParser: () => MockPlistUtils(), PlistParser: () => FakePlistUtils(),
Platform: _kNoColorTerminalPlatform, Platform: _kNoColorTerminalPlatform,
OperatingSystemUtils: () => os, OperatingSystemUtils: () => os,
}; };
...@@ -204,7 +204,7 @@ final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{ ...@@ -204,7 +204,7 @@ final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
Platform: _kNoColorTerminalPlatform, Platform: _kNoColorTerminalPlatform,
}; };
class MockPlistUtils extends Mock implements PlistParser { class FakePlistUtils extends Fake implements PlistParser {
@override @override
Map<String, dynamic> parseFile(String plistFilePath) { Map<String, dynamic> parseFile(String plistFilePath) {
final File file = globals.fs.file(plistFilePath); final File file = globals.fs.file(plistFilePath);
......
...@@ -362,9 +362,9 @@ class MockDevice extends Mock implements Device { ...@@ -362,9 +362,9 @@ class MockDevice extends Mock implements Device {
class MockResidentRunner extends Mock implements ResidentRunner {} class MockResidentRunner extends Mock implements ResidentRunner {}
class MockFlutterDevice extends Mock implements FlutterDevice {} class MockFlutterDevice extends Mock implements FlutterDevice {}
class MockResidentCompiler extends Mock implements ResidentCompiler {} class FakeResidentCompiler extends Fake implements ResidentCompiler {}
class TestRunner extends Mock implements ResidentRunner { class TestRunner extends Fake implements ResidentRunner {
bool hasHelpBeenPrinted = false; bool hasHelpBeenPrinted = false;
String receivedCommand; String receivedCommand;
......
...@@ -115,7 +115,7 @@ void main() { ...@@ -115,7 +115,7 @@ void main() {
}); });
testUsingContext('VmService registers flutterMemoryInfo service', () async { testUsingContext('VmService registers flutterMemoryInfo service', () async {
final MockDevice mockDevice = MockDevice(); final FakeDevice mockDevice = FakeDevice();
final MockVMService mockVMService = MockVMService(); final MockVMService mockVMService = MockVMService();
setUpVmService( setUpVmService(
...@@ -183,7 +183,7 @@ void main() { ...@@ -183,7 +183,7 @@ void main() {
verify(mockVMService.registerService('flutterVersion', 'Flutter Tools')).called(1); verify(mockVMService.registerService('flutterVersion', 'Flutter Tools')).called(1);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FlutterVersion: () => MockFlutterVersion(), FlutterVersion: () => FakeFlutterVersion(),
}); });
testUsingContext('VMService prints messages for connection failures', () { testUsingContext('VMService prints messages for connection failures', () {
...@@ -467,11 +467,11 @@ void main() { ...@@ -467,11 +467,11 @@ void main() {
}); });
} }
class MockDevice extends Mock implements Device {}
class MockVMService extends Mock implements vm_service.VmService {} class MockVMService extends Mock implements vm_service.VmService {}
class MockFlutterVersion extends Mock implements FlutterVersion { class FakeDevice extends Fake implements Device {}
class FakeFlutterVersion extends Fake implements FlutterVersion {
@override @override
Map<String, Object> toJson() => const <String, Object>{'Mock': 'Version'}; Map<String, Object> toJson() => const <String, Object>{'Fake': 'Version'};
} }
/// A [WebSocketConnector] that always throws an [io.SocketException]. /// A [WebSocketConnector] that always throws an [io.SocketException].
......
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