1- import 'package:flutter/services.dart' ;
21import 'package:flutter_secure_storage/flutter_secure_storage.dart' ;
32import 'package:flutter_secure_storage_platform_interface/flutter_secure_storage_platform_interface.dart' ;
43import 'package:flutter_test/flutter_test.dart' ;
54import 'package:mocktail/mocktail.dart' ;
5+ import 'package:plugin_platform_interface/plugin_platform_interface.dart' ;
66
7- import 'flutter_secure_storage_mock.dart' ;
7+ // ✅ Correct Mock Class Implementation
8+ class MockFlutterSecureStoragePlatform extends Mock
9+ with MockPlatformInterfaceMixin
10+ implements FlutterSecureStoragePlatform {}
811
912void main () {
10- TestWidgetsFlutterBinding .ensureInitialized ();
11-
1213 late FlutterSecureStorage storage;
1314 late MockFlutterSecureStoragePlatform mockPlatform;
1415
15- const channel = MethodChannel ('plugins.it_nomads.com/flutter_secure_storage' );
16- final methodStorage = MethodChannelFlutterSecureStorage ();
17- final log = < MethodCall > [];
18-
19- Future <bool ?>? handler (MethodCall methodCall) async {
20- log.add (methodCall);
21- if (methodCall.method == 'containsKey' ) {
22- return true ;
23- } else if (methodCall.method == 'isProtectedDataAvailable' ) {
24- return true ;
25- }
26- return null ;
27- }
28-
2916 setUp (() {
3017 mockPlatform = MockFlutterSecureStoragePlatform ();
3118 FlutterSecureStoragePlatform .instance = mockPlatform;
3219 storage = const FlutterSecureStorage ();
33-
34- // Ensure method channel mock is set up for the tests
35- TestDefaultBinaryMessengerBinding .instance.defaultBinaryMessenger
36- .setMockMethodCallHandler (channel, handler);
37-
38- log.clear (); // Clear logs before each test
39- });
40-
41- tearDown (() {
42- log.clear (); // Clear logs after each test
43- TestDefaultBinaryMessengerBinding .instance.defaultBinaryMessenger
44- .setMockMethodCallHandler (channel, null ); // Remove the mock handler
45- });
46-
47- group ('Method Channel Interaction Tests for FlutterSecureStorage' , () {
48- test ('read' , () async {
49- const key = 'test_key' ;
50- const options = < String , String > {};
51- await methodStorage.read (key: key, options: options);
52-
53- expect (
54- log,
55- < Matcher > [
56- isMethodCall (
57- 'read' ,
58- arguments: < String , Object > {
59- 'key' : key,
60- 'options' : options,
61- },
62- ),
63- ],
64- );
65- });
66-
67- test ('write' , () async {
68- const key = 'test_key' ;
69- const options = < String , String > {};
70- await methodStorage.write (key: key, value: 'test' , options: options);
71-
72- expect (
73- log,
74- < Matcher > [
75- isMethodCall (
76- 'write' ,
77- arguments: < String , Object > {
78- 'key' : key,
79- 'value' : 'test' ,
80- 'options' : options,
81- },
82- ),
83- ],
84- );
85- });
86-
87- test ('containsKey' , () async {
88- const key = 'test_key' ;
89- const options = < String , String > {};
90- await methodStorage.write (key: key, value: 'test' , options: options);
91-
92- final result =
93- await methodStorage.containsKey (key: key, options: options);
94-
95- expect (result, true );
96- });
97-
98- test ('delete' , () async {
99- const key = 'test_key' ;
100- const options = < String , String > {};
101- await methodStorage.write (key: key, value: 'test' , options: options);
102- await methodStorage.delete (key: key, options: options);
103-
104- expect (
105- log,
106- < Matcher > [
107- isMethodCall (
108- 'write' ,
109- arguments: < String , Object > {
110- 'key' : key,
111- 'value' : 'test' ,
112- 'options' : options,
113- },
114- ),
115- isMethodCall (
116- 'delete' ,
117- arguments: < String , Object > {
118- 'key' : key,
119- 'options' : options,
120- },
121- ),
122- ],
123- );
124- });
125-
126- test ('deleteAll' , () async {
127- const options = < String , String > {};
128- await methodStorage.deleteAll (options: options);
129-
130- expect (
131- log,
132- < Matcher > [
133- isMethodCall (
134- 'deleteAll' ,
135- arguments: < String , Object > {
136- 'options' : options,
137- },
138- ),
139- ],
140- );
141- });
142- });
143-
144- group ('Platform-Specific Interface Tests' , () {
145- test ('Cannot be implemented with `implements`' , () {
146- expect (
147- () {
148- FlutterSecureStoragePlatform .instance =
149- ImplementsFlutterSecureStoragePlatform ();
150- },
151- throwsA (isInstanceOf <AssertionError >()),
152- );
153- });
154-
155- test ('Can be mocked with `implements`' , () {
156- final mock = MockFlutterSecureStoragePlatform ();
157- FlutterSecureStoragePlatform .instance = mock;
158- });
159-
160- test ('Can be extended' , () {
161- FlutterSecureStoragePlatform .instance =
162- ExtendsFlutterSecureStoragePlatform ();
163- });
16420 });
16521
166- group ('FlutterSecureStorage Methods Invocation Tests' , () {
22+ group ('FlutterSecureStorage Tests' , () {
16723 const testKey = 'testKey' ;
16824 const testValue = 'testValue' ;
16925
@@ -262,7 +118,7 @@ void main() {
262118 });
263119 });
264120
265- group ('AndroidOptions Configuration Tests' , () {
121+ group ('AndroidOptions Tests' , () {
266122 test ('Default AndroidOptions should have correct default values' , () {
267123 const options = AndroidOptions .defaultOptions;
268124
@@ -345,7 +201,7 @@ void main() {
345201 });
346202 });
347203
348- group ('WebOptions Configuration Tests' , () {
204+ group ('WebOptions Tests' , () {
349205 test ('Default WebOptions should have correct default values' , () {
350206 const options = WebOptions .defaultOptions;
351207
@@ -405,7 +261,7 @@ void main() {
405261 });
406262 });
407263
408- group ('WindowsOptions Configuration Tests' , () {
264+ group ('WindowsOptions Tests' , () {
409265 test ('Default WindowsOptions should have correct default values' , () {
410266 const options = WindowsOptions .defaultOptions;
411267
@@ -452,7 +308,7 @@ void main() {
452308 });
453309 });
454310
455- group ('iOSOptions Configuration Tests' , () {
311+ group ('IOSOptions Tests' , () {
456312 test ('Default IOSOptions should have correct default values' , () {
457313 const options = IOSOptions .defaultOptions;
458314
@@ -512,8 +368,8 @@ void main() {
512368 });
513369 });
514370
515- group ('macOSOptions Configuration Tests' , () {
516- test ('Default macOSOptions should have correct default values' , () {
371+ group ('MacOsOptions Tests' , () {
372+ test ('Default MacOsOptions should have correct default values' , () {
517373 // Ignore for test
518374 // ignore: use_named_constants
519375 const options = MacOsOptions ();
@@ -526,7 +382,7 @@ void main() {
526382 });
527383 });
528384
529- test ('macOSOptions with custom values' , () {
385+ test ('MacOsOptions with custom values' , () {
530386 const options = MacOsOptions (
531387 accountName: 'macAccount' ,
532388 groupId: 'group.mac.example' ,
@@ -544,7 +400,7 @@ void main() {
544400 });
545401 });
546402
547- test ('macOSOptions defaultOptions matches default constructor' , () {
403+ test ('MacOsOptions defaultOptions matches default constructor' , () {
548404 const defaultOptions = MacOsOptions .defaultOptions;
549405 // Ignore for test
550406 // ignore: use_named_constants
0 commit comments