Skip to content

Commit b4ab9a7

Browse files
authored
test: add test case for L2 hit and L1 miss (#56)
1 parent c8022e1 commit b4ab9a7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/json_cache_mem_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter_test/flutter_test.dart';
22
import 'package:json_cache/json_cache.dart';
3+
import 'package:shared_preferences/shared_preferences.dart';
34

45
/// Throws an exception after 'N' refreshes.
56
class _JsonCacheThrowsAfterN extends JsonCacheWrap {
@@ -170,6 +171,15 @@ void main() {
170171
expect(mem[profKey], profData);
171172
expect(mem[prefKey], prefData);
172173
});
174+
test('value missing from L1 cache', () async {
175+
const key = 'aValue';
176+
const value = <String, dynamic>{'must be a json encodable value': true};
177+
final prefs = JsonCachePrefs(await SharedPreferences.getInstance());
178+
await prefs.refresh(key, value);
179+
final JsonCacheMem memCache = JsonCacheMem(prefs);
180+
final cacheL2Value = await memCache.value(key);
181+
expect(cacheL2Value, value);
182+
});
173183
});
174184
});
175185
}

0 commit comments

Comments
 (0)