From aa96eb299a28209e97b198786fe1130d4e8d765b Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Thu, 8 Apr 2021 15:18:40 -0700 Subject: [PATCH] Migrate intellij tests and context_test to null safety (#80008) --- .../test/general.shard/base/context_test.dart | 38 +++++++++---------- .../general.shard/intellij/intellij_test.dart | 18 ++++----- .../intellij/intellij_validator_test.dart | 8 ++-- 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/packages/flutter_tools/test/general.shard/base/context_test.dart b/packages/flutter_tools/test/general.shard/base/context_test.dart index 2534e8f7e6..1aebfce76b 100644 --- a/packages/flutter_tools/test/general.shard/base/context_test.dart +++ b/packages/flutter_tools/test/general.shard/base/context_test.dart @@ -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/base/context.dart'; @@ -13,7 +11,7 @@ import '../../src/common.dart'; void main() { group('AppContext', () { group('global getter', () { - bool called; + late bool called; setUp(() { called = false; @@ -78,7 +76,7 @@ void main() { test('still finds values if async code runs after body has finished', () async { final Completer outer = Completer(); final Completer inner = Completer(); - String value; + String? value; await context.run( body: () { outer.future.then((_) { @@ -98,10 +96,10 @@ void main() { test('caches generated override values', () async { int consultationCount = 0; - String value; + String? value; await context.run( body: () async { - final StringBuffer buf = StringBuffer(context.get()); + final StringBuffer buf = StringBuffer(context.get()!); buf.write(context.get()); await context.run(body: () { buf.write(context.get()); @@ -121,10 +119,10 @@ void main() { test('caches generated fallback values', () async { int consultationCount = 0; - String value; + String? value; await context.run( body: () async { - final StringBuffer buf = StringBuffer(context.get()); + final StringBuffer buf = StringBuffer(context.get()!); buf.write(context.get()); await context.run(body: () { buf.write(context.get()); @@ -143,7 +141,7 @@ void main() { }); test('returns null if generated value is null', () async { - final String value = await context.run( + final String? value = await context.run( body: () => context.get(), overrides: { String: () => null, @@ -153,14 +151,14 @@ void main() { }); test('throws if generator has dependency cycle', () async { - final Future value = context.run( + final Future value = context.run( body: () async { return context.get(); }, fallbacks: { - int: () => int.parse(context.get()), + int: () => int.parse(context.get() ?? ''), String: () => '${context.get()}', - double: () => context.get() * 1.0, + double: () => context.get()! * 1.0, }, ); try { @@ -187,16 +185,16 @@ void main() { }); group('fallbacks', () { - bool called; + late bool called; setUp(() { called = false; }); test('are applied after parent context is consulted', () async { - final String value = await context.run( + final String? value = await context.run( body: () { - return context.run( + return context.run( body: () { called = true; return context.get(); @@ -213,9 +211,9 @@ void main() { test('are not applied if parent context supplies value', () async { bool childConsulted = false; - final String value = await context.run( + final String? value = await context.run( body: () { - return context.run( + return context.run( body: () { called = true; return context.get(); @@ -238,7 +236,7 @@ void main() { }); test('may depend on one another', () async { - final String value = await context.run( + final String? value = await context.run( body: () { return context.get(); }, @@ -254,9 +252,9 @@ void main() { group('overrides', () { test('intercept consultation of parent context', () async { bool parentConsulted = false; - final String value = await context.run( + final String? value = await context.run( body: () { - return context.run( + return context.run( body: () => context.get(), overrides: { String: () => 'child', diff --git a/packages/flutter_tools/test/general.shard/intellij/intellij_test.dart b/packages/flutter_tools/test/general.shard/intellij/intellij_test.dart index 2a12b84ba6..6644fe5d57 100644 --- a/packages/flutter_tools/test/general.shard/intellij/intellij_test.dart +++ b/packages/flutter_tools/test/general.shard/intellij/intellij_test.dart @@ -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:convert'; import 'package:archive/archive.dart'; @@ -16,7 +14,7 @@ import 'package:flutter_tools/src/intellij/intellij.dart'; import '../../src/common.dart'; void main() { - FileSystem fileSystem; + late FileSystem fileSystem; void writeFileCreatingDirectories(String path, List bytes) { final File file = fileSystem.file(path); @@ -40,7 +38,7 @@ void main() { '''); writeFileCreatingDirectories( fileSystem.path.join(_kPluginsPath, 'Dart', 'lib', 'Dart.jar'), - ZipEncoder().encode(dartJarArchive), + ZipEncoder().encode(dartJarArchive)!, ); final Archive flutterJarArchive = buildSingleFileArchive('META-INF/plugin.xml', r''' @@ -51,7 +49,7 @@ void main() { '''); writeFileCreatingDirectories( fileSystem.path.join(_kPluginsPath, 'flutter-intellij.jar'), - ZipEncoder().encode(flutterJarArchive), + ZipEncoder().encode(flutterJarArchive)!, ); final List messages = []; @@ -82,14 +80,14 @@ void main() { '''); writeFileCreatingDirectories( fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-idea-50.0.jar'), - ZipEncoder().encode(flutterIdeaJarArchive), + ZipEncoder().encode(flutterIdeaJarArchive)!, ); final Archive flutterIntellijJarArchive = buildSingleFileArchive('META-INF/MANIFEST.MF', r''' Manifest-Version: 1.0 '''); writeFileCreatingDirectories( fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-intellij-50.0.jar'), - ZipEncoder().encode(flutterIntellijJarArchive), + ZipEncoder().encode(flutterIntellijJarArchive)!, ); final List messages = []; @@ -118,7 +116,7 @@ Manifest-Version: 1.0 '''); writeFileCreatingDirectories( fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-idea-50.0.jar'), - ZipEncoder().encode(flutterIdeaJarArchive), + ZipEncoder().encode(flutterIdeaJarArchive)!, ); final Archive flutterIntellijJarArchive = buildSingleFileArchive('META-INF/plugin.xml', r''' @@ -128,7 +126,7 @@ Manifest-Version: 1.0 '''); writeFileCreatingDirectories( fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-intellij-50.0.jar'), - ZipEncoder().encode(flutterIntellijJarArchive), + ZipEncoder().encode(flutterIntellijJarArchive)!, ); final List messages = []; @@ -176,7 +174,7 @@ Manifest-Version: 1.0 '''); writeFileCreatingDirectories( fileSystem.path.join(_kPluginsPath, 'Dart', 'lib', 'Other.jar'), - ZipEncoder().encode(dartJarArchive), + ZipEncoder().encode(dartJarArchive)!, ); expect( diff --git a/packages/flutter_tools/test/general.shard/intellij/intellij_validator_test.dart b/packages/flutter_tools/test/general.shard/intellij/intellij_validator_test.dart index 0585e9fbfa..4b71fef438 100644 --- a/packages/flutter_tools/test/general.shard/intellij/intellij_validator_test.dart +++ b/packages/flutter_tools/test/general.shard/intellij/intellij_validator_test.dart @@ -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:archive/archive.dart'; import 'package:file/memory.dart'; import 'package:flutter_tools/src/base/file_system.dart'; @@ -332,7 +330,7 @@ class FakePlistParser extends Fake implements PlistParser { final Map values; @override - String getValueFromFile(String plistFilePath, String key) { + String? getValueFromFile(String plistFilePath, String key) { return values[key]; } } @@ -379,7 +377,7 @@ void createIntellijFlutterPluginJar(String pluginJarPath, FileSystem fileSystem, flutterPlugins.addFile(ArchiveFile('META-INF/plugin.xml', flutterPluginBytes.length, flutterPluginBytes)); fileSystem.file(pluginJarPath) ..createSync(recursive: true) - ..writeAsBytesSync(ZipEncoder().encode(flutterPlugins)); + ..writeAsBytesSync(ZipEncoder().encode(flutterPlugins)!); } @@ -416,5 +414,5 @@ void createIntellijDartPluginJar(String pluginJarPath, FileSystem fileSystem) { dartPlugins.addFile(ArchiveFile('META-INF/plugin.xml', dartPluginBytes.length, dartPluginBytes)); fileSystem.file(pluginJarPath) ..createSync(recursive: true) - ..writeAsBytesSync(ZipEncoder().encode(dartPlugins)); + ..writeAsBytesSync(ZipEncoder().encode(dartPlugins)!); }