From 2a851b5abf73c006a276a68c4d5eb092fa7fb5a9 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 16 Aug 2022 10:24:40 -0700 Subject: [PATCH 1/3] Prepare for fix to https://github.com/flutter/flutter/issues/109339. Currently, in some circumstances where a subclasses of `PlatformInterface` erroneously uses `implements` rather than `extends`, a `NoSuchMethodError` will be thrown (in spite of the documentation at https://pub.dev/documentation/plugin_platform_interface/latest/plugin_platform_interface/PlatformInterface/verify.html claiming that `AssertionError` will be thrown). After https://github.com/flutter/flutter/issues/109339 is fixed, the correct type of exception will be thrown. To avoid tests breakages when the fix happens, we need to modify these tests so that they don't care what kind of exception is thrown. --- .../test/camera_platform_interface_test.dart | 9 ++++++++- .../google_maps_flutter_platform_test.dart | 9 ++++++++- ...google_sign_in_platform_interface_test.dart | 9 ++++++++- .../test/in_app_purchase_platform_test.dart | 18 ++++++++++++++++-- .../quick_actions_platform_interface_test.dart | 9 ++++++++- .../test/method_channel_url_launcher_test.dart | 9 ++++++++- .../v4/platform_navigation_delegate_test.dart | 9 ++++++++- .../v4/platform_webview_controller_test.dart | 9 ++++++++- .../src/v4/platform_webview_widget_test.dart | 9 ++++++++- .../test/src/v4/webview_platform_test.dart | 9 ++++++++- 10 files changed, 88 insertions(+), 11 deletions(-) diff --git a/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart b/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart index 3060089bef40..eab518ce3b23 100644 --- a/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart +++ b/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart @@ -18,7 +18,14 @@ void main() { test('Cannot be implemented with `implements`', () { expect(() { CameraPlatform.instance = ImplementsCameraPlatform(); - }, throwsNoSuchMethodError); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes + // throw a `NoSuchMethodError` and other times throw an + // `AssertionError`. After the issue is fixed, an `AssertionError` will + // always be thrown. For the purpose of this test, we don't really care + // what exception is thrown, so just allow any exception. + }, throwsA(anything)); }); test('Can be extended', () { diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/platform_interface/google_maps_flutter_platform_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/platform_interface/google_maps_flutter_platform_test.dart index d185aabe1a5c..d1dba2b75b55 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/platform_interface/google_maps_flutter_platform_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/platform_interface/google_maps_flutter_platform_test.dart @@ -27,7 +27,14 @@ void main() { expect(() { GoogleMapsFlutterPlatform.instance = ImplementsGoogleMapsFlutterPlatform(); - }, throwsA(isInstanceOf())); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes + // throw a `NoSuchMethodError` and other times throw an + // `AssertionError`. After the issue is fixed, an `AssertionError` will + // always be thrown. For the purpose of this test, we don't really care + // what exception is thrown, so just allow any exception. + }, throwsA(anything)); }); test('Can be mocked with `implements`', () { diff --git a/packages/google_sign_in/google_sign_in_platform_interface/test/google_sign_in_platform_interface_test.dart b/packages/google_sign_in/google_sign_in_platform_interface/test/google_sign_in_platform_interface_test.dart index bf960abc7375..6ffa85fa1e4b 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/test/google_sign_in_platform_interface_test.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/test/google_sign_in_platform_interface_test.dart @@ -18,7 +18,14 @@ void main() { test('Cannot be implemented with `implements`', () { expect(() { GoogleSignInPlatform.instance = ImplementsGoogleSignInPlatform(); - }, throwsA(isA())); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes + // throw a `NoSuchMethodError` and other times throw an + // `AssertionError`. After the issue is fixed, an `AssertionError` will + // always be thrown. For the purpose of this test, we don't really care + // what exception is thrown, so just allow any exception. + }, throwsA(anything)); }); test('Can be extended', () { diff --git a/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart b/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart index 9c0f2dc00020..707802c33dd1 100644 --- a/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart +++ b/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart @@ -14,7 +14,14 @@ void main() { test('Cannot be implemented with `implements`', () { expect(() { InAppPurchasePlatform.instance = ImplementsInAppPurchasePlatform(); - }, throwsNoSuchMethodError); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes + // throw a `NoSuchMethodError` and other times throw an + // `AssertionError`. After the issue is fixed, an `AssertionError` will + // always be thrown. For the purpose of this test, we don't really care + // what exception is thrown, so just allow any exception. + }, throwsA(anything)); }); test('Can be extended', () { @@ -128,7 +135,14 @@ void main() { test('Cannot be implemented with `implements`', () { expect(InAppPurchasePlatformAddition.instance, isNull); - }); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes throw + // a `NoSuchMethodError` and other times throw an `AssertionError`. After + // the issue is fixed, an `AssertionError` will always be thrown. For the + // purpose of this test, we don't really care what exception is thrown, so + // just allow any exception. + }, throwsA(anything)); test('Can be implemented.', () { InAppPurchasePlatformAddition.instance = diff --git a/packages/quick_actions/quick_actions_platform_interface/test/quick_actions_platform_interface_test.dart b/packages/quick_actions/quick_actions_platform_interface/test/quick_actions_platform_interface_test.dart index b9655dc56a3c..ab3299b0cc14 100644 --- a/packages/quick_actions/quick_actions_platform_interface/test/quick_actions_platform_interface_test.dart +++ b/packages/quick_actions/quick_actions_platform_interface/test/quick_actions_platform_interface_test.dart @@ -21,7 +21,14 @@ void main() { test('Cannot be implemented with `implements`', () { expect(() { QuickActionsPlatform.instance = ImplementsQuickActionsPlatform(); - }, throwsNoSuchMethodError); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes + // throw a `NoSuchMethodError` and other times throw an + // `AssertionError`. After the issue is fixed, an `AssertionError` will + // always be thrown. For the purpose of this test, we don't really care + // what exception is thrown, so just allow any exception. + }, throwsA(anything)); }); test('Can be extended', () { diff --git a/packages/url_launcher/url_launcher_platform_interface/test/method_channel_url_launcher_test.dart b/packages/url_launcher/url_launcher_platform_interface/test/method_channel_url_launcher_test.dart index e44e80bab02c..c8ec08c53095 100644 --- a/packages/url_launcher/url_launcher_platform_interface/test/method_channel_url_launcher_test.dart +++ b/packages/url_launcher/url_launcher_platform_interface/test/method_channel_url_launcher_test.dart @@ -24,7 +24,14 @@ void main() { test('Cannot be implemented with `implements`', () { expect(() { UrlLauncherPlatform.instance = ImplementsUrlLauncherPlatform(); - }, throwsA(isInstanceOf())); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes + // throw a `NoSuchMethodError` and other times throw an + // `AssertionError`. After the issue is fixed, an `AssertionError` will + // always be thrown. For the purpose of this test, we don't really care + // what exception is thrown, so just allow any exception. + }, throwsA(anything)); }); test('Can be mocked with `implements`', () { diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_navigation_delegate_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_navigation_delegate_test.dart index 5674c1522408..dd4a26c4faf9 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_navigation_delegate_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_navigation_delegate_test.dart @@ -23,7 +23,14 @@ void main() { expect(() { PlatformNavigationDelegate(params); - }, throwsNoSuchMethodError); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes throw + // a `NoSuchMethodError` and other times throw an `AssertionError`. After + // the issue is fixed, an `AssertionError` will always be thrown. For the + // purpose of this test, we don't really care what exception is thrown, so + // just allow any exception. + }, throwsA(anything)); }); test('Can be extended', () { diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_controller_test.dart index b6d043cac9c8..32374fb04484 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_controller_test.dart @@ -28,7 +28,14 @@ void main() { expect(() { PlatformWebViewController( const PlatformWebViewControllerCreationParams()); - }, throwsNoSuchMethodError); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes throw + // a `NoSuchMethodError` and other times throw an `AssertionError`. After + // the issue is fixed, an `AssertionError` will always be thrown. For the + // purpose of this test, we don't really care what exception is thrown, so + // just allow any exception. + }, throwsA(anything)); }); test('Can be extended', () { diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_widget_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_widget_test.dart index 30fa52ece24a..ede16c162413 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_widget_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_widget_test.dart @@ -27,7 +27,14 @@ void main() { expect(() { PlatformWebViewWidget(params); - }, throwsNoSuchMethodError); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes throw + // a `NoSuchMethodError` and other times throw an `AssertionError`. After + // the issue is fixed, an `AssertionError` will always be thrown. For the + // purpose of this test, we don't really care what exception is thrown, so + // just allow any exception. + }, throwsA(anything)); }); test('Can be extended', () { diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/webview_platform_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/webview_platform_test.dart index f09156919512..4ab6d587b879 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/webview_platform_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/webview_platform_test.dart @@ -22,7 +22,14 @@ void main() { test('Cannot be implemented with `implements`', () { expect(() { WebViewPlatform.instance = ImplementsWebViewPlatform(); - }, throwsNoSuchMethodError); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes throw + // a `NoSuchMethodError` and other times throw an `AssertionError`. After + // the issue is fixed, an `AssertionError` will always be thrown. For the + // purpose of this test, we don't really care what exception is thrown, so + // just allow any exception. + }, throwsA(anything)); }); test('Can be extended', () { From 52d55c7eda0a3a8edfd0110d7c5c4d19b59312ee Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 16 Aug 2022 11:19:37 -0700 Subject: [PATCH 2/3] Remove accidental extra change --- .../test/in_app_purchase_platform_test.dart | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart b/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart index 707802c33dd1..ac70f6d2b070 100644 --- a/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart +++ b/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart @@ -135,14 +135,7 @@ void main() { test('Cannot be implemented with `implements`', () { expect(InAppPurchasePlatformAddition.instance, isNull); - // In versions of `package:plugin_platform_interface` prior to fixing - // https://github.com/flutter/flutter/issues/109339, an attempt to - // implement a platform interface using `implements` would sometimes throw - // a `NoSuchMethodError` and other times throw an `AssertionError`. After - // the issue is fixed, an `AssertionError` will always be thrown. For the - // purpose of this test, we don't really care what exception is thrown, so - // just allow any exception. - }, throwsA(anything)); + }); test('Can be implemented.', () { InAppPurchasePlatformAddition.instance = From f1200cd667c1936915796f7aa23cb93d21ff3555 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 16 Aug 2022 11:28:58 -0700 Subject: [PATCH 3/3] Rename misleading test --- .../test/in_app_purchase_platform_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart b/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart index ac70f6d2b070..879ad9c4c633 100644 --- a/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart +++ b/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart @@ -133,7 +133,7 @@ void main() { InAppPurchasePlatformAddition.instance = null; }); - test('Cannot be implemented with `implements`', () { + test('Default instance is null', () { expect(InAppPurchasePlatformAddition.instance, isNull); });