Unverified Commit 1ad6edb8 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Remove MockProcessManager from channel_test and other tests (#74780)

parent 675fd554
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'dart:convert';
import 'dart:io';
import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/artifacts.dart';
......@@ -11,7 +10,6 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/devices.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import '../../src/common.dart';
......@@ -45,7 +43,7 @@ void main() {
}, overrides: <Type, Generator>{
AndroidSdk: () => null,
DeviceManager: () => NoDevicesManager(),
ProcessManager: () => MockProcessManager(),
ProcessManager: () => FakeProcessManager.any(),
Cache: () => cache,
Artifacts: () => Artifacts.test(),
});
......@@ -57,7 +55,7 @@ void main() {
expect(platformTypes, <String>['android', 'web']);
}, overrides: <Type, Generator>{
DeviceManager: () => _FakeDeviceManager(),
ProcessManager: () => MockProcessManager(),
ProcessManager: () => FakeProcessManager.any(),
Cache: () => cache,
Artifacts: () => Artifacts.test(),
});
......@@ -106,7 +104,7 @@ void main() {
);
}, overrides: <Type, Generator>{
DeviceManager: () => _FakeDeviceManager(),
ProcessManager: () => MockProcessManager(),
ProcessManager: () => FakeProcessManager.any(),
Cache: () => cache,
Artifacts: () => Artifacts.test(),
});
......@@ -127,39 +125,11 @@ webby (mobile) • webby • web-javascript • Web SDK (1.2.4) (emulato
);
}, overrides: <Type, Generator>{
DeviceManager: () => _FakeDeviceManager(),
ProcessManager: () => MockProcessManager(),
ProcessManager: () => FakeProcessManager.any(),
});
});
}
class MockProcessManager extends Mock implements ProcessManager {
@override
Future<ProcessResult> run(
List<dynamic> command, {
String workingDirectory,
Map<String, String> environment,
bool includeParentEnvironment = true,
bool runInShell = false,
Encoding stdoutEncoding = systemEncoding,
Encoding stderrEncoding = systemEncoding,
}) async {
return ProcessResult(0, 0, '', '');
}
@override
ProcessResult runSync(
List<dynamic> command, {
String workingDirectory,
Map<String, String> environment,
bool includeParentEnvironment = true,
bool runInShell = false,
Encoding stdoutEncoding = systemEncoding,
Encoding stderrEncoding = systemEncoding,
}) {
return ProcessResult(0, 0, '', '');
}
}
class _FakeDeviceManager extends DeviceManager {
_FakeDeviceManager();
......
......@@ -12,7 +12,6 @@ import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import '../../src/common.dart';
......@@ -27,9 +26,11 @@ final Platform linuxPlatform = FakePlatform(
void main() {
FileSystem fileSystem;
FakeProcessManager fakeProcessManager;
setUp(() {
fileSystem = MemoryFileSystem.test();
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
});
testWithoutContext('NoAndroidStudioValidator shows Android Studio as "not available" when not available.', () async {
......@@ -48,10 +49,15 @@ void main() {
});
testUsingContext('AndroidStudioValidator gives doctor error on java crash', () async {
when(globals.processManager.canRun(any)).thenReturn(true);
when(globals.processManager.runSync(any)).thenAnswer((Invocation _) {
throw const ProcessException('java', <String>['--version']);
});
fakeProcessManager.addCommand(FakeCommand(
command: const <String>[
'/opt/android-studio-with-cheese-5.0/jre/bin/java',
'-version',
],
onRun: () {
throw const ProcessException('java', <String>['-version']);
},
));
const String installPath = '/opt/android-studio-with-cheese-5.0';
const String studioHome = '$home/.AndroidStudioWithCheese5.0';
const String homeFile = '$studioHome/system/.home';
......@@ -68,9 +74,10 @@ void main() {
return message.isError && message.message.contains('ProcessException');
}).isNotEmpty, true);
}
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => MockProcessManager(),
ProcessManager: () => fakeProcessManager,
Platform: () => linuxPlatform,
FileSystemUtils: () => FileSystemUtils(
fileSystem: fileSystem,
......@@ -78,5 +85,3 @@ void main() {
),
});
}
class MockProcessManager extends Mock implements ProcessManager {}
......@@ -31,7 +31,6 @@ void main() {
// Create an l10n.yaml file
fileSystem.file('l10n.yaml').createSync();
final FakeProcessManager mockProcessManager = FakeProcessManager.any();
final BufferLogger mockBufferLogger = BufferLogger.test();
final Artifacts artifacts = Artifacts.test();
final Environment environment = Environment.test(
......@@ -39,7 +38,7 @@ void main() {
fileSystem: fileSystem,
logger: mockBufferLogger,
artifacts: artifacts,
processManager: mockProcessManager,
processManager: FakeProcessManager.any(),
);
final BuildSystem buildSystem = MockBuildSystem();
......@@ -72,7 +71,7 @@ void main() {
// Create an l10n.yaml file
fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: true');
final FakeProcessManager mockProcessManager = FakeProcessManager.any();
final FakeProcessManager fakeProcessManager = FakeProcessManager.any();
final BufferLogger mockBufferLogger = BufferLogger.test();
final Artifacts artifacts = Artifacts.test();
final Environment environment = Environment.test(
......@@ -80,7 +79,7 @@ void main() {
fileSystem: fileSystem,
logger: mockBufferLogger,
artifacts: artifacts,
processManager: mockProcessManager,
processManager: fakeProcessManager,
);
final BuildSystem buildSystem = MockBuildSystem();
......@@ -113,14 +112,13 @@ void main() {
// Create an l10n.yaml file
fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: null');
final FakeProcessManager mockProcessManager = FakeProcessManager.any();
final BufferLogger mockBufferLogger = BufferLogger.test();
final Environment environment = Environment.test(
fileSystem.currentDirectory,
fileSystem: fileSystem,
logger: mockBufferLogger,
artifacts: Artifacts.test(),
processManager: mockProcessManager,
processManager: FakeProcessManager.any(),
);
final BuildSystem buildSystem = MockBuildSystem();
......@@ -150,14 +148,13 @@ void main() {
);
pubspecFile.writeAsStringSync(content);
final FakeProcessManager mockProcessManager = FakeProcessManager.any();
final BufferLogger mockBufferLogger = BufferLogger.test();
final Environment environment = Environment.test(
fileSystem.currentDirectory,
fileSystem: fileSystem,
logger: mockBufferLogger,
artifacts: Artifacts.test(),
processManager: mockProcessManager,
processManager: FakeProcessManager.any(),
);
final BuildSystem buildSystem = MockBuildSystem();
......@@ -187,14 +184,13 @@ void main() {
// Create an l10n.yaml file
fileSystem.file('l10n.yaml').writeAsStringSync('helloWorld');
final FakeProcessManager mockProcessManager = FakeProcessManager.any();
final BufferLogger mockBufferLogger = BufferLogger.test();
final Environment environment = Environment.test(
fileSystem.currentDirectory,
fileSystem: fileSystem,
logger: mockBufferLogger,
artifacts: Artifacts.test(),
processManager: mockProcessManager,
processManager: FakeProcessManager.any(),
);
final BuildSystem buildSystem = MockBuildSystem();
......@@ -227,14 +223,13 @@ void main() {
// Create an l10n.yaml file
fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: nonBoolValue');
final FakeProcessManager mockProcessManager = FakeProcessManager.any();
final BufferLogger mockBufferLogger = BufferLogger.test();
final Environment environment = Environment.test(
fileSystem.currentDirectory,
fileSystem: fileSystem,
logger: mockBufferLogger,
artifacts: Artifacts.test(),
processManager: mockProcessManager,
processManager: FakeProcessManager.any(),
);
final BuildSystem buildSystem = MockBuildSystem();
......
......@@ -18,7 +18,6 @@ import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/ios/devices.dart';
import 'package:flutter_tools/src/ios/simulators.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:mockito/mockito.dart';
import 'package:package_config/package_config.dart';
......@@ -580,17 +579,6 @@ class MockIOSDevice extends Mock implements IOSDevice {
bool isSupportedForProject(FlutterProject flutterProject) => true;
}
class MockIOSSimulator extends Mock implements IOSSimulator {
@override
Future<TargetPlatform> get targetPlatform async => TargetPlatform.ios;
@override
bool isSupported() => true;
@override
bool isSupportedForProject(FlutterProject flutterProject) => true;
}
/// Common functionality for tracking mock interaction.
class BasicMock {
final List<String> messages = <String>[];
......@@ -710,9 +698,6 @@ class MockStdIn extends Mock implements IOSink {
class MockStream extends Mock implements Stream<List<int>> {}
class MockDevToolsServer extends Mock implements HttpServer {}
class MockInternetAddress extends Mock implements InternetAddress {}
class AlwaysTrueBotDetector implements BotDetector {
const AlwaysTrueBotDetector();
......
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