@@ -4,23 +4,24 @@ import 'package:json_cache/json_cache.dart';
4
4
import 'flutter_secure_storage_mock.dart' ;
5
5
6
6
void main () {
7
- group ('JsonCacheSecStorage ' , () {
7
+ group ('JsonCacheFlutterSecureStorage ' , () {
8
8
test ('clear, value, refresh' , () async {
9
9
final secStorageMock = FlutterSecureStorageMock ();
10
- final JsonCacheSecStorage secCache = JsonCacheSecStorage (secStorageMock);
10
+ final JsonCacheFlutterSecureStorage flutterSecureCache =
11
+ JsonCacheFlutterSecureStorage (secStorageMock);
11
12
const profKey = 'profile' ;
12
13
const profData = < String , Object > {'id' : 1 , 'name' : 'John Due' };
13
- await secCache .refresh (profKey, profData);
14
+ await flutterSecureCache .refresh (profKey, profData);
14
15
expect (secStorageMock.writeInvokations, 1 );
15
16
16
- var prof = await secCache .value (profKey);
17
+ var prof = await flutterSecureCache .value (profKey);
17
18
expect (prof, profData);
18
19
expect (secStorageMock.readInvokations, 1 );
19
20
20
- await secCache .clear ();
21
+ await flutterSecureCache .clear ();
21
22
expect (secStorageMock.deleteAllInvokations, 1 );
22
23
23
- prof = await secCache .value (profKey);
24
+ prof = await flutterSecureCache .value (profKey);
24
25
expect (prof, isNull);
25
26
expect (secStorageMock.readInvokations, 2 );
26
27
});
@@ -34,52 +35,54 @@ void main() {
34
35
'notifications' : {'enabled' : true }
35
36
};
36
37
final secStorageMock = FlutterSecureStorageMock ();
37
- final JsonCacheSecStorage secCache = JsonCacheSecStorage (secStorageMock);
38
+ final JsonCacheFlutterSecureStorage flutterSecureCache =
39
+ JsonCacheFlutterSecureStorage (secStorageMock);
38
40
// update data
39
- await secCache .refresh (profKey, profData);
40
- await secCache .refresh (prefKey, prefData);
41
+ await flutterSecureCache .refresh (profKey, profData);
42
+ await flutterSecureCache .refresh (prefKey, prefData);
41
43
42
44
// test for `true`
43
- expect (await secCache .contains (profKey), true );
44
- expect (await secCache .contains (prefKey), true );
45
+ expect (await flutterSecureCache .contains (profKey), true );
46
+ expect (await flutterSecureCache .contains (prefKey), true );
45
47
46
48
// test for `false`
47
- expect (await secCache .contains ('a key' ), false );
48
- await secCache .remove (profKey);
49
- expect (await secCache .contains (profKey), false );
50
- await secCache .remove (prefKey);
51
- expect (await secCache .contains (prefKey), false );
49
+ expect (await flutterSecureCache .contains ('a key' ), false );
50
+ await flutterSecureCache .remove (profKey);
51
+ expect (await flutterSecureCache .contains (profKey), false );
52
+ await flutterSecureCache .remove (prefKey);
53
+ expect (await flutterSecureCache .contains (prefKey), false );
52
54
});
53
55
test ('remove' , () async {
54
56
final secStorageMock = FlutterSecureStorageMock ();
55
- final JsonCacheSecStorage secCache = JsonCacheSecStorage (secStorageMock);
57
+ final JsonCacheFlutterSecureStorage flutterSecureCache =
58
+ JsonCacheFlutterSecureStorage (secStorageMock);
56
59
const profKey = 'profile' ;
57
60
const prefKey = 'preferences' ;
58
61
final profData = < String , Object > {'id' : 1 , 'name' : 'John Due' };
59
62
final prefData = < String , Object > {
60
63
'theme' : 'dark' ,
61
64
'notifications' : {'enabled' : true }
62
65
};
63
- await secCache .refresh (profKey, profData);
64
- await secCache .refresh (prefKey, prefData);
66
+ await flutterSecureCache .refresh (profKey, profData);
67
+ await flutterSecureCache .refresh (prefKey, prefData);
65
68
expect (secStorageMock.writeInvokations, 2 );
66
69
67
- var prof = await secCache .value (profKey);
70
+ var prof = await flutterSecureCache .value (profKey);
68
71
expect (prof, profData);
69
72
expect (secStorageMock.readInvokations, 1 );
70
73
71
- await secCache .remove (profKey);
74
+ await flutterSecureCache .remove (profKey);
72
75
expect (secStorageMock.deleteInvokations, 1 );
73
- prof = await secCache .value (profKey);
76
+ prof = await flutterSecureCache .value (profKey);
74
77
expect (prof, isNull);
75
78
expect (secStorageMock.readInvokations, 2 );
76
79
77
- var pref = await secCache .value (prefKey);
80
+ var pref = await flutterSecureCache .value (prefKey);
78
81
expect (pref, prefData);
79
82
expect (secStorageMock.readInvokations, 3 );
80
- await secCache .remove (prefKey);
83
+ await flutterSecureCache .remove (prefKey);
81
84
expect (secStorageMock.deleteInvokations, 2 );
82
- pref = await secCache .value (prefKey);
85
+ pref = await flutterSecureCache .value (prefKey);
83
86
expect (pref, isNull);
84
87
expect (secStorageMock.readInvokations, 4 );
85
88
});
0 commit comments