File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,18 @@ abstract class HiveInterface implements TypeRegistry {
69
69
70
70
/// Checks if a box exists
71
71
Future <bool > boxExists (String name, {String ? path});
72
+
73
+ /// Clears all registered adapters.
74
+ ///
75
+ /// To register an adapter use [registerAdapter] .
76
+ ///
77
+ /// NOTE: [resetAdapters] also clears the default adapters registered
78
+ /// by Hive.
79
+ ///
80
+ /// WARNING: This method is only intended to be used for integration and unit tests
81
+ /// and SHOULD not be used in production code.
82
+ @visibleForTesting
83
+ void resetAdapters ();
72
84
}
73
85
74
86
///
Original file line number Diff line number Diff line change @@ -132,7 +132,6 @@ class TypeRegistryImpl implements TypeRegistry {
132
132
return findAdapterForTypeId (typeId) != null ;
133
133
}
134
134
135
- /// Not part of public API
136
135
void resetAdapters () {
137
136
_typeAdapters.clear ();
138
137
}
Original file line number Diff line number Diff line change @@ -9,6 +9,19 @@ import 'package:test/test.dart';
9
9
10
10
import 'common.dart' ;
11
11
12
+ class _TestAdapter extends TypeAdapter <int > {
13
+ _TestAdapter ([this .typeId = 0 ]);
14
+
15
+ @override
16
+ final int typeId;
17
+
18
+ @override
19
+ int read (_) => 5 ;
20
+
21
+ @override
22
+ void write (_, __) {}
23
+ }
24
+
12
25
void main () {
13
26
group ('HiveImpl' , () {
14
27
Future <HiveImpl > initHive () async {
@@ -316,5 +329,24 @@ void main() {
316
329
await hive.close ();
317
330
});
318
331
});
332
+
333
+ group ('.resetAdapters()' , () {
334
+ test ('returns normally' , () async {
335
+ final hive = await initHive ();
336
+ expect (hive.resetAdapters, returnsNormally);
337
+ });
338
+
339
+ test ('clears an adapter' , () async {
340
+ final hive = await initHive ();
341
+ final adapter = _TestAdapter (1 );
342
+
343
+ expect (hive.isAdapterRegistered (adapter.typeId), isFalse);
344
+ hive.registerAdapter (adapter);
345
+ expect (hive.isAdapterRegistered (adapter.typeId), isTrue);
346
+
347
+ hive.resetAdapters ();
348
+ expect (hive.isAdapterRegistered (adapter.typeId), isFalse);
349
+ });
350
+ });
319
351
});
320
352
}
You can’t perform that action at this time.
0 commit comments