From a6f5209b30a77ae8a05991a7477af5a9e5ca9885 Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Fri, 12 May 2023 16:41:21 +0300 Subject: [PATCH] [shared_pref] add channel test --- ...references_aurora_method_channel_test.dart | 55 +++++++++++++++++-- .../test/shared_preferences_aurora_test.dart | 29 ---------- 2 files changed, 51 insertions(+), 33 deletions(-) delete mode 100644 packages/shared_preferences/shared_preferences_aurora/test/shared_preferences_aurora_test.dart diff --git a/packages/shared_preferences/shared_preferences_aurora/test/shared_preferences_aurora_method_channel_test.dart b/packages/shared_preferences/shared_preferences_aurora/test/shared_preferences_aurora_method_channel_test.dart index 391c42f..1649c56 100644 --- a/packages/shared_preferences/shared_preferences_aurora/test/shared_preferences_aurora_method_channel_test.dart +++ b/packages/shared_preferences/shared_preferences_aurora/test/shared_preferences_aurora_method_channel_test.dart @@ -3,14 +3,33 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:shared_preferences_aurora/shared_preferences_aurora_method_channel.dart'; void main() { - MethodChannelSharedPreferencesAurora platform = MethodChannelSharedPreferencesAurora(); + MethodChannelSharedPreferencesAurora platform = + MethodChannelSharedPreferencesAurora(); const MethodChannel channel = MethodChannel('shared_preferences_aurora'); TestWidgetsFlutterBinding.ensureInitialized(); setUp(() { channel.setMockMethodCallHandler((MethodCall methodCall) async { - return '42'; + switch (methodCall.method) { + case 'setInt': + return true; + case 'setBool': + return true; + case 'setDouble': + return true; + case 'setString': + return true; + case 'setStringList': + return true; + case 'clearWithPrefix': + return true; + case 'remove': + return true; + case 'getAllWithPrefix': + return {}; + } + return null; }); }); @@ -18,7 +37,35 @@ void main() { channel.setMockMethodCallHandler(null); }); - test('getPlatformVersion', () async { - expect(await platform.getPlatformVersion(), '42'); + test('onSetInt', () async { + expect(await platform.setInt('key', 42), true); + }); + + test('onSetBool', () async { + expect(await platform.setBool('key', true), true); + }); + + test('onSetDouble', () async { + expect(await platform.setDouble('key', 0.0), true); + }); + + test('onSetString', () async { + expect(await platform.setString('key', "Start"), true); + }); + + test('onSetStringList', () async { + expect(await platform.setStringList('key', []), true); + }); + + test('onClearWithPrefix', () async { + expect(await platform.clearWithPrefix('prefix'), true); + }); + + test('onRemove', () async { + expect(await platform.remove('key'), true); + }); + + test('onGetAllWithPrefix', () async { + expect(await platform.getAllWithPrefix('prefix'), {}); }); } diff --git a/packages/shared_preferences/shared_preferences_aurora/test/shared_preferences_aurora_test.dart b/packages/shared_preferences/shared_preferences_aurora/test/shared_preferences_aurora_test.dart deleted file mode 100644 index bae150b..0000000 --- a/packages/shared_preferences/shared_preferences_aurora/test/shared_preferences_aurora_test.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:shared_preferences_aurora/shared_preferences_aurora.dart'; -import 'package:shared_preferences_aurora/shared_preferences_aurora_platform_interface.dart'; -import 'package:shared_preferences_aurora/shared_preferences_aurora_method_channel.dart'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - -class MockSharedPreferencesAuroraPlatform - with MockPlatformInterfaceMixin - implements SharedPreferencesAuroraPlatform { - - @override - Future getPlatformVersion() => Future.value('42'); -} - -void main() { - final SharedPreferencesAuroraPlatform initialPlatform = SharedPreferencesAuroraPlatform.instance; - - test('$MethodChannelSharedPreferencesAurora is the default instance', () { - expect(initialPlatform, isInstanceOf()); - }); - - test('getPlatformVersion', () async { - SharedPreferencesAurora sharedPreferencesAuroraPlugin = SharedPreferencesAurora(); - MockSharedPreferencesAuroraPlatform fakePlatform = MockSharedPreferencesAuroraPlatform(); - SharedPreferencesAuroraPlatform.instance = fakePlatform; - - expect(await sharedPreferencesAuroraPlugin.getPlatformVersion(), '42'); - }); -}