Unverified Commit 8b144544 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Remove MockFlutterVersion from mocks (#78089)

parent c94648f9
......@@ -12,12 +12,11 @@ import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/downgrade.dart';
import 'package:flutter_tools/src/persistent_tool_state.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/mocks.dart';
import '../../src/fakes.dart';
void main() {
FileSystem fileSystem;
......@@ -25,7 +24,6 @@ void main() {
AnsiTerminal terminal;
ProcessManager processManager;
MockStdio mockStdio;
FlutterVersion flutterVersion;
setUpAll(() {
Cache.disableLocking();
......@@ -36,7 +34,6 @@ void main() {
});
setUp(() {
flutterVersion = MockFlutterVersion();
mockStdio = MockStdio();
processManager = FakeProcessManager.any();
terminal = MockTerminal();
......@@ -45,6 +42,7 @@ void main() {
});
testUsingContext('Downgrade exits on unknown channel', () async {
final FakeFlutterVersion fakeFlutterVersion = FakeFlutterVersion(channel: 'unknown');
fileSystem.currentDirectory.childFile('.flutter_tool_state')
.writeAsStringSync('{"last-active-master-version":"invalid"}');
final DowngradeCommand command = DowngradeCommand(
......@@ -52,7 +50,7 @@ void main() {
processManager: processManager,
terminal: terminal,
stdio: mockStdio,
flutterVersion: flutterVersion,
flutterVersion: fakeFlutterVersion,
logger: bufferLogger,
);
......@@ -61,7 +59,7 @@ void main() {
});
testUsingContext('Downgrade exits on no recorded version', () async {
when(flutterVersion.channel).thenReturn('dev');
final FakeFlutterVersion fakeFlutterVersion = FakeFlutterVersion(channel: 'dev');
fileSystem.currentDirectory.childFile('.flutter_tool_state')
.writeAsStringSync('{"last-active-master-version":"abcd"}');
final DowngradeCommand command = DowngradeCommand(
......@@ -77,7 +75,7 @@ void main() {
]),
terminal: terminal,
stdio: mockStdio,
flutterVersion: flutterVersion,
flutterVersion: fakeFlutterVersion,
logger: bufferLogger,
);
......@@ -90,7 +88,7 @@ void main() {
});
testUsingContext('Downgrade exits on unknown recorded version', () async {
when(flutterVersion.channel).thenReturn('master');
final FakeFlutterVersion fakeFlutterVersion = FakeFlutterVersion(channel: 'master');
fileSystem.currentDirectory.childFile('.flutter_tool_state')
.writeAsStringSync('{"last-active-master-version":"invalid"}');
final DowngradeCommand command = DowngradeCommand(
......@@ -105,7 +103,7 @@ void main() {
]),
terminal: terminal,
stdio: mockStdio,
flutterVersion: flutterVersion,
flutterVersion: fakeFlutterVersion,
logger: bufferLogger,
);
......@@ -114,7 +112,7 @@ void main() {
});
testUsingContext('Downgrade prompts for user input when terminal is attached - y', () async {
when(flutterVersion.channel).thenReturn('master');
final FakeFlutterVersion fakeFlutterVersion = FakeFlutterVersion(channel: 'master');
when(mockStdio.hasTerminal).thenReturn(true);
fileSystem.currentDirectory.childFile('.flutter_tool_state')
.writeAsStringSync('{"last-active-master-version":"g6b00b5e88"}');
......@@ -123,7 +121,7 @@ void main() {
processManager: processManager,
terminal: terminal,
stdio: mockStdio,
flutterVersion: flutterVersion,
flutterVersion: fakeFlutterVersion,
logger: bufferLogger,
);
......@@ -144,7 +142,7 @@ void main() {
});
testUsingContext('Downgrade prompts for user input when terminal is attached - n', () async {
when(flutterVersion.channel).thenReturn('master');
final FakeFlutterVersion fakeFlutterVersion = FakeFlutterVersion(channel: 'master');
when(mockStdio.hasTerminal).thenReturn(true);
fileSystem.currentDirectory.childFile('.flutter_tool_state')
.writeAsStringSync('{"last-active-master-version":"g6b00b5e88"}');
......@@ -153,7 +151,7 @@ void main() {
processManager: processManager,
terminal: terminal,
stdio: mockStdio,
flutterVersion: flutterVersion,
flutterVersion: fakeFlutterVersion,
logger: bufferLogger,
);
......@@ -174,7 +172,7 @@ void main() {
});
testUsingContext('Downgrade does not prompt when there is no terminal', () async {
when(flutterVersion.channel).thenReturn('master');
final FakeFlutterVersion fakeFlutterVersion = FakeFlutterVersion(channel: 'master');
when(mockStdio.hasTerminal).thenReturn(false);
fileSystem.currentDirectory.childFile('.flutter_tool_state')
.writeAsStringSync('{"last-active-master-version":"g6b00b5e88"}');
......@@ -186,7 +184,7 @@ void main() {
processManager: processManager,
terminal: terminal,
stdio: mockStdio,
flutterVersion: flutterVersion,
flutterVersion: fakeFlutterVersion,
logger: bufferLogger,
);
......@@ -201,7 +199,7 @@ void main() {
});
testUsingContext('Downgrade performs correct git commands', () async {
when(flutterVersion.channel).thenReturn('master');
final FakeFlutterVersion fakeFlutterVersion = FakeFlutterVersion(channel: 'master');
when(mockStdio.hasTerminal).thenReturn(false);
fileSystem.currentDirectory.childFile('.flutter_tool_state')
.writeAsStringSync('{"last-active-master-version":"g6b00b5e88"}');
......@@ -230,7 +228,7 @@ void main() {
]),
terminal: terminal,
stdio: mockStdio,
flutterVersion: flutterVersion,
flutterVersion: fakeFlutterVersion,
logger: bufferLogger,
);
......
......@@ -14,13 +14,12 @@ import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/persistent_tool_state.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fake_process_manager.dart';
import '../../src/mocks.dart';
import '../../src/fakes.dart';
void main() {
group('UpgradeCommandRunner', () {
......@@ -28,7 +27,6 @@ void main() {
UpgradeCommandRunner realCommandRunner;
FakeProcessManager processManager;
FakePlatform fakePlatform;
final MockFlutterVersion flutterVersion = MockFlutterVersion();
const GitTagVersion gitTagVersion = GitTagVersion(
x: 1,
y: 2,
......@@ -37,7 +35,6 @@ void main() {
commits: 5,
hash: 'asd',
);
when(flutterVersion.channel).thenReturn('dev');
setUp(() {
fakeCommandRunner = FakeUpgradeCommandRunner();
......@@ -51,9 +48,9 @@ void main() {
});
testUsingContext('throws on unknown tag, official branch, noforce', () async {
final FakeFlutterVersion flutterVersion = FakeFlutterVersion(channel: 'dev');
const String upstreamRevision = '';
final MockFlutterVersion latestVersion = MockFlutterVersion();
when(latestVersion.frameworkRevision).thenReturn(upstreamRevision);
final FakeFlutterVersion latestVersion = FakeFlutterVersion(frameworkRevision: upstreamRevision);
fakeCommandRunner.remoteVersion = latestVersion;
final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
......@@ -65,15 +62,15 @@ void main() {
verifyOnly: false,
);
expect(result, throwsToolExit());
expect(processManager.hasRemainingExpectations, isFalse);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
});
testUsingContext('throws tool exit with uncommitted changes', () async {
final FakeFlutterVersion flutterVersion = FakeFlutterVersion(channel: 'dev');
const String upstreamRevision = '';
final MockFlutterVersion latestVersion = MockFlutterVersion();
when(latestVersion.frameworkRevision).thenReturn(upstreamRevision);
final FakeFlutterVersion latestVersion = FakeFlutterVersion(frameworkRevision: upstreamRevision);
fakeCommandRunner.remoteVersion = latestVersion;
fakeCommandRunner.willHaveUncommittedChanges = true;
......@@ -86,16 +83,15 @@ void main() {
verifyOnly: false,
);
expect(result, throwsToolExit());
expect(processManager.hasRemainingExpectations, isFalse);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
});
testUsingContext("Doesn't continue on known tag, dev branch, no force, already up-to-date", () async {
const String revision = 'abc123';
final MockFlutterVersion latestVersion = MockFlutterVersion();
when(flutterVersion.frameworkRevision).thenReturn(revision);
when(latestVersion.frameworkRevision).thenReturn(revision);
final FakeFlutterVersion latestVersion = FakeFlutterVersion(frameworkRevision: revision);
final FakeFlutterVersion flutterVersion = FakeFlutterVersion(channel: 'dev', frameworkRevision: revision);
fakeCommandRunner.alreadyUpToDate = true;
fakeCommandRunner.remoteVersion = latestVersion;
......@@ -109,7 +105,7 @@ void main() {
);
expect(await result, FlutterCommandResult.success());
expect(testLogger.statusText, contains('Flutter is already up to date'));
expect(processManager.hasRemainingExpectations, isFalse);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Platform: () => fakePlatform,
......@@ -121,15 +117,18 @@ void main() {
const String version = '1.2.3';
const String upstreamVersion = '4.5.6';
when(flutterVersion.frameworkRevision).thenReturn(revision);
when(flutterVersion.frameworkRevisionShort).thenReturn(revision);
when(flutterVersion.frameworkVersion).thenReturn(version);
final MockFlutterVersion latestVersion = MockFlutterVersion();
final FakeFlutterVersion flutterVersion = FakeFlutterVersion(
channel: 'dev',
frameworkRevision: revision,
frameworkRevisionShort: revision,
frameworkVersion: version,
);
when(latestVersion.frameworkRevision).thenReturn(upstreamRevision);
when(latestVersion.frameworkRevisionShort).thenReturn(upstreamRevision);
when(latestVersion.frameworkVersion).thenReturn(upstreamVersion);
final FakeFlutterVersion latestVersion = FakeFlutterVersion(
frameworkRevision: upstreamRevision,
frameworkRevisionShort: upstreamRevision,
frameworkVersion: upstreamVersion,
);
fakeCommandRunner.alreadyUpToDate = false;
fakeCommandRunner.remoteVersion = latestVersion;
......@@ -146,7 +145,7 @@ void main() {
expect(testLogger.statusText, contains('A new version of Flutter is available'));
expect(testLogger.statusText, contains('The latest version: 4.5.6 (revision def456)'));
expect(testLogger.statusText, contains('Your current version: 1.2.3 (revision abc123)'));
expect(processManager.hasRemainingExpectations, isFalse);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Platform: () => fakePlatform,
......@@ -178,7 +177,7 @@ void main() {
expect(updateVersion.frameworkVersion, version);
expect(updateVersion.frameworkRevision, revision);
expect(processManager.hasRemainingExpectations, isFalse);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Platform: () => fakePlatform,
......@@ -203,7 +202,7 @@ void main() {
() async => realCommandRunner.fetchLatestVersion(),
throwsToolExit(message: 'You are not currently on a release branch.'),
);
expect(processManager.hasRemainingExpectations, isFalse);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Platform: () => fakePlatform,
......@@ -230,7 +229,7 @@ void main() {
message: 'Unable to upgrade Flutter: no origin repository configured.',
),
);
expect(processManager.hasRemainingExpectations, isFalse);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Platform: () => fakePlatform,
......@@ -254,7 +253,7 @@ void main() {
() async => realCommandRunner.attemptReset(revision),
throwsToolExit(message: errorMessage),
);
expect(processManager.hasRemainingExpectations, isFalse);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Platform: () => fakePlatform,
......@@ -273,7 +272,7 @@ void main() {
),
);
await realCommandRunner.flutterUpgradeContinue();
expect(processManager.hasRemainingExpectations, isFalse);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Platform: () => fakePlatform,
......@@ -285,13 +284,15 @@ void main() {
const String version = '1.2.3';
const String upstreamVersion = '4.5.6';
when(flutterVersion.frameworkRevision).thenReturn(revision);
when(flutterVersion.frameworkVersion).thenReturn(version);
final MockFlutterVersion latestVersion = MockFlutterVersion();
when(latestVersion.frameworkRevision).thenReturn(upstreamRevision);
when(latestVersion.frameworkVersion).thenReturn(upstreamVersion);
final FakeFlutterVersion flutterVersion = FakeFlutterVersion(
channel: 'dev',
frameworkRevision: revision,
frameworkVersion: version,
);
final FakeFlutterVersion latestVersion = FakeFlutterVersion(
frameworkRevision: upstreamRevision,
frameworkVersion: upstreamVersion,
);
fakeCommandRunner.alreadyUpToDate = false;
fakeCommandRunner.remoteVersion = latestVersion;
......@@ -325,7 +326,7 @@ void main() {
),
);
await realCommandRunner.precacheArtifacts();
expect(processManager.hasRemainingExpectations, isFalse);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Platform: () => fakePlatform,
......@@ -344,8 +345,8 @@ void main() {
});
testUsingContext('does not throw on unknown tag, official branch, force', () async {
final MockFlutterVersion latestVersion = MockFlutterVersion();
fakeCommandRunner.remoteVersion = latestVersion;
fakeCommandRunner.remoteVersion = FakeFlutterVersion(frameworkRevision: null);
final FakeFlutterVersion flutterVersion = FakeFlutterVersion(channel: 'dev');
final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
force: true,
......@@ -356,15 +357,15 @@ void main() {
verifyOnly: false,
);
expect(await result, FlutterCommandResult.success());
expect(processManager.hasRemainingExpectations, isFalse);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Platform: () => fakePlatform,
});
testUsingContext('does not throw tool exit with uncommitted changes and force', () async {
final MockFlutterVersion latestVersion = MockFlutterVersion();
fakeCommandRunner.remoteVersion = latestVersion;
final FakeFlutterVersion flutterVersion = FakeFlutterVersion(channel: 'dev');
fakeCommandRunner.remoteVersion = FakeFlutterVersion(frameworkRevision: null);
fakeCommandRunner.willHaveUncommittedChanges = true;
final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
......@@ -376,15 +377,15 @@ void main() {
verifyOnly: false,
);
expect(await result, FlutterCommandResult.success());
expect(processManager.hasRemainingExpectations, isFalse);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Platform: () => fakePlatform,
});
testUsingContext("Doesn't throw on known tag, dev branch, no force", () async {
final MockFlutterVersion latestVersion = MockFlutterVersion();
fakeCommandRunner.remoteVersion = latestVersion;
final FakeFlutterVersion flutterVersion = FakeFlutterVersion(channel: 'dev');
fakeCommandRunner.remoteVersion = FakeFlutterVersion(frameworkRevision: null);
final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
force: false,
......@@ -395,7 +396,7 @@ void main() {
verifyOnly: false,
);
expect(await result, FlutterCommandResult.success());
expect(processManager.hasRemainingExpectations, isFalse);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Platform: () => fakePlatform,
......@@ -406,8 +407,6 @@ void main() {
Directory tempDir;
File flutterToolState;
FlutterVersion mockFlutterVersion;
setUp(() {
Cache.disableLocking();
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
......@@ -426,7 +425,6 @@ void main() {
]);
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_upgrade_test.');
flutterToolState = tempDir.childFile('.flutter_tool_state');
mockFlutterVersion = MockFlutterVersion();
});
tearDown(() {
......@@ -452,7 +450,7 @@ void main() {
containsPair('redisplay-welcome-message', true),
);
}, overrides: <Type, Generator>{
FlutterVersion: () => mockFlutterVersion,
FlutterVersion: () => FakeFlutterVersion(),
ProcessManager: () => fakeProcessManager,
PersistentToolState: () => PersistentToolState.test(
directory: tempDir,
......
......@@ -15,7 +15,6 @@ import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/ios/devices.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
......@@ -235,4 +234,3 @@ class MockStdIn extends Mock implements IOSink {
}
class MockStream extends Mock implements Stream<List<int>> {}
class MockFlutterVersion extends Mock implements FlutterVersion {}
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