Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit eea17c9

Browse files
authored
Migrate these tests to the "new" API. (#7189)
1 parent 48f50b4 commit eea17c9

File tree

47 files changed

+658
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+658
-172
lines changed

packages/camera/camera_android/test/method_channel_mock.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class MethodChannelMock {
1111
this.delay,
1212
required this.methods,
1313
}) : methodChannel = MethodChannel(channelName) {
14-
methodChannel.setMockMethodCallHandler(_handler);
14+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
15+
.defaultBinaryMessenger
16+
.setMockMethodCallHandler(methodChannel, _handler);
1517
}
1618

1719
final Duration? delay;
@@ -37,3 +39,9 @@ class MethodChannelMock {
3739
});
3840
}
3941
}
42+
43+
/// This allows a value of type T or T? to be treated as a value of type T?.
44+
///
45+
/// We use this so that APIs that have become non-nullable can still be used
46+
/// with `!` and `?` on the stable branch.
47+
T? _ambiguate<T>(T? value) => value;

packages/camera/camera_avfoundation/test/method_channel_mock.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class MethodChannelMock {
1111
this.delay,
1212
required this.methods,
1313
}) : methodChannel = MethodChannel(channelName) {
14-
methodChannel.setMockMethodCallHandler(_handler);
14+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
15+
.defaultBinaryMessenger
16+
.setMockMethodCallHandler(methodChannel, _handler);
1517
}
1618

1719
final Duration? delay;
@@ -37,3 +39,9 @@ class MethodChannelMock {
3739
});
3840
}
3941
}
42+
43+
/// This allows a value of type T or T? to be treated as a value of type T?.
44+
///
45+
/// We use this so that APIs that have become non-nullable can still be used
46+
/// with `!` and `?` on the stable branch.
47+
T? _ambiguate<T>(T? value) => value;

packages/camera/camera_platform_interface/test/utils/method_channel_mock.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class MethodChannelMock {
1111
this.delay,
1212
required this.methods,
1313
}) : methodChannel = MethodChannel(channelName) {
14-
methodChannel.setMockMethodCallHandler(_handler);
14+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
15+
.defaultBinaryMessenger
16+
.setMockMethodCallHandler(methodChannel, _handler);
1517
}
1618

1719
final Duration? delay;
@@ -37,3 +39,9 @@ class MethodChannelMock {
3739
});
3840
}
3941
}
42+
43+
/// This allows a value of type T or T? to be treated as a value of type T?.
44+
///
45+
/// We use this so that APIs that have become non-nullable can still be used
46+
/// with `!` and `?` on the stable branch.
47+
T? _ambiguate<T>(T? value) => value;

packages/camera/camera_windows/test/utils/method_channel_mock.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class MethodChannelMock {
1717
this.delay,
1818
required this.methods,
1919
}) : methodChannel = MethodChannel(channelName) {
20-
methodChannel.setMockMethodCallHandler(_handler);
20+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
21+
.defaultBinaryMessenger
22+
.setMockMethodCallHandler(methodChannel, _handler);
2123
}
2224

2325
final Duration? delay;
@@ -43,3 +45,9 @@ class MethodChannelMock {
4345
});
4446
}
4547
}
48+
49+
/// This allows a value of type T or T? to be treated as a value of type T?.
50+
///
51+
/// We use this so that APIs that have become non-nullable can still be used
52+
/// with `!` and `?` on the stable branch.
53+
T? _ambiguate<T>(T? value) => value;

packages/file_selector/file_selector_linux/test/file_selector_linux_test.dart

