Skip to content

Commit

Permalink
Migrate some test files to null safety (#104469)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmagman committed May 24, 2022
1 parent b3e98a9 commit a56c5e5
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/memory.dart';
import 'package:flutter_tools/src/android/android_device_discovery.dart';
import 'package:flutter_tools/src/android/android_sdk.dart';
Expand All @@ -15,11 +13,11 @@ import 'package:flutter_tools/src/device.dart';
import 'package:test/fake.dart';

import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fake_process_manager.dart';
import '../../src/fakes.dart';

void main() {
AndroidWorkflow androidWorkflow;
late AndroidWorkflow androidWorkflow;

setUp(() {
androidWorkflow = AndroidWorkflow(
Expand Down Expand Up @@ -243,5 +241,5 @@ class FakeAndroidSdk extends Fake implements AndroidSdk {
FakeAndroidSdk([this.adbPath = 'adb']);

@override
final String adbPath;
final String? adbPath;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/memory.dart';
import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/android/android_studio.dart';
Expand All @@ -18,15 +16,15 @@ import 'package:flutter_tools/src/doctor_validator.dart';
import 'package:test/fake.dart';

import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fake_process_manager.dart';
import '../../src/fakes.dart';

void main() {
FakeAndroidSdk sdk;
Logger logger;
MemoryFileSystem fileSystem;
FakeProcessManager processManager;
FakeStdio stdio;
late FakeAndroidSdk sdk;
late Logger logger;
late MemoryFileSystem fileSystem;
late FakeProcessManager processManager;
late FakeStdio stdio;

setUp(() {
sdk = FakeAndroidSdk();
Expand Down Expand Up @@ -532,31 +530,31 @@ Review licenses that have not been accepted (y/N)?

class FakeAndroidSdk extends Fake implements AndroidSdk {
@override
String sdkManagerPath;
String? sdkManagerPath;

@override
String sdkManagerVersion;
String? sdkManagerVersion;

@override
String adbPath;
String? adbPath;

@override
bool licensesAvailable;
bool licensesAvailable = false;

@override
bool platformToolsAvailable;
bool platformToolsAvailable = false;

@override
bool cmdlineToolsAvailable;
bool cmdlineToolsAvailable = false;

@override
Directory directory;
Directory directory = MemoryFileSystem.test().directory('/foo/bar');

@override
AndroidSdkVersion latestVersion;
AndroidSdkVersion? latestVersion;

@override
String emulatorPath;
String? emulatorPath;

@override
List<String> validateSdkWellFormed() => <String>[];
Expand All @@ -567,10 +565,10 @@ class FakeAndroidSdk extends Fake implements AndroidSdk {

class FakeAndroidSdkVersion extends Fake implements AndroidSdkVersion {
@override
int sdkLevel;
int sdkLevel = 0;

@override
Version buildToolsVersion;
Version buildToolsVersion = Version(0, 0, 0);

@override
String get buildToolsVersionName => '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/os.dart';
Expand All @@ -20,9 +18,9 @@ import '../src/fakes.dart';

/// Matches a doctor validation result.
Matcher _matchDoctorValidation({
ValidationType validationType,
String statusInfo,
dynamic messages
required ValidationType validationType,
required String statusInfo,
required Object messages
}) {
return const TypeMatcher<ValidationResult>()
.having((ValidationResult result) => result.type, 'type', validationType)
Expand Down Expand Up @@ -235,7 +233,7 @@ void main() {
}

class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
FakeOperatingSystemUtils({this.name});
FakeOperatingSystemUtils({required this.name});

@override
final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart';
Expand All @@ -17,7 +15,6 @@ import 'package:flutter_tools/src/ios/devices.dart';
import 'package:flutter_tools/src/ios/ios_deploy.dart';
import 'package:flutter_tools/src/ios/iproxy.dart';
import 'package:flutter_tools/src/ios/mac.dart';
import 'package:meta/meta.dart';

import '../../src/common.dart';
import '../../src/fake_process_manager.dart';
Expand All @@ -28,10 +25,10 @@ const Map<String, String> kDyLdLibEntry = <String, String>{
};

void main() {
Artifacts artifacts;
String iosDeployPath;
FileSystem fileSystem;
Directory bundleDirectory;
late Artifacts artifacts;
late String iosDeployPath;
late FileSystem fileSystem;
late Directory bundleDirectory;

setUp(() {
artifacts = Artifacts.test();
Expand Down Expand Up @@ -319,11 +316,11 @@ void main() {
}

IOSDevice setUpIOSDevice({
@required ProcessManager processManager,
FileSystem fileSystem,
Logger logger,
IOSDeviceConnectionInterface interfaceType,
Artifacts artifacts,
required ProcessManager processManager,
FileSystem? fileSystem,
Logger? logger,
IOSDeviceConnectionInterface? interfaceType,
Artifacts? artifacts,
}) {
logger ??= BufferLogger.test();
final FakePlatform platform = FakePlatform(
Expand Down Expand Up @@ -360,6 +357,6 @@ IOSDevice setUpIOSDevice({
cache: cache,
),
iProxy: IProxy.test(logger: logger, processManager: processManager),
interfaceType: interfaceType,
interfaceType: interfaceType ?? IOSDeviceConnectionInterface.usb,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'dart:async';

import 'package:flutter_tools/src/artifacts.dart';
Expand All @@ -24,11 +22,11 @@ import '../../src/fake_process_manager.dart';
import '../../src/fake_vm_services.dart';

void main() {
FakeProcessManager processManager;
Artifacts artifacts;
Cache fakeCache;
BufferLogger logger;
String ideviceSyslogPath;
late FakeProcessManager processManager;
late Artifacts artifacts;
late Cache fakeCache;
late BufferLogger logger;
late String ideviceSyslogPath;

setUp(() {
processManager = FakeProcessManager.empty();
Expand Down Expand Up @@ -328,8 +326,8 @@ Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt
),
useSyslog: false,
);
Object exception;
StackTrace trace;
Object? exception;
StackTrace? trace;
await asyncGuard(
() async {
await logReader.linesController.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'dart:async';
import 'dart:convert';

Expand Down Expand Up @@ -66,8 +64,8 @@ const FakeCommand kLaunchDebugCommand = FakeCommand(command: <String>[

// The command used to actually launch the app and attach the debugger with args in debug.
FakeCommand attachDebuggerCommand({
IOSink stdin,
Completer<void>/*?*/ completer,
IOSink? stdin,
Completer<void>? completer,
}) {
return FakeCommand(
command: const <String>[
Expand Down Expand Up @@ -359,10 +357,10 @@ void main() {

IOSDevice setUpIOSDevice({
String sdkVersion = '13.0.1',
FileSystem fileSystem,
Logger logger,
ProcessManager processManager,
IOSDeploy iosDeploy,
FileSystem? fileSystem,
Logger? logger,
ProcessManager? processManager,
IOSDeploy? iosDeploy,
}) {
final Artifacts artifacts = Artifacts.test();
final FakePlatform macPlatform = FakePlatform(
Expand All @@ -377,24 +375,24 @@ IOSDevice setUpIOSDevice({
],
processManager: FakeProcessManager.any(),
);

logger ??= BufferLogger.test();
return IOSDevice('123',
name: 'iPhone 1',
sdkVersion: sdkVersion,
fileSystem: fileSystem ?? MemoryFileSystem.test(),
platform: macPlatform,
iProxy: IProxy.test(logger: logger, processManager: processManager ?? FakeProcessManager.any()),
logger: logger ?? BufferLogger.test(),
logger: logger,
iosDeploy: iosDeploy ??
IOSDeploy(
logger: logger ?? BufferLogger.test(),
logger: logger,
platform: macPlatform,
processManager: processManager ?? FakeProcessManager.any(),
artifacts: artifacts,
cache: cache,
),
iMobileDevice: IMobileDevice(
logger: logger ?? BufferLogger.test(),
logger: logger,
processManager: processManager ?? FakeProcessManager.any(),
artifacts: artifacts,
cache: cache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/memory.dart';
import 'package:flutter_tools/src/application_package.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/desktop_device.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/ios/application_package.dart';
import 'package:flutter_tools/src/ios/ios_workflow.dart';
import 'package:flutter_tools/src/macos/macos_ipad_device.dart';
import 'package:meta/meta.dart';
import 'package:test/fake.dart';

import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fake_process_manager.dart';
import '../../src/fakes.dart';

void main() {
Expand Down Expand Up @@ -125,25 +124,34 @@ void main() {
expect(device.portForwarder, isNot(isNull));
expect(await device.targetPlatform, TargetPlatform.darwin);

expect(await device.installApp(null), isTrue);
expect(await device.isAppInstalled(null), isTrue);
expect(await device.isLatestBuildInstalled(null), isTrue);
expect(await device.uninstallApp(null), isTrue);
expect(await device.installApp(FakeApplicationPackage()), isTrue);
expect(await device.isAppInstalled(FakeApplicationPackage()), isTrue);
expect(await device.isLatestBuildInstalled(FakeApplicationPackage()), isTrue);
expect(await device.uninstallApp(FakeApplicationPackage()), isTrue);

expect(device.isSupported(), isTrue);
expect(device.getLogReader(), isA<DesktopLogReader>());

expect(await device.stopApp(null), isFalse);
expect(await device.stopApp(FakeIOSApp()), isFalse);

await expectLater(() => device.startApp(null, debuggingOptions: null), throwsA(isA<UnimplementedError>()));
await expectLater(() => device.buildForDevice(null, buildInfo: BuildInfo.debug), throwsA(isA<UnimplementedError>()));
expect(device.executablePathForDevice(null, null), null);
await expectLater(
() => device.startApp(
FakeIOSApp(),
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
),
throwsA(isA<UnimplementedError>()),
);
await expectLater(() => device.buildForDevice(FakeIOSApp(), buildInfo: BuildInfo.debug), throwsA(isA<UnimplementedError>()));
expect(device.executablePathForDevice(FakeIOSApp(), BuildMode.debug), null);
});
}

class FakeIOSWorkflow extends Fake implements IOSWorkflow {
FakeIOSWorkflow({@required this.canListDevices});
FakeIOSWorkflow({required this.canListDevices});

@override
final bool canListDevices;
}

class FakeApplicationPackage extends Fake implements ApplicationPackage {}
class FakeIOSApp extends Fake implements IOSApp {}
Loading

0 comments on commit a56c5e5

Please sign in to comment.