Unverified Commit 06a20be5 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Remove MockBuildSystem from generate_synthetic_packages_test (#77983)

parent 82675474
......@@ -95,14 +95,14 @@ void main() {
group('Gradle', () {
Directory tempDir;
FakeProcessManager processManager;
FakeAndroidSdk mockAndroidSdk;
FakeAndroidSdk fakeAndroidSdk;
TestUsage testUsage;
setUp(() {
testUsage = TestUsage();
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
processManager = FakeProcessManager.any();
mockAndroidSdk = FakeAndroidSdk(globals.fs.directory('irrelevant'));
fakeAndroidSdk = FakeAndroidSdk(globals.fs.directory('irrelevant'));
});
tearDown(() {
......@@ -169,7 +169,7 @@ void main() {
));
},
overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
AndroidSdk: () => fakeAndroidSdk,
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
ProcessManager: () => processManager,
Usage: () => testUsage,
......@@ -209,7 +209,7 @@ void main() {
));
},
overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
AndroidSdk: () => fakeAndroidSdk,
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
ProcessManager: () => processManager,
Usage: () => testUsage,
......
......@@ -4,6 +4,8 @@
// @dart = 2.8
import 'dart:async';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart';
......@@ -11,11 +13,11 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/dart/generate_synthetic_packages.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/targets/localizations.dart';
import 'package:mockito/mockito.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fake_process_manager.dart';
import '../../src/fakes.dart';
void main() {
testWithoutContext('calls buildSystem.build with blank l10n.yaml file', () async {
......@@ -42,7 +44,15 @@ void main() {
artifacts: artifacts,
processManager: FakeProcessManager.any(),
);
final BuildSystem buildSystem = MockBuildSystem();
final Completer<void> completer = Completer<void>();
final BuildResult exception = BuildResult(success: false, exceptions: <String, ExceptionMeasurement>{
'hello': ExceptionMeasurement('hello', 'bar', null),
});
final TestBuildSystem buildSystem = TestBuildSystem.all(exception, (Target target, Environment environment) {
expect(target, const GenerateLocalizationsTarget());
expect(environment, environment);
completer.complete();
});
await expectLater(
() => generateLocalizationsSyntheticPackage(
......@@ -51,11 +61,7 @@ void main() {
),
throwsToolExit(message: 'Generating synthetic localizations package has failed.'),
);
// [BuildSystem] should have called build with [GenerateLocalizationsTarget].
verify(buildSystem.build(
const GenerateLocalizationsTarget(),
environment,
)).called(1);
await completer.future;
});
testWithoutContext('calls buildSystem.build with l10n.yaml synthetic-package: true', () async {
......@@ -83,7 +89,15 @@ void main() {
artifacts: artifacts,
processManager: fakeProcessManager,
);
final BuildSystem buildSystem = MockBuildSystem();
final Completer<void> completer = Completer<void>();
final BuildResult exception = BuildResult(success: false, exceptions: <String, ExceptionMeasurement>{
'hello': ExceptionMeasurement('hello', 'bar', null),
});
final TestBuildSystem buildSystem = TestBuildSystem.all(exception, (Target target, Environment environment) {
expect(target, const GenerateLocalizationsTarget());
expect(environment, environment);
completer.complete();
});
await expectLater(
() => generateLocalizationsSyntheticPackage(
......@@ -92,11 +106,7 @@ void main() {
),
throwsToolExit(message: 'Generating synthetic localizations package has failed.'),
);
// [BuildSystem] should have called build with [GenerateLocalizationsTarget].
verify(buildSystem.build(
const GenerateLocalizationsTarget(),
environment,
)).called(1);
await completer.future;
});
testWithoutContext('calls buildSystem.build with l10n.yaml synthetic-package: null', () async {
......@@ -122,7 +132,15 @@ void main() {
artifacts: Artifacts.test(),
processManager: FakeProcessManager.any(),
);
final BuildSystem buildSystem = MockBuildSystem();
final Completer<void> completer = Completer<void>();
final BuildResult exception = BuildResult(success: false, exceptions: <String, ExceptionMeasurement>{
'hello': ExceptionMeasurement('hello', 'bar', null),
});
final TestBuildSystem buildSystem = TestBuildSystem.all(exception, (Target target, Environment environment) {
expect(target, const GenerateLocalizationsTarget());
expect(environment, environment);
completer.complete();
});
await expectLater(
() => generateLocalizationsSyntheticPackage(
......@@ -131,11 +149,7 @@ void main() {
),
throwsToolExit(message: 'Generating synthetic localizations package has failed.'),
);
// [BuildSystem] should have called build with [GenerateLocalizationsTarget].
verify(buildSystem.build(
const GenerateLocalizationsTarget(),
environment,
)).called(1);
await completer.future;
});
testWithoutContext('does not call buildSystem.build when l10n.yaml is not present', () async {
......@@ -158,17 +172,13 @@ void main() {
artifacts: Artifacts.test(),
processManager: FakeProcessManager.any(),
);
final BuildSystem buildSystem = MockBuildSystem();
// Will throw if build is called.
final TestBuildSystem buildSystem = TestBuildSystem.all(null);
await generateLocalizationsSyntheticPackage(
environment: environment,
buildSystem: buildSystem,
);
// [BuildSystem] should not be called with [GenerateLocalizationsTarget].
verifyNever(buildSystem.build(
const GenerateLocalizationsTarget(),
environment,
));
});
testWithoutContext('does not call buildSystem.build with incorrect l10n.yaml format', () async {
......@@ -194,7 +204,8 @@ void main() {
artifacts: Artifacts.test(),
processManager: FakeProcessManager.any(),
);
final BuildSystem buildSystem = MockBuildSystem();
// Will throw if build is called.
final TestBuildSystem buildSystem = TestBuildSystem.all(null);
await expectLater(
() => generateLocalizationsSyntheticPackage(
......@@ -203,11 +214,6 @@ void main() {
),
throwsToolExit(message: 'to contain a map, instead was helloWorld'),
);
// [BuildSystem] should not be called with [GenerateLocalizationsTarget].
verifyNever(buildSystem.build(
const GenerateLocalizationsTarget(),
environment,
));
});
testWithoutContext('does not call buildSystem.build with non-bool "synthetic-package" value', () async {
......@@ -233,7 +239,8 @@ void main() {
artifacts: Artifacts.test(),
processManager: FakeProcessManager.any(),
);
final BuildSystem buildSystem = MockBuildSystem();
// Will throw if build is called.
final TestBuildSystem buildSystem = TestBuildSystem.all(null);
await expectLater(
() => generateLocalizationsSyntheticPackage(
......@@ -242,12 +249,5 @@ void main() {
),
throwsToolExit(message: 'to have a bool value, instead was "nonBoolValue"'),
);
// [BuildSystem] should not be called with [GenerateLocalizationsTarget].
verifyNever(buildSystem.build(
const GenerateLocalizationsTarget(),
environment,
));
});
}
class MockBuildSystem extends Mock implements BuildSystem {}
......@@ -660,7 +660,7 @@ class TestBuildSystem implements BuildSystem {
return _singleResult;
}
if (_nextResult >= _results.length) {
throw StateError('Unexpected buildIncremental request of ${target.name}');
throw StateError('Unexpected build request of ${target.name}');
}
return _results[_nextResult++];
}
......
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