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';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.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/reporting/reporting.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
void main() {
MockAndroidStudio mockAndroidStudio;
MockAndroidSdk mockAndroidSdk;
MockFlutterVersion mockFlutterVersion;
FakeAndroidStudio fakeAndroidStudio;
FakeAndroidSdk fakeAndroidSdk;
FakeFlutterVersion fakeFlutterVersion;
TestUsage testUsage;
setUpAll(() {
......@@ -33,9 +33,9 @@ void main() {
});
setUp(() {
mockAndroidStudio = MockAndroidStudio();
mockAndroidSdk = MockAndroidSdk();
mockFlutterVersion = MockFlutterVersion();
fakeAndroidStudio = FakeAndroidStudio();
fakeAndroidSdk = FakeAndroidSdk();
fakeFlutterVersion = FakeFlutterVersion();
testUsage = TestUsage();
});
......@@ -61,8 +61,8 @@ void main() {
expect(jsonObject['android-sdk'], isNotNull);
verifyNoAnalytics();
}, overrides: <Type, Generator>{
AndroidStudio: () => mockAndroidStudio,
AndroidSdk: () => mockAndroidSdk,
AndroidStudio: () => fakeAndroidStudio,
AndroidSdk: () => fakeAndroidSdk,
Usage: () => testUsage,
});
......@@ -134,8 +134,8 @@ void main() {
expect(globals.config.getValue('enable-macos-desktop'), false);
verifyNoAnalytics();
}, overrides: <Type, Generator>{
AndroidStudio: () => mockAndroidStudio,
AndroidSdk: () => mockAndroidSdk,
AndroidStudio: () => fakeAndroidStudio,
AndroidSdk: () => fakeAndroidSdk,
Usage: () => testUsage,
});
......@@ -157,7 +157,7 @@ void main() {
});
testUsingContext('displays which config settings are available on stable', () async {
when(mockFlutterVersion.channel).thenReturn('stable');
fakeFlutterVersion.channel = 'stable';
final ConfigCommand configCommand = ConfigCommand();
final CommandRunner<void> commandRunner = createTestCommandRunner(configCommand);
......@@ -191,9 +191,9 @@ void main() {
);
verifyNoAnalytics();
}, overrides: <Type, Generator>{
AndroidStudio: () => mockAndroidStudio,
AndroidSdk: () => mockAndroidSdk,
FlutterVersion: () => mockFlutterVersion,
AndroidStudio: () => fakeAndroidStudio,
AndroidSdk: () => fakeAndroidSdk,
FlutterVersion: () => fakeFlutterVersion,
Usage: () => testUsage,
});
......@@ -265,14 +265,23 @@ void main() {
});
}
class MockAndroidStudio extends Mock implements AndroidStudio, Comparable<AndroidStudio> {
class FakeAndroidStudio extends Fake implements AndroidStudio, Comparable<AndroidStudio> {
@override
String get directory => 'path/to/android/stdio';
}
class MockAndroidSdk extends Mock implements AndroidSdk {
class FakeAndroidSdk extends Fake implements AndroidSdk {
@override
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';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../src/common.dart';
import '../src/fake_http_client.dart';
......@@ -25,7 +25,7 @@ final Platform testPlatform = FakePlatform(environment: const <String, String>{}
void main() {
testWithoutContext('ArtifactUpdater can download a zip archive', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils();
final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater(
......@@ -48,7 +48,7 @@ void main() {
});
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 BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater(
......@@ -78,7 +78,7 @@ void main() {
testWithoutContext('ArtifactUpdater will not validate the md5 hash if the '
'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 BufferLogger logger = BufferLogger.test();
......@@ -109,7 +109,7 @@ void main() {
testWithoutContext('ArtifactUpdater will validate the md5 hash if the '
'x-goog-hash header is present', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils();
final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test();
......@@ -144,7 +144,7 @@ void main() {
testWithoutContext('ArtifactUpdater will validate the md5 hash if the '
'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 BufferLogger logger = BufferLogger.test();
......@@ -184,7 +184,7 @@ void main() {
});
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 Logger logger = StdoutLogger(
terminal: Terminal.test(supportsColor: true),
......@@ -214,7 +214,7 @@ void main() {
});
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 BufferLogger logger = BufferLogger.test();
......@@ -242,7 +242,7 @@ void main() {
});
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 BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater(
......@@ -272,7 +272,7 @@ void main() {
});
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 BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater(
......@@ -298,7 +298,7 @@ void main() {
});
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 BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater(
......@@ -322,7 +322,7 @@ void main() {
});
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 BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater(
......@@ -346,7 +346,7 @@ void main() {
});
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 BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater(
......@@ -370,7 +370,7 @@ void main() {
});
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 BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater(
......@@ -394,7 +394,7 @@ void main() {
});
testWithoutContext('ArtifactUpdater can download a tar archive', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils();
final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater(
......@@ -416,7 +416,7 @@ void main() {
});
testWithoutContext('ArtifactUpdater will delete downloaded files if they exist.', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils();
final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater(
......@@ -441,8 +441,8 @@ void main() {
});
}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {
MockOperatingSystemUtils({this.windows = false});
class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
FakeOperatingSystemUtils({this.windows = false});
int failures = 0;
final bool windows;
......
......@@ -9,7 +9,7 @@ import 'dart:io' as io;
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/signals.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
......
......@@ -26,7 +26,7 @@ void main() {
final Map<Type, Generator> overrides = <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
PlistParser: () => MockPlistUtils(),
PlistParser: () => FakePlistUtils(),
Platform: _kNoColorTerminalPlatform,
OperatingSystemUtils: () => os,
};
......@@ -204,7 +204,7 @@ final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
Platform: _kNoColorTerminalPlatform,
};
class MockPlistUtils extends Mock implements PlistParser {
class FakePlistUtils extends Fake implements PlistParser {
@override
Map<String, dynamic> parseFile(String plistFilePath) {
final File file = globals.fs.file(plistFilePath);
......
......@@ -362,9 +362,9 @@ class MockDevice extends Mock implements Device {
class MockResidentRunner extends Mock implements ResidentRunner {}
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;
String receivedCommand;
......
......@@ -115,7 +115,7 @@ void main() {
});
testUsingContext('VmService registers flutterMemoryInfo service', () async {
final MockDevice mockDevice = MockDevice();
final FakeDevice mockDevice = FakeDevice();
final MockVMService mockVMService = MockVMService();
setUpVmService(
......@@ -183,7 +183,7 @@ void main() {
verify(mockVMService.registerService('flutterVersion', 'Flutter Tools')).called(1);
}, overrides: <Type, Generator>{
FlutterVersion: () => MockFlutterVersion(),
FlutterVersion: () => FakeFlutterVersion(),
});
testUsingContext('VMService prints messages for connection failures', () {
......@@ -467,11 +467,11 @@ void main() {
});
}
class MockDevice extends Mock implements Device {}
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
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].
......
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