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

Replace MockProcessManager with FakeProcessManager (#67019)

parent b42cf8a7
...@@ -827,8 +827,6 @@ class TestHotRunnerFactory extends HotRunnerFactory { ...@@ -827,8 +827,6 @@ class TestHotRunnerFactory extends HotRunnerFactory {
} }
class MockDartDevelopmentService extends Mock implements DartDevelopmentService {} class MockDartDevelopmentService extends Mock implements DartDevelopmentService {}
class MockProcessManager extends Mock implements ProcessManager {}
class MockProcess extends Mock implements Process {}
class MockHttpClientRequest extends Mock implements HttpClientRequest {} class MockHttpClientRequest extends Mock implements HttpClientRequest {}
class MockHttpClientResponse extends Mock implements HttpClientResponse {} class MockHttpClientResponse extends Mock implements HttpClientResponse {}
class MockHttpHeaders extends Mock implements HttpHeaders {} class MockHttpHeaders extends Mock implements HttpHeaders {}
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart'; import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build_windows.dart'; import 'package:flutter_tools/src/commands/build_windows.dart';
...@@ -420,7 +419,5 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier ...@@ -420,7 +419,5 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier
}); });
} }
class MockProcessManager extends Mock implements ProcessManager {}
class MockProcess extends Mock implements Process {}
class MockVisualStudio extends Mock implements VisualStudio {} class MockVisualStudio extends Mock implements VisualStudio {}
class MockUsage extends Mock implements Usage {} class MockUsage extends Mock implements Usage {}
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:convert'; import 'dart:convert';
import 'dart:io' show ProcessResult;
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
...@@ -30,44 +29,35 @@ final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{ ...@@ -30,44 +29,35 @@ final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
Platform: _kNoColorTerminalPlatform, Platform: _kNoColorTerminalPlatform,
}; };
class MockitoProcessManager extends Mock implements ProcessManager {}
class MockitoAndroidSdk extends Mock implements AndroidSdk {} class MockitoAndroidSdk extends Mock implements AndroidSdk {}
class MockitoAndroidSdkVersion extends Mock implements AndroidSdkVersion {} class MockitoAndroidSdkVersion extends Mock implements AndroidSdkVersion {}
void main() { void main() {
group('Apk with partial Android SDK works', () { group('Apk with partial Android SDK works', () {
AndroidSdk sdk; AndroidSdk sdk;
ProcessManager mockProcessManager; FakeProcessManager fakeProcessManager;
MemoryFileSystem fs; MemoryFileSystem fs;
Cache cache; Cache cache;
File gradle;
final Map<Type, Generator> overrides = <Type, Generator>{ final Map<Type, Generator> overrides = <Type, Generator>{
AndroidSdk: () => sdk, AndroidSdk: () => sdk,
ProcessManager: () => mockProcessManager, ProcessManager: () => fakeProcessManager,
FileSystem: () => fs, FileSystem: () => fs,
Cache: () => cache, Cache: () => cache,
}; };
setUp(() async { setUp(() async {
sdk = MockitoAndroidSdk(); sdk = MockitoAndroidSdk();
mockProcessManager = MockitoProcessManager(); fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
fs = MemoryFileSystem.test(); fs = MemoryFileSystem.test();
cache = Cache.test( cache = Cache.test(
processManager: FakeProcessManager.any() processManager: FakeProcessManager.any(),
); );
Cache.flutterRoot = '../..'; Cache.flutterRoot = '../..';
when(sdk.licensesAvailable).thenReturn(true); when(sdk.licensesAvailable).thenReturn(true);
when(mockProcessManager.canRun(any)).thenReturn(true);
when(mockProcessManager.run(
any,
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) async => ProcessResult(1, 0, 'stdout', 'stderr'));
when(mockProcessManager.runSync(any)).thenReturn(ProcessResult(1, 0, 'stdout', 'stderr'));
final FlutterProject project = FlutterProject.current(); final FlutterProject project = FlutterProject.current();
gradle = globals.fs.file(project.android.hostAppGradleRoot.childFile( globals.fs.file(project.android.hostAppGradleRoot.childFile(
globals.platform.isWindows ? 'gradlew.bat' : 'gradlew', globals.platform.isWindows ? 'gradlew.bat' : 'gradlew',
).path)..createSync(recursive: true); ).path).createSync(recursive: true);
}); });
testUsingContext('Licenses not available, platform and buildtools available, apk exists', () async { testUsingContext('Licenses not available, platform and buildtools available, apk exists', () async {
...@@ -78,18 +68,19 @@ void main() { ...@@ -78,18 +68,19 @@ void main() {
when(sdk.latestVersion).thenReturn(sdkVersion); when(sdk.latestVersion).thenReturn(sdkVersion);
when(sdk.platformToolsAvailable).thenReturn(true); when(sdk.platformToolsAvailable).thenReturn(true);
when(sdk.licensesAvailable).thenReturn(false); when(sdk.licensesAvailable).thenReturn(false);
when(mockProcessManager.runSync(
argThat(equals(<String>[ fakeProcessManager.addCommand(
FakeCommand(
command: <String>[
aaptPath, aaptPath,
'dump', 'dump',
'xmltree', 'xmltree',
apkFile.path, apkFile.path,
'AndroidManifest.xml', 'AndroidManifest.xml',
])), ],
workingDirectory: anyNamed('workingDirectory'), stdout: _aaptDataWithDefaultEnabledAndMainLauncherActivity
environment: anyNamed('environment'), )
), );
).thenReturn(ProcessResult(0, 0, _aaptDataWithDefaultEnabledAndMainLauncherActivity, ''));
final ApplicationPackage applicationPackage = await ApplicationPackageFactory.instance.getPackageForPlatform( final ApplicationPackage applicationPackage = await ApplicationPackageFactory.instance.getPackageForPlatform(
TargetPlatform.android_arm, TargetPlatform.android_arm,
...@@ -97,6 +88,7 @@ void main() { ...@@ -97,6 +88,7 @@ void main() {
applicationBinary: apkFile, applicationBinary: apkFile,
); );
expect(applicationPackage.name, 'app.apk'); expect(applicationPackage.name, 'app.apk');
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: overrides); }, overrides: overrides);
testUsingContext('Licenses available, build tools not, apk exists', () async { testUsingContext('Licenses available, build tools not, apk exists', () async {
...@@ -117,18 +109,14 @@ void main() { ...@@ -117,18 +109,14 @@ void main() {
gradleWrapperDir.childFile('gradlew').writeAsStringSync('irrelevant'); gradleWrapperDir.childFile('gradlew').writeAsStringSync('irrelevant');
gradleWrapperDir.childFile('gradlew.bat').writeAsStringSync('irrelevant'); gradleWrapperDir.childFile('gradlew.bat').writeAsStringSync('irrelevant');
fakeProcessManager.addCommand(FakeCommand(command: <String>[gradle.path, 'dependencies']));
await ApplicationPackageFactory.instance.getPackageForPlatform( await ApplicationPackageFactory.instance.getPackageForPlatform(
TargetPlatform.android_arm, TargetPlatform.android_arm,
buildInfo: null, buildInfo: null,
applicationBinary: globals.fs.file('app.apk'), applicationBinary: globals.fs.file('app.apk'),
); );
verify( expect(fakeProcessManager.hasRemainingExpectations, isFalse);
mockProcessManager.run(
argThat(equals(<String>[gradle.path, 'dependencies'])),
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
),
).called(1);
}, overrides: overrides); }, overrides: overrides);
testUsingContext('Licenses available, build tools available, does not call gradle dependencies', () async { testUsingContext('Licenses available, build tools available, does not call gradle dependencies', () async {
...@@ -139,22 +127,15 @@ void main() { ...@@ -139,22 +127,15 @@ void main() {
TargetPlatform.android_arm, TargetPlatform.android_arm,
buildInfo: null, buildInfo: null,
); );
verifyNever( expect(fakeProcessManager.hasRemainingExpectations, isFalse);
mockProcessManager.run(
argThat(equals(<String>[gradle.path, 'dependencies'])),
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
),
);
}, overrides: overrides); }, overrides: overrides);
testUsingContext('returns null when failed to extract manifest', () async { testUsingContext('returns null when failed to extract manifest', () async {
final AndroidSdkVersion sdkVersion = MockitoAndroidSdkVersion(); final AndroidSdkVersion sdkVersion = MockitoAndroidSdkVersion();
when(sdk.latestVersion).thenReturn(sdkVersion); when(sdk.latestVersion).thenReturn(sdkVersion);
when(mockProcessManager.runSync(argThat(contains('logcat'))))
.thenReturn(ProcessResult(0, 1, '', ''));
expect(AndroidApk.fromApk(null), isNull); expect(AndroidApk.fromApk(null), isNull);
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: overrides); }, overrides: overrides);
}); });
......
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