+15-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ void main() {
1616
setUp(() {
1717
plugin = FileSelectorLinux();
1818
log = <MethodCall>[];
19-
plugin.channel.setMockMethodCallHandler((MethodCall methodCall) async {
20-
log.add(methodCall);
21-
return null;
22-
});
19+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
20+
.defaultBinaryMessenger
21+
.setMockMethodCallHandler(
22+
plugin.channel,
23+
(MethodCall methodCall) async {
24+
log.add(methodCall);
25+
return null;
26+
},
27+
);
2328
});
2429

2530
test('registers instance', () {
@@ -424,3 +429,9 @@ void expectMethodCall(
424429
}) {
425430
expect(log, <Matcher>[isMethodCall(methodName, arguments: arguments)]);
426431
}
432+
433+
/// This allows a value of type T or T? to be treated as a value of type T?.
434+
///
435+
/// We use this so that APIs that have become non-nullable can still be used
436+
/// with `!` and `?` on the stable branch.
437+
T? _ambiguate<T>(T? value) => value;

packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart

+15-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ void main() {
1616
final List<MethodCall> log = <MethodCall>[];
1717

1818
setUp(() {
19-
plugin.channel.setMockMethodCallHandler((MethodCall methodCall) async {
20-
log.add(methodCall);
21-
return null;
22-
});
19+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
20+
.defaultBinaryMessenger
21+
.setMockMethodCallHandler(
22+
plugin.channel,
23+
(MethodCall methodCall) async {
24+
log.add(methodCall);
25+
return null;
26+
},
27+
);
2328

2429
log.clear();
2530
});
@@ -274,3 +279,9 @@ void expectMethodCall(
274279
}) {
275280
expect(log, <Matcher>[isMethodCall(methodName, arguments: arguments)]);
276281
}
282+
283+
/// This allows a value of type T or T? to be treated as a value of type T?.
284+
///
285+
/// We use this so that APIs that have become non-nullable can still be used
286+
/// with `!` and `?` on the stable branch.
287+
T? _ambiguate<T>(T? value) => value;

packages/google_maps_flutter/google_maps_flutter/test/circle_updates_test.dart

+12-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ void main() {
2626
FakePlatformViewsController();
2727

2828
setUpAll(() {
29-
SystemChannels.platform_views.setMockMethodCallHandler(
30-
fakePlatformViewsController.fakePlatformViewsMethodHandler);
29+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
30+
.defaultBinaryMessenger
31+
.setMockMethodCallHandler(
32+
SystemChannels.platform_views,
33+
fakePlatformViewsController.fakePlatformViewsMethodHandler,
34+
);
3135
});
3236

3337
setUp(() {
@@ -194,3 +198,9 @@ void main() {
194198
expect(platformGoogleMap.circlesToAdd.isEmpty, true);
195199
});
196200
}
201+
202+
/// This allows a value of type T or T? to be treated as a value of type T?.
203+
///
204+
/// We use this so that APIs that have become non-nullable can still be used
205+
/// with `!` and `?` on the stable branch.
206+
T? _ambiguate<T>(T? value) => value;

packages/google_maps_flutter/google_maps_flutter/test/fake_maps_controllers.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class FakePlatformGoogleMap {
1313
: cameraPosition =
1414
CameraPosition.fromMap(params['initialCameraPosition']),
1515
channel = MethodChannel('plugins.flutter.io/google_maps_$id') {
16-
channel.setMockMethodCallHandler(onMethodCall);
16+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
17+
.defaultBinaryMessenger
18+
.setMockMethodCallHandler(channel, onMethodCall);
1719
updateOptions(params['options'] as Map<dynamic, dynamic>);
1820
updateMarkers(params);
1921
updatePolygons(params);
@@ -478,3 +480,9 @@ Map<dynamic, dynamic>? _decodeParams(Uint8List paramsMessage) {
478480
return const StandardMessageCodec().decodeMessage(messageBytes)
479481
as Map<dynamic, dynamic>?;
480482
}
483+
484+
/// This allows a value of type T or T? to be treated as a value of type T?.
485+
///
486+
/// We use this so that APIs that have become non-nullable can still be used
487+
/// with `!` and `?` on the stable branch.
488+
T? _ambiguate<T>(T? value) => value;

packages/google_maps_flutter/google_maps_flutter/test/google_map_test.dart

+12-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ void main() {
1616
FakePlatformViewsController();
1717

1818
setUpAll(() {
19-
SystemChannels.platform_views.setMockMethodCallHandler(
20-
fakePlatformViewsController.fakePlatformViewsMethodHandler);
19+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
20+
.defaultBinaryMessenger
21+
.setMockMethodCallHandler(
22+
SystemChannels.platform_views,
23+
fakePlatformViewsController.fakePlatformViewsMethodHandler,
24+
);
2125
});
2226

2327
setUp(() {
@@ -576,3 +580,9 @@ void main() {
576580
expect(platformGoogleMap.buildingsEnabled, true);
577581
});
578582
}
583+
584+
/// This allows a value of type T or T? to be treated as a value of type T?.
585+
///
586+
/// We use this so that APIs that have become non-nullable can still be used
587+
/// with `!` and `?` on the stable branch.
588+
T? _ambiguate<T>(T? value) => value;

packages/google_maps_flutter/google_maps_flutter/test/marker_updates_test.dart

+12-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ void main() {
2626
FakePlatformViewsController();
2727

2828
setUpAll(() {
29-
SystemChannels.platform_views.setMockMethodCallHandler(
30-
fakePlatformViewsController.fakePlatformViewsMethodHandler);
29+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
30+
.defaultBinaryMessenger
31+
.setMockMethodCallHandler(
32+
SystemChannels.platform_views,
33+
fakePlatformViewsController.fakePlatformViewsMethodHandler,
34+
);
3135
});
3236

3337
setUp(() {
@@ -200,3 +204,9 @@ void main() {
200204
expect(platformGoogleMap.markersToAdd.isEmpty, true);
201205
});
202206
}
207+
208+
/// This allows a value of type T or T? to be treated as a value of type T?.
209+
///
210+
/// We use this so that APIs that have become non-nullable can still be used
211+
/// with `!` and `?` on the stable branch.
212+
T? _ambiguate<T>(T? value) => value;

packages/google_maps_flutter/google_maps_flutter/test/polygon_updates_test.dart

+12-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ void main() {
4949
FakePlatformViewsController();
5050

5151
setUpAll(() {
52-
SystemChannels.platform_views.setMockMethodCallHandler(
53-
fakePlatformViewsController.fakePlatformViewsMethodHandler);
52+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
53+
.defaultBinaryMessenger
54+
.setMockMethodCallHandler(
55+
SystemChannels.platform_views,
56+
fakePlatformViewsController.fakePlatformViewsMethodHandler,
57+
);
5458
});
5559

5660
setUp(() {
@@ -403,3 +407,9 @@ void main() {
403407
expect(platformGoogleMap.polygonsToAdd.isEmpty, true);
404408
});
405409
}
410+
411+
/// This allows a value of type T or T? to be treated as a value of type T?.
412+
///
413+
/// We use this so that APIs that have become non-nullable can still be used
414+
/// with `!` and `?` on the stable branch.
415+
T? _ambiguate<T>(T? value) => value;

packages/google_maps_flutter/google_maps_flutter/test/polyline_updates_test.dart

+12-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ void main() {
2626
FakePlatformViewsController();
2727

2828
setUpAll(() {
29-
SystemChannels.platform_views.setMockMethodCallHandler(
30-
fakePlatformViewsController.fakePlatformViewsMethodHandler);
29+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
30+
.defaultBinaryMessenger
31+
.setMockMethodCallHandler(
32+
SystemChannels.platform_views,
33+
fakePlatformViewsController.fakePlatformViewsMethodHandler,
34+
);
3135
});
3236

3337
setUp(() {
@@ -216,3 +220,9 @@ void main() {
216220
expect(platformGoogleMap.polylinesToAdd.isEmpty, true);
217221
});
218222
}
223+
224+
/// This allows a value of type T or T? to be treated as a value of type T?.
225+
///
226+
/// We use this so that APIs that have become non-nullable can still be used
227+
/// with `!` and `?` on the stable branch.
228+
T? _ambiguate<T>(T? value) => value;

packages/google_maps_flutter/google_maps_flutter/test/tile_overlay_updates_test.dart

+12-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ void main() {
2424
FakePlatformViewsController();
2525

2626
setUpAll(() {
27-
SystemChannels.platform_views.setMockMethodCallHandler(
28-
fakePlatformViewsController.fakePlatformViewsMethodHandler);
27+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
28+
.defaultBinaryMessenger
29+
.setMockMethodCallHandler(
30+
SystemChannels.platform_views,
31+
fakePlatformViewsController.fakePlatformViewsMethodHandler,
32+
);
2933
});
3034

3135
setUp(() {
@@ -198,3 +202,9 @@ void main() {
198202
expect(platformGoogleMap.tileOverlaysToAdd.isEmpty, true);
199203
});
200204
}
205+
206+
/// This allows a value of type T or T? to be treated as a value of type T?.
207+
///
208+
/// We use this so that APIs that have become non-nullable can still be used
209+
/// with `!` and `?` on the stable branch.
210+
T? _ambiguate<T>(T? value) => value;

packages/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart

+10-6
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ void main() {
2525
required int mapId,
2626
required Future<dynamic>? Function(MethodCall call) handler,
2727
}) {
28-
maps
29-
.ensureChannelInitialized(mapId)
30-
.setMockMethodCallHandler((MethodCall methodCall) {
31-
log.add(methodCall.method);
32-
return handler(methodCall);
33-
});
28+
final MethodChannel channel = maps.ensureChannelInitialized(mapId);
29+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
30+
.defaultBinaryMessenger
31+
.setMockMethodCallHandler(
32+
channel,
33+
(MethodCall methodCall) {
34+
log.add(methodCall.method);
35+
return handler(methodCall);
36+
},
37+
);
3438
}
3539

3640
Future<void> sendPlatformMessage(

packages/google_maps_flutter/google_maps_flutter_ios/test/google_maps_flutter_ios_test.dart

+10-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ void main() {
2424
required int mapId,
2525
required Future<dynamic>? Function(MethodCall call) handler,
2626
}) {
27-
maps
28-
.ensureChannelInitialized(mapId)
29-
.setMockMethodCallHandler((MethodCall methodCall) {
30-
log.add(methodCall.method);
31-
return handler(methodCall);
32-
});
27+
final MethodChannel channel = maps.ensureChannelInitialized(mapId);
28+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
29+
.defaultBinaryMessenger
30+
.setMockMethodCallHandler(
31+
channel,
32+
(MethodCall methodCall) {
33+
log.add(methodCall.method);
34+
return handler(methodCall);
35+
},
36+
);
3337
}
3438

3539
Future<void> sendPlatformMessage(

packages/google_maps_flutter/google_maps_flutter_platform_interface/test/method_channel/method_channel_google_maps_flutter_test.dart

+10-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ void main() {
2424
required int mapId,
2525
required Future<dynamic>? Function(MethodCall call) handler,
2626
}) {
27-
maps
28-
.ensureChannelInitialized(mapId)
29-
.setMockMethodCallHandler((MethodCall methodCall) {
30-
log.add(methodCall.method);
31-
return handler(methodCall);
32-
});
27+
final MethodChannel channel = maps.ensureChannelInitialized(mapId);
28+
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
29+
.defaultBinaryMessenger
30+
.setMockMethodCallHandler(
31+
channel,
32+
(MethodCall methodCall) {
33+
log.add(methodCall.method);
34+
return handler(methodCall);
35+
},
36+
);
3337
}
3438

3539
Future<void> sendPlatformMessage(

0 commit comments

Comments
 (0)