Skip to content

Commit

Permalink
[various] Disambiguate TestDefaultBinaryMessengerBinding (#6009)
Browse files Browse the repository at this point in the history
Removes the "ambiguate" method that was used to allow compatibility with both stable and master during the transition of `TestDefaultBinaryMessengerBinding.instance` from a nullable return to a non-nullable return, now that all versions we analyze are sufficiently new to have the non-nullable version.

Part of flutter/flutter#111841
  • Loading branch information
stuartmorgan committed Jan 29, 2024
1 parent 7c95a32 commit e08e149
Show file tree
Hide file tree
Showing 30 changed files with 100 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ void main() {
// registerWith is called very early in initialization the bindings won't
// have been initialized. While registerWith could initialize them, that
// could slow down startup, so instead the handler should be set up lazily.
final ByteData? response =
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
.handlePlatformMessage(
AVFoundationCamera.deviceEventChannelName,
const StandardMethodCodec().encodeMethodCall(const MethodCall(
'orientation_changed',
<String, Object>{'orientation': 'portraitDown'})),
(ByteData? data) {});
final ByteData? response = await TestDefaultBinaryMessengerBinding
.instance.defaultBinaryMessenger
.handlePlatformMessage(
AVFoundationCamera.deviceEventChannelName,
const StandardMethodCodec().encodeMethodCall(const MethodCall(
'orientation_changed',
<String, Object>{'orientation': 'portraitDown'})),
(ByteData? data) {});
expect(response, null);
});

Expand Down Expand Up @@ -422,8 +421,7 @@ void main() {
const DeviceOrientationChangedEvent event =
DeviceOrientationChangedEvent(DeviceOrientation.portraitUp);
for (int i = 0; i < 3; i++) {
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.handlePlatformMessage(
AVFoundationCamera.deviceEventChannelName,
const StandardMethodCodec().encodeMethodCall(
Expand Down Expand Up @@ -1187,9 +1185,3 @@ void main() {
});
});
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
T? _ambiguate<T>(T? value) => value;
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class MethodChannelMock {
this.delay,
required this.methods,
}) : methodChannel = MethodChannel(channelName) {
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(methodChannel, _handler);
}

Expand All @@ -39,9 +38,3 @@ class MethodChannelMock {
});
}
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
T? _ambiguate<T>(T? value) => value;
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class MethodChannelMock {
this.delay,
required this.methods,
}) : methodChannel = MethodChannel(channelName) {
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(methodChannel, _handler);
}

Expand All @@ -39,9 +38,3 @@ class MethodChannelMock {
});
}
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
T? _ambiguate<T>(T? value) => value;
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class MethodChannelMock {
this.delay,
required this.methods,
}) : methodChannel = MethodChannel(channelName) {
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(methodChannel, _handler);
}

Expand All @@ -45,9 +44,3 @@ class MethodChannelMock {
});
}
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
T? _ambiguate<T>(T? value) => value;
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ void main() {
setUp(() {
plugin = FileSelectorLinux();
log = <MethodCall>[];
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
plugin.channel,
(MethodCall methodCall) async {
Expand Down Expand Up @@ -527,9 +526,3 @@ void expectMethodCall(
}) {
expect(log, <Matcher>[isMethodCall(methodName, arguments: arguments)]);
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
T? _ambiguate<T>(T? value) => value;
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ void main() {
final List<MethodCall> log = <MethodCall>[];

setUp(() {
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
plugin.channel,
(MethodCall methodCall) async {
Expand Down Expand Up @@ -279,9 +278,3 @@ void expectMethodCall(
}) {
expect(log, <Matcher>[isMethodCall(methodName, arguments: arguments)]);
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
T? _ambiguate<T>(T? value) => value;
21 changes: 5 additions & 16 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,7 @@ void main() {
'Handles the Android back button when parentNavigatorKey is set to the root navigator',
(WidgetTester tester) async {
final List<MethodCall> log = <MethodCall>[];
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform,
(MethodCall methodCall) async {
log.add(methodCall);
Expand Down Expand Up @@ -817,8 +816,7 @@ void main() {
testWidgets("Handles the Android back button when ShellRoute can't pop",
(WidgetTester tester) async {
final List<MethodCall> log = <MethodCall>[];
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform,
(MethodCall methodCall) async {
log.add(methodCall);
Expand Down Expand Up @@ -917,8 +915,7 @@ void main() {
'Handles the Android back button when a second Shell has a GoRoute with parentNavigator key',
(WidgetTester tester) async {
final List<MethodCall> log = <MethodCall>[];
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform,
(MethodCall methodCall) async {
log.add(methodCall);
Expand Down Expand Up @@ -1008,8 +1005,7 @@ void main() {
final List<MethodCall> log = <MethodCall>[];
setUp(() {
GoRouter.optionURLReflectsImperativeAPIs = false;
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.navigation,
(MethodCall methodCall) async {
log.add(methodCall);
Expand All @@ -1018,8 +1014,7 @@ void main() {
});
tearDown(() {
GoRouter.optionURLReflectsImperativeAPIs = false;
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.navigation, null);
log.clear();
});
Expand Down Expand Up @@ -5158,9 +5153,3 @@ class IsRouteUpdateCall extends Matcher {
.addDescriptionOf(replace);
}
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
T? _ambiguate<T>(T? value) => value;
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ void main() {
required Future<dynamic>? Function(MethodCall call) handler,
}) {
final MethodChannel channel = maps.ensureChannelInitialized(mapId);
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
channel,
(MethodCall methodCall) {
Expand All @@ -42,8 +41,7 @@ void main() {
int mapId, String method, Map<dynamic, dynamic> data) async {
final ByteData byteData =
const StandardMethodCodec().encodeMethodCall(MethodCall(method, data));
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.handlePlatformMessage('plugins.flutter.dev/google_maps_android_$mapId',
byteData, (ByteData? data) {});
}
Expand Down Expand Up @@ -218,9 +216,3 @@ void main() {
);
});
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
T? _ambiguate<T>(T? value) => value;
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ void main() {
required Future<dynamic>? Function(MethodCall call) handler,
}) {
final MethodChannel channel = maps.ensureChannelInitialized(mapId);
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
channel,
(MethodCall methodCall) {
Expand All @@ -42,8 +41,7 @@ void main() {
int mapId, String method, Map<dynamic, dynamic> data) async {
final ByteData byteData =
const StandardMethodCodec().encodeMethodCall(MethodCall(method, data));
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.handlePlatformMessage('plugins.flutter.dev/google_maps_ios_$mapId',
byteData, (ByteData? data) {});
}
Expand Down Expand Up @@ -179,9 +177,3 @@ void main() {
);
});
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
T? _ambiguate<T>(T? value) => value;
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ void main() {
required Future<dynamic>? Function(MethodCall call) handler,
}) {
final MethodChannel channel = maps.ensureChannelInitialized(mapId);
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
channel,
(MethodCall methodCall) {
Expand All @@ -40,8 +39,7 @@ void main() {
int mapId, String method, Map<dynamic, dynamic> data) async {
final ByteData byteData = const StandardMethodCodec()
.encodeMethodCall(MethodCall(method, data));
await _ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.handlePlatformMessage('plugins.flutter.io/google_maps_$mapId',
byteData, (ByteData? data) {});
}
Expand Down Expand Up @@ -125,9 +123,3 @@ void main() {
});
});
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
T? _ambiguate<T>(T? value) => value;
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ void main() {

setUp(() {
responses = Map<String, dynamic>.from(kDefaultResponses);
_ambiguate(TestDefaultBinaryMessengerBinding.instance)!
.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) {
log.add(methodCall);
final dynamic response = responses[methodCall.method];
Expand Down Expand Up @@ -173,9 +172,3 @@ void main() {
});
});
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
T? _ambiguate<T>(T? value) => value;
Loading

0 comments on commit e08e149

Please sign in to comment.