Unverified Commit aa96eb29 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate intellij tests and context_test to null safety (#80008)

parent fdb16cd7
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:async'; import 'dart:async';
import 'package:flutter_tools/src/base/context.dart'; import 'package:flutter_tools/src/base/context.dart';
...@@ -13,7 +11,7 @@ import '../../src/common.dart'; ...@@ -13,7 +11,7 @@ import '../../src/common.dart';
void main() { void main() {
group('AppContext', () { group('AppContext', () {
group('global getter', () { group('global getter', () {
bool called; late bool called;
setUp(() { setUp(() {
called = false; called = false;
...@@ -78,7 +76,7 @@ void main() { ...@@ -78,7 +76,7 @@ void main() {
test('still finds values if async code runs after body has finished', () async { test('still finds values if async code runs after body has finished', () async {
final Completer<void> outer = Completer<void>(); final Completer<void> outer = Completer<void>();
final Completer<void> inner = Completer<void>(); final Completer<void> inner = Completer<void>();
String value; String? value;
await context.run<void>( await context.run<void>(
body: () { body: () {
outer.future.then<void>((_) { outer.future.then<void>((_) {
...@@ -98,10 +96,10 @@ void main() { ...@@ -98,10 +96,10 @@ void main() {
test('caches generated override values', () async { test('caches generated override values', () async {
int consultationCount = 0; int consultationCount = 0;
String value; String? value;
await context.run<void>( await context.run<void>(
body: () async { body: () async {
final StringBuffer buf = StringBuffer(context.get<String>()); final StringBuffer buf = StringBuffer(context.get<String>()!);
buf.write(context.get<String>()); buf.write(context.get<String>());
await context.run<void>(body: () { await context.run<void>(body: () {
buf.write(context.get<String>()); buf.write(context.get<String>());
...@@ -121,10 +119,10 @@ void main() { ...@@ -121,10 +119,10 @@ void main() {
test('caches generated fallback values', () async { test('caches generated fallback values', () async {
int consultationCount = 0; int consultationCount = 0;
String value; String? value;
await context.run( await context.run(
body: () async { body: () async {
final StringBuffer buf = StringBuffer(context.get<String>()); final StringBuffer buf = StringBuffer(context.get<String>()!);
buf.write(context.get<String>()); buf.write(context.get<String>());
await context.run<void>(body: () { await context.run<void>(body: () {
buf.write(context.get<String>()); buf.write(context.get<String>());
...@@ -143,7 +141,7 @@ void main() { ...@@ -143,7 +141,7 @@ void main() {
}); });
test('returns null if generated value is null', () async { test('returns null if generated value is null', () async {
final String value = await context.run<String>( final String? value = await context.run<String?>(
body: () => context.get<String>(), body: () => context.get<String>(),
overrides: <Type, Generator>{ overrides: <Type, Generator>{
String: () => null, String: () => null,
...@@ -153,14 +151,14 @@ void main() { ...@@ -153,14 +151,14 @@ void main() {
}); });
test('throws if generator has dependency cycle', () async { test('throws if generator has dependency cycle', () async {
final Future<String> value = context.run<String>( final Future<String?> value = context.run<String?>(
body: () async { body: () async {
return context.get<String>(); return context.get<String>();
}, },
fallbacks: <Type, Generator>{ fallbacks: <Type, Generator>{
int: () => int.parse(context.get<String>()), int: () => int.parse(context.get<String>() ?? ''),
String: () => '${context.get<double>()}', String: () => '${context.get<double>()}',
double: () => context.get<int>() * 1.0, double: () => context.get<int>()! * 1.0,
}, },
); );
try { try {
...@@ -187,16 +185,16 @@ void main() { ...@@ -187,16 +185,16 @@ void main() {
}); });
group('fallbacks', () { group('fallbacks', () {
bool called; late bool called;
setUp(() { setUp(() {
called = false; called = false;
}); });
test('are applied after parent context is consulted', () async { test('are applied after parent context is consulted', () async {
final String value = await context.run<String>( final String? value = await context.run<String?>(
body: () { body: () {
return context.run<String>( return context.run<String?>(
body: () { body: () {
called = true; called = true;
return context.get<String>(); return context.get<String>();
...@@ -213,9 +211,9 @@ void main() { ...@@ -213,9 +211,9 @@ void main() {
test('are not applied if parent context supplies value', () async { test('are not applied if parent context supplies value', () async {
bool childConsulted = false; bool childConsulted = false;
final String value = await context.run<String>( final String? value = await context.run<String?>(
body: () { body: () {
return context.run<String>( return context.run<String?>(
body: () { body: () {
called = true; called = true;
return context.get<String>(); return context.get<String>();
...@@ -238,7 +236,7 @@ void main() { ...@@ -238,7 +236,7 @@ void main() {
}); });
test('may depend on one another', () async { test('may depend on one another', () async {
final String value = await context.run<String>( final String? value = await context.run<String?>(
body: () { body: () {
return context.get<String>(); return context.get<String>();
}, },
...@@ -254,9 +252,9 @@ void main() { ...@@ -254,9 +252,9 @@ void main() {
group('overrides', () { group('overrides', () {
test('intercept consultation of parent context', () async { test('intercept consultation of parent context', () async {
bool parentConsulted = false; bool parentConsulted = false;
final String value = await context.run<String>( final String? value = await context.run<String?>(
body: () { body: () {
return context.run<String>( return context.run<String?>(
body: () => context.get<String>(), body: () => context.get<String>(),
overrides: <Type, Generator>{ overrides: <Type, Generator>{
String: () => 'child', String: () => 'child',
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:convert'; import 'dart:convert';
import 'package:archive/archive.dart'; import 'package:archive/archive.dart';
...@@ -16,7 +14,7 @@ import 'package:flutter_tools/src/intellij/intellij.dart'; ...@@ -16,7 +14,7 @@ import 'package:flutter_tools/src/intellij/intellij.dart';
import '../../src/common.dart'; import '../../src/common.dart';
void main() { void main() {
FileSystem fileSystem; late FileSystem fileSystem;
void writeFileCreatingDirectories(String path, List<int> bytes) { void writeFileCreatingDirectories(String path, List<int> bytes) {
final File file = fileSystem.file(path); final File file = fileSystem.file(path);
...@@ -40,7 +38,7 @@ void main() { ...@@ -40,7 +38,7 @@ void main() {
'''); ''');
writeFileCreatingDirectories( writeFileCreatingDirectories(
fileSystem.path.join(_kPluginsPath, 'Dart', 'lib', 'Dart.jar'), fileSystem.path.join(_kPluginsPath, 'Dart', 'lib', 'Dart.jar'),
ZipEncoder().encode(dartJarArchive), ZipEncoder().encode(dartJarArchive)!,
); );
final Archive flutterJarArchive = buildSingleFileArchive('META-INF/plugin.xml', r''' final Archive flutterJarArchive = buildSingleFileArchive('META-INF/plugin.xml', r'''
...@@ -51,7 +49,7 @@ void main() { ...@@ -51,7 +49,7 @@ void main() {
'''); ''');
writeFileCreatingDirectories( writeFileCreatingDirectories(
fileSystem.path.join(_kPluginsPath, 'flutter-intellij.jar'), fileSystem.path.join(_kPluginsPath, 'flutter-intellij.jar'),
ZipEncoder().encode(flutterJarArchive), ZipEncoder().encode(flutterJarArchive)!,
); );
final List<ValidationMessage> messages = <ValidationMessage>[]; final List<ValidationMessage> messages = <ValidationMessage>[];
...@@ -82,14 +80,14 @@ void main() { ...@@ -82,14 +80,14 @@ void main() {
'''); ''');
writeFileCreatingDirectories( writeFileCreatingDirectories(
fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-idea-50.0.jar'), 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''' final Archive flutterIntellijJarArchive = buildSingleFileArchive('META-INF/MANIFEST.MF', r'''
Manifest-Version: 1.0 Manifest-Version: 1.0
'''); ''');
writeFileCreatingDirectories( writeFileCreatingDirectories(
fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-intellij-50.0.jar'), fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-intellij-50.0.jar'),
ZipEncoder().encode(flutterIntellijJarArchive), ZipEncoder().encode(flutterIntellijJarArchive)!,
); );
final List<ValidationMessage> messages = <ValidationMessage>[]; final List<ValidationMessage> messages = <ValidationMessage>[];
...@@ -118,7 +116,7 @@ Manifest-Version: 1.0 ...@@ -118,7 +116,7 @@ Manifest-Version: 1.0
'''); ''');
writeFileCreatingDirectories( writeFileCreatingDirectories(
fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-idea-50.0.jar'), 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''' final Archive flutterIntellijJarArchive = buildSingleFileArchive('META-INF/plugin.xml', r'''
<idea-plugin version="2"> <idea-plugin version="2">
...@@ -128,7 +126,7 @@ Manifest-Version: 1.0 ...@@ -128,7 +126,7 @@ Manifest-Version: 1.0
'''); ''');
writeFileCreatingDirectories( writeFileCreatingDirectories(
fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-intellij-50.0.jar'), fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-intellij-50.0.jar'),
ZipEncoder().encode(flutterIntellijJarArchive), ZipEncoder().encode(flutterIntellijJarArchive)!,
); );
final List<ValidationMessage> messages = <ValidationMessage>[]; final List<ValidationMessage> messages = <ValidationMessage>[];
...@@ -176,7 +174,7 @@ Manifest-Version: 1.0 ...@@ -176,7 +174,7 @@ Manifest-Version: 1.0
'''); ''');
writeFileCreatingDirectories( writeFileCreatingDirectories(
fileSystem.path.join(_kPluginsPath, 'Dart', 'lib', 'Other.jar'), fileSystem.path.join(_kPluginsPath, 'Dart', 'lib', 'Other.jar'),
ZipEncoder().encode(dartJarArchive), ZipEncoder().encode(dartJarArchive)!,
); );
expect( expect(
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:archive/archive.dart'; import 'package:archive/archive.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
...@@ -332,7 +330,7 @@ class FakePlistParser extends Fake implements PlistParser { ...@@ -332,7 +330,7 @@ class FakePlistParser extends Fake implements PlistParser {
final Map<String, String> values; final Map<String, String> values;
@override @override
String getValueFromFile(String plistFilePath, String key) { String? getValueFromFile(String plistFilePath, String key) {
return values[key]; return values[key];
} }
} }
...@@ -379,7 +377,7 @@ void createIntellijFlutterPluginJar(String pluginJarPath, FileSystem fileSystem, ...@@ -379,7 +377,7 @@ void createIntellijFlutterPluginJar(String pluginJarPath, FileSystem fileSystem,
flutterPlugins.addFile(ArchiveFile('META-INF/plugin.xml', flutterPluginBytes.length, flutterPluginBytes)); flutterPlugins.addFile(ArchiveFile('META-INF/plugin.xml', flutterPluginBytes.length, flutterPluginBytes));
fileSystem.file(pluginJarPath) fileSystem.file(pluginJarPath)
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsBytesSync(ZipEncoder().encode(flutterPlugins)); ..writeAsBytesSync(ZipEncoder().encode(flutterPlugins)!);
} }
...@@ -416,5 +414,5 @@ void createIntellijDartPluginJar(String pluginJarPath, FileSystem fileSystem) { ...@@ -416,5 +414,5 @@ void createIntellijDartPluginJar(String pluginJarPath, FileSystem fileSystem) {
dartPlugins.addFile(ArchiveFile('META-INF/plugin.xml', dartPluginBytes.length, dartPluginBytes)); dartPlugins.addFile(ArchiveFile('META-INF/plugin.xml', dartPluginBytes.length, dartPluginBytes));
fileSystem.file(pluginJarPath) fileSystem.file(pluginJarPath)
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsBytesSync(ZipEncoder().encode(dartPlugins)); ..writeAsBytesSync(ZipEncoder().encode(dartPlugins)!);
} }
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