Unverified Commit 945e0df1 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove several AndroidSdk Mocks (#77264)

parent 6b500fa7
......@@ -23,7 +23,7 @@ import 'package:process/process.dart';
import '../../src/android_common.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/mocks.dart';
import '../../src/mocks.dart' hide MockAndroidSdk;
void main() {
Cache.disableLocking();
......@@ -173,8 +173,7 @@ void main() {
return Future<ProcessResult>.value(ProcessResult(0, 0, '', ''));
});
mockAndroidSdk = MockAndroidSdk();
when(mockAndroidSdk.directory).thenReturn(globals.fs.directory('irrelevant'));
mockAndroidSdk = FakeAndroidSdk(globals.fs.directory('irrelevant'));
});
tearDown(() {
......@@ -530,5 +529,11 @@ Future<BuildApkCommand> runBuildApkCommand(
return command;
}
class MockAndroidSdk extends Mock implements AndroidSdk {}
class FakeAndroidSdk extends Fake implements AndroidSdk {
FakeAndroidSdk(this.directory);
@override
final Directory directory;
}
class MockProcessManager extends Mock implements ProcessManager {}
......@@ -16,13 +16,12 @@ import 'package:flutter_tools/src/commands/build_appbundle.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
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/android_common.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/mocks.dart';
void main() {
Cache.disableLocking();
......@@ -97,64 +96,15 @@ void main() {
group('Gradle', () {
Directory tempDir;
ProcessManager mockProcessManager;
MockAndroidSdk mockAndroidSdk;
String gradlew;
FakeProcessManager processManager;
FakeAndroidSdk mockAndroidSdk;
TestUsage testUsage;
setUp(() {
testUsage = TestUsage();
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
gradlew = globals.fs.path.join(tempDir.path, 'flutter_project', 'android',
globals.platform.isWindows ? 'gradlew.bat' : 'gradlew');
mockProcessManager = MockProcessManager();
when(mockProcessManager.run(<String>[gradlew, '-v'],
environment: anyNamed('environment')))
.thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(0, 0, '', '')));
when(mockProcessManager.run(<String>[gradlew, 'app:properties'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment')))
.thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(0, 0, 'buildDir: irrelevant', '')));
when(mockProcessManager.run(<String>[gradlew, 'app:tasks', '--all', '--console=auto'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment')))
.thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(0, 0, 'assembleRelease', '')));
// Fallback with error.
final Process process = createMockProcess(exitCode: 1);
when(mockProcessManager.start(any,
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment')))
.thenAnswer((_) => Future<Process>.value(process));
when(mockProcessManager.canRun(any)).thenReturn(false);
when(mockProcessManager.runSync(
argThat(contains(contains('gen_snapshot'))),
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenReturn(ProcessResult(0, 255, '', ''));
when(mockProcessManager.runSync(
<String>['/usr/bin/xcode-select', '--print-path'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenReturn(ProcessResult(0, 0, '', ''));
when(mockProcessManager.run(
<String>['which', 'pod'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) {
return Future<ProcessResult>.value(ProcessResult(0, 0, '', ''));
});
mockAndroidSdk = MockAndroidSdk();
when(mockAndroidSdk.licensesAvailable).thenReturn(true);
when(mockAndroidSdk.platformToolsAvailable).thenReturn(true);
when(mockAndroidSdk.validateSdkWellFormed()).thenReturn(const <String>[]);
when(mockAndroidSdk.directory).thenReturn(globals.fs.directory('irrelevant'));
processManager = FakeProcessManager.any();
mockAndroidSdk = FakeAndroidSdk(globals.fs.directory('irrelevant'));
});
tearDown(() {
......@@ -178,7 +128,7 @@ void main() {
overrides: <Type, Generator>{
AndroidSdk: () => null,
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
ProcessManager: () => mockProcessManager,
ProcessManager: () => processManager,
});
});
......@@ -192,25 +142,6 @@ void main() {
.childFile('gradle.properties')
.writeAsStringSync('android.useAndroidX=false');
when(mockProcessManager.start(
<String>[
gradlew,
'-q',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'assembleRelease',
],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) {
return Future<Process>.value(
createMockProcess(
exitCode: 0,
stdout: '',
),
);
});
// The command throws a [ToolExit] because it expects an AAB in the file system.
await expectLater(() async {
await runBuildAppBundleCommand(
......@@ -242,7 +173,7 @@ void main() {
overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
ProcessManager: () => mockProcessManager,
ProcessManager: () => processManager,
Usage: () => testUsage,
});
......@@ -250,25 +181,6 @@ void main() {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=app']);
when(mockProcessManager.start(
<String>[
gradlew,
'-q',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'assembleRelease',
],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) {
return Future<Process>.value(
createMockProcess(
exitCode: 0,
stdout: '',
),
);
});
// The command throws a [ToolExit] because it expects an AAB in the file system.
await expectLater(() async {
await runBuildAppBundleCommand(
......@@ -278,11 +190,11 @@ void main() {
expect(
testLogger.statusText,
not(containsIgnoringWhitespace("Your app isn't using AndroidX")),
isNot(containsIgnoringWhitespace("Your app isn't using AndroidX")),
);
expect(
testLogger.statusText,
not(
isNot(
containsIgnoringWhitespace(
'To avoid potential build failures, you can quickly migrate your app by '
'following the steps on https://goo.gl/CP92wY'),
......@@ -301,7 +213,7 @@ void main() {
overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
ProcessManager: () => mockProcessManager,
ProcessManager: () => processManager,
Usage: () => testUsage,
});
});
......@@ -322,9 +234,9 @@ Future<BuildAppBundleCommand> runBuildAppBundleCommand(
return command;
}
Matcher not(Matcher target){
return isNot(target);
}
class FakeAndroidSdk extends Fake implements AndroidSdk {
FakeAndroidSdk(this.directory);
class MockAndroidSdk extends Mock implements AndroidSdk {}
class MockProcessManager extends Mock implements ProcessManager {}
@override
final Directory directory;
}
......@@ -13,7 +13,7 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
......@@ -49,9 +49,7 @@ void main() {
setUp(() {
processManager = FakeProcessManager.list(<FakeCommand>[]);
fileSystem = MemoryFileSystem.test();
androidSdk = MockAndroidSdk();
when(androidSdk.adbPath).thenReturn('adb');
when(androidSdk.licensesAvailable).thenReturn(false);
androidSdk = FakeAndroidSdk();
});
for (final TargetPlatform targetPlatform in <TargetPlatform>[
......@@ -291,4 +289,10 @@ void main() {
});
}
class MockAndroidSdk extends Mock implements AndroidSdk {}
class FakeAndroidSdk extends Fake implements AndroidSdk {
@override
String get adbPath => 'adb';
@override
bool get licensesAvailable => false;
}
......@@ -9,7 +9,7 @@ import 'package:flutter_tools/src/android/android_device.dart';
import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
......@@ -17,7 +17,7 @@ import '../../src/context.dart';
void main() {
testWithoutContext('AndroidDevice.stopApp handles a null ApplicationPackage', () async {
final AndroidDevice androidDevice = AndroidDevice('1234',
androidSdk: MockAndroidSdk(),
androidSdk: FakeAndroidSdk(),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'linux'),
......@@ -28,4 +28,4 @@ void main() {
});
}
class MockAndroidSdk extends Mock implements AndroidSdk {}
class FakeAndroidSdk extends Fake implements AndroidSdk {}
......@@ -19,7 +19,7 @@ import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
......@@ -63,7 +63,7 @@ void main() {
platform: FakePlatform(operatingSystem: 'macos')
);
// Parsing succeedes despite the error.
// Parsing succeeds despite the error.
expect(await windowsDevice.isLocalEmulator, true);
// Parsing fails and these default to false.
......@@ -466,8 +466,7 @@ AndroidDevice setUpAndroidDevice({
Platform platform,
AndroidConsoleSocketFactory androidConsoleSocketFactory = kAndroidConsoleSocketFactory,
}) {
androidSdk ??= MockAndroidSdk();
when(androidSdk.adbPath).thenReturn('adb');
androidSdk ??= FakeAndroidSdk();
return AndroidDevice(id ?? '1234',
logger: BufferLogger.test(),
platform: platform ?? FakePlatform(operatingSystem: 'linux'),
......@@ -478,7 +477,10 @@ AndroidDevice setUpAndroidDevice({
);
}
class MockAndroidSdk extends Mock implements AndroidSdk {}
class FakeAndroidSdk extends Fake implements AndroidSdk {
@override
String get adbPath => 'adb';
}
const String kAdbShellGetprop = '''
[dalvik.vm.dex2oat-Xms]: [64m]
......
......@@ -630,7 +630,7 @@ flutter:
group('buildPluginsAsAar', () {
FileSystem fs;
FakeProcessManager fakeProcessManager;
MockAndroidSdk mockAndroidSdk;
FakeAndroidSdk androidSdk;
AndroidGradleBuilder builder;
BufferLogger logger;
......@@ -638,8 +638,7 @@ flutter:
logger = BufferLogger.test();
fs = MemoryFileSystem.test();
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
mockAndroidSdk = MockAndroidSdk();
when(mockAndroidSdk.directory).thenReturn(fs.directory('irrelevant'));
androidSdk = FakeAndroidSdk();
builder = AndroidGradleBuilder(
logger: logger,
processManager: fakeProcessManager,
......@@ -761,7 +760,7 @@ plugin2=${plugin2.path}
);
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
AndroidSdk: () => androidSdk,
FileSystem: () => fs,
ProcessManager: () => fakeProcessManager,
GradleUtils: () => FakeGradleUtils(),
......@@ -808,7 +807,7 @@ plugin1=${plugin1.path}
);
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
AndroidSdk: () => androidSdk,
FileSystem: () => fs,
ProcessManager: () => fakeProcessManager,
GradleUtils: () => FakeGradleUtils(),
......@@ -1031,6 +1030,6 @@ class FakeGradleUtils extends GradleUtils {
}
}
class MockAndroidSdk extends Mock implements AndroidSdk {}
class FakeAndroidSdk extends Fake implements AndroidSdk {}
class MockAndroidProject extends Mock implements AndroidProject {}
class MockFlutterProject extends Mock implements FlutterProject {}
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