Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix order-dependant platform interface tests
Fixes all instance of an anti-pattern that was cloned among many of our
platform interfaces, where one test asserts that the static instance is
of a specific class, but other tests change that static instance, such
that the initial test fails if not run first.

Fixes flutter/flutter#52690
Fixes flutter/flutter#52689
  • Loading branch information
stuartmorgan-g committed Oct 1, 2021
commit d9fed59fd0dbf70d15cec7b3ef91d7b013cf8bb9
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import 'package:file_selector_platform_interface/src/method_channel/method_chann
import 'package:flutter_test/flutter_test.dart';

void main() {
// Store the initial instance before any tests change it.
final FileSelectorPlatform initialInstance = FileSelectorPlatform.instance;

group('$FileSelectorPlatform', () {
test('$MethodChannelFileSelector() is the default instance', () {
expect(FileSelectorPlatform.instance,
isInstanceOf<MethodChannelFileSelector>());
expect(initialInstance, isInstanceOf<MethodChannelFileSelector>());
});

test('Can be extended', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

// Store the initial instance before any tests change it.
final GoogleMapsFlutterPlatform initialInstance =
GoogleMapsFlutterPlatform.instance;

group('$GoogleMapsFlutterPlatform', () {
test('$MethodChannelGoogleMapsFlutter() is the default instance', () {
expect(GoogleMapsFlutterPlatform.instance,
isInstanceOf<MethodChannelGoogleMapsFlutter>());
expect(initialInstance, isInstanceOf<MethodChannelGoogleMapsFlutter>());
});

test('Cannot be implemented with `implements`', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';

void main() {
// Store the initial instance before any tests change it.
final GoogleSignInPlatform initialInstance = GoogleSignInPlatform.instance;

group('$GoogleSignInPlatform', () {
test('$MethodChannelGoogleSignIn is the default instance', () {
expect(GoogleSignInPlatform.instance, isA<MethodChannelGoogleSignIn>());
expect(initialInstance, isA<MethodChannelGoogleSignIn>());
});

test('Cannot be implemented with `implements`', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import 'package:quick_actions_platform_interface/platform_interface/quick_action
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

// Store the initial instance before any tests change it.
final QuickActionsPlatform initialInstance = QuickActionsPlatform.instance;

group('$QuickActionsPlatform', () {
test('$MethodChannelQuickActions is the default instance', () {
expect(QuickActionsPlatform.instance, isA<MethodChannelQuickActions>());
expect(initialInstance, isA<MethodChannelQuickActions>());
});

test('Cannot be implemented with `implements`', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import 'package:url_launcher_platform_interface/url_launcher_platform_interface.
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

// Store the initial instance before any tests change it.
final UrlLauncherPlatform initialInstance = UrlLauncherPlatform.instance;

group('$UrlLauncherPlatform', () {
test('$MethodChannelUrlLauncher() is the default instance', () {
expect(UrlLauncherPlatform.instance,
isInstanceOf<MethodChannelUrlLauncher>());
expect(initialInstance, isInstanceOf<MethodChannelUrlLauncher>());
});

test('Cannot be implemented with `implements`', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ class _ApiLogger implements TestHostVideoPlayerApi {
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

// Store the initial instance before any tests change it.
final VideoPlayerPlatform initialInstance = VideoPlayerPlatform.instance;

group('$VideoPlayerPlatform', () {
test('$MethodChannelVideoPlayer() is the default instance', () {
expect(VideoPlayerPlatform.instance,
isInstanceOf<MethodChannelVideoPlayer>());
expect(initialInstance, isInstanceOf<MethodChannelVideoPlayer>());
});
});

Expand Down