diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 137ea985d..1ec63fda5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: test-platform: [vm, chrome] - dart-channel: ["2.12.0", "2.13.0"] + dart-channel: ["2.12.0", "2.13.0", "2.14.0"] steps: - uses: actions/checkout@v1 - uses: dart-lang/setup-dart@v1 diff --git a/hive/CHANGELOG.md b/hive/CHANGELOG.md index eb2ba655f..a5594b597 100644 --- a/hive/CHANGELOG.md +++ b/hive/CHANGELOG.md @@ -1,3 +1,15 @@ +# 2.0.5 + +### Enhancements + +- Get IndexedDB selectively based on window property - [#802](https://github.com/hivedb/hive/pull/802) +- Added `path` parameter to `boxExists` and `deleteBoxFromDisk` methods - [#776](https://github.com/hivedb/hive/pull/776) +- Added `flush` method to boxes - [#852](https://github.com/hivedb/hive/pull/852) + +### Fixes + +- Don't loose track of box objects if init crashes - [#846](https://github.com/hivedb/hive/pull/846) + # 2.0.4 ### Enhancements diff --git a/hive/analysis_options.yaml b/hive/analysis_options.yaml index 282147030..96d00b1bb 100644 --- a/hive/analysis_options.yaml +++ b/hive/analysis_options.yaml @@ -1,13 +1,13 @@ -include: package:pedantic/analysis_options.yaml +include: package:lints/recommended.yaml analyzer: exclude: - "**/*.g.dart" - - "example/*" + - "example/**" strong-mode: implicit-casts: false errors: invalid_use_of_protected_member: error - always_declare_return_types: error + always_declare_return_types: error linter: rules: - avoid_function_literals_in_foreach_calls @@ -44,4 +44,4 @@ linter: - unnecessary_getters_setters - unnecessary_lambdas - unnecessary_null_aware_assignments - - unnecessary_statements \ No newline at end of file + - unnecessary_statements diff --git a/hive/lib/src/backend/js/backend_manager.dart b/hive/lib/src/backend/js/backend_manager.dart index b86d8f9b2..8d9d02781 100644 --- a/hive/lib/src/backend/js/backend_manager.dart +++ b/hive/lib/src/backend/js/backend_manager.dart @@ -1,17 +1,20 @@ import 'dart:html'; import 'dart:indexed_db'; - +import 'dart:js' as js; import 'package:hive/hive.dart'; import 'package:hive/src/backend/js/storage_backend_js.dart'; import 'package:hive/src/backend/storage_backend.dart'; /// Opens IndexedDB databases class BackendManager implements BackendManagerInterface { + IdbFactory? get indexedDB => js.context.hasProperty('window') + ? window.indexedDB + : WorkerGlobalScope.instance.indexedDB; + @override Future open( String name, String? path, bool crashRecovery, HiveCipher? cipher) async { - var db = - await window.indexedDB!.open(name, version: 1, onUpgradeNeeded: (e) { + var db = await indexedDB!.open(name, version: 1, onUpgradeNeeded: (e) { var db = e.target.result as Database; if (!db.objectStoreNames!.contains('box')) { db.createObjectStore('box'); @@ -23,7 +26,7 @@ class BackendManager implements BackendManagerInterface { @override Future deleteBox(String name, String? path) { - return window.indexedDB!.deleteDatabase(name); + return indexedDB!.deleteDatabase(name); } @override @@ -31,7 +34,7 @@ class BackendManager implements BackendManagerInterface { // https://stackoverflow.com/a/17473952 try { var _exists = true; - await window.indexedDB!.open(name, version: 1, onUpgradeNeeded: (e) { + await indexedDB!.open(name, version: 1, onUpgradeNeeded: (e) { e.target.transaction!.abort(); _exists = false; }); diff --git a/hive/lib/src/backend/js/storage_backend_js.dart b/hive/lib/src/backend/js/storage_backend_js.dart index 92bf9b257..b15a76471 100644 --- a/hive/lib/src/backend/js/storage_backend_js.dart +++ b/hive/lib/src/backend/js/storage_backend_js.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:html'; import 'dart:indexed_db'; +import 'dart:js' as js; import 'dart:js_util'; import 'dart:typed_data'; @@ -199,6 +200,12 @@ class StorageBackendJs extends StorageBackend { @override Future deleteFromDisk() { - return window.indexedDB!.deleteDatabase(_db.name!); + final indexDB = js.context.hasProperty('window') + ? window.indexedDB + : WorkerGlobalScope.instance.indexedDB; + return indexDB!.deleteDatabase(_db.name!); } + + @override + Future flush() => Future.value(); } diff --git a/hive/lib/src/backend/storage_backend.dart b/hive/lib/src/backend/storage_backend.dart index 61786e6f4..8883a6685 100644 --- a/hive/lib/src/backend/storage_backend.dart +++ b/hive/lib/src/backend/storage_backend.dart @@ -34,6 +34,9 @@ abstract class StorageBackend { /// Clear database and delete from disk Future deleteFromDisk(); + + /// Flush all changes to disk + Future flush(); } /// Abstract database manager diff --git a/hive/lib/src/backend/storage_backend_memory.dart b/hive/lib/src/backend/storage_backend_memory.dart index 55ec4e2a3..1087dcd74 100644 --- a/hive/lib/src/backend/storage_backend_memory.dart +++ b/hive/lib/src/backend/storage_backend_memory.dart @@ -67,4 +67,7 @@ class StorageBackendMemory extends StorageBackend { Future deleteFromDisk() { throw UnsupportedError('This operation is unsupported for memory boxes.'); } + + @override + Future flush() => Future.value(); } diff --git a/hive/lib/src/backend/vm/storage_backend_vm.dart b/hive/lib/src/backend/vm/storage_backend_vm.dart index 07a9ca956..341017799 100644 --- a/hive/lib/src/backend/vm/storage_backend_vm.dart +++ b/hive/lib/src/backend/vm/storage_backend_vm.dart @@ -2,8 +2,8 @@ import 'dart:async'; import 'dart:io'; import 'package:hive/hive.dart'; -import 'package:hive/src/backend/vm/read_write_sync.dart'; import 'package:hive/src/backend/storage_backend.dart'; +import 'package:hive/src/backend/vm/read_write_sync.dart'; import 'package:hive/src/binary/binary_reader_impl.dart'; import 'package:hive/src/binary/binary_writer_impl.dart'; import 'package:hive/src/binary/frame.dart'; @@ -226,4 +226,11 @@ class StorageBackendVm extends StorageBackend { await _file.delete(); }); } + + @override + Future flush() { + return _sync.syncWrite(() async { + await writeRaf.flush(); + }); + } } diff --git a/hive/lib/src/binary/frame.dart b/hive/lib/src/binary/frame.dart index 4f1861e82..e1d2902a4 100644 --- a/hive/lib/src/binary/frame.dart +++ b/hive/lib/src/binary/frame.dart @@ -96,6 +96,14 @@ class Frame { 'length: $length, offset: $offset)'; } } + + @override + int get hashCode => + runtimeType.hashCode ^ + key.hashCode ^ + value.hashCode ^ + length.hashCode ^ + deleted.hashCode; } /// Possible Key types diff --git a/hive/lib/src/box/box_base.dart b/hive/lib/src/box/box_base.dart index 0644b43d3..e3e40d907 100644 --- a/hive/lib/src/box/box_base.dart +++ b/hive/lib/src/box/box_base.dart @@ -21,6 +21,9 @@ class BoxEvent { } return false; } + + @override + int get hashCode => runtimeType.hashCode ^ key.hashCode ^ value.hashCode; } /// Boxes contain all of your data. In the browser, each box has its own @@ -124,4 +127,7 @@ abstract class BoxBase { /// /// In the browser, the IndexedDB database is being removed. Future deleteFromDisk(); + + /// Flushes all pending changes of the box to disk. + Future flush(); } diff --git a/hive/lib/src/box/box_base_impl.dart b/hive/lib/src/box/box_base_impl.dart index 368ab6584..79163db5e 100644 --- a/hive/lib/src/box/box_base_impl.dart +++ b/hive/lib/src/box/box_base_impl.dart @@ -254,4 +254,7 @@ class _NullBoxBase implements BoxBase { @override Never watch({key}) => throw UnimplementedError(); + + @override + Never flush() => throw UnimplementedError(); } diff --git a/hive/lib/src/box/box_impl.dart b/hive/lib/src/box/box_impl.dart index a92fadfc0..7d81db2e0 100644 --- a/hive/lib/src/box/box_impl.dart +++ b/hive/lib/src/box/box_impl.dart @@ -103,4 +103,9 @@ class BoxImpl extends BoxBaseImpl implements Box { } return map; } + + @override + Future flush() async { + await backend.flush(); + } } diff --git a/hive/lib/src/box/lazy_box_impl.dart b/hive/lib/src/box/lazy_box_impl.dart index 4f04a207c..9f0965e9c 100644 --- a/hive/lib/src/box/lazy_box_impl.dart +++ b/hive/lib/src/box/lazy_box_impl.dart @@ -5,8 +5,8 @@ import 'package:hive/hive.dart'; import 'package:hive/src/backend/storage_backend.dart'; import 'package:hive/src/binary/frame.dart'; import 'package:hive/src/box/box_base_impl.dart'; -import 'package:hive/src/object/hive_object.dart'; import 'package:hive/src/hive_impl.dart'; +import 'package:hive/src/object/hive_object.dart'; /// Not part of public API class LazyBoxImpl extends BoxBaseImpl implements LazyBox { @@ -92,4 +92,9 @@ class LazyBoxImpl extends BoxBaseImpl implements LazyBox { await performCompactionIfNeeded(); } + + @override + Future flush() async { + await backend.flush(); + } } diff --git a/hive/lib/src/hive.dart b/hive/lib/src/hive.dart index d88720d5f..586d947ed 100644 --- a/hive/lib/src/hive.dart +++ b/hive/lib/src/hive.dart @@ -19,7 +19,7 @@ abstract class HiveInterface implements TypeRegistry { bool crashRecovery = true, String? path, Uint8List? bytes, - @deprecated List? encryptionKey, + @Deprecated('Use encryptionCipher instead') List? encryptionKey, }); /// Opens a lazy box. @@ -33,7 +33,7 @@ abstract class HiveInterface implements TypeRegistry { CompactionStrategy compactionStrategy = defaultCompactionStrategy, bool crashRecovery = true, String? path, - @deprecated List? encryptionKey, + @Deprecated('Use encryptionCipher instead') List? encryptionKey, }); /// Returns a previously opened box. @@ -51,7 +51,7 @@ abstract class HiveInterface implements TypeRegistry { /// Removes the file which contains the box and closes the box. /// /// In the browser, the IndexedDB database is being removed. - Future deleteBoxFromDisk(String name); + Future deleteBoxFromDisk(String name, {String? path}); /// Deletes all currently open boxes from disk. /// @@ -62,7 +62,7 @@ abstract class HiveInterface implements TypeRegistry { List generateSecureKey(); /// Checks if a box exists - Future boxExists(String name); + Future boxExists(String name, {String? path}); } /// diff --git a/hive/lib/src/hive_impl.dart b/hive/lib/src/hive_impl.dart index 535c060d6..0d49531bc 100644 --- a/hive/lib/src/hive_impl.dart +++ b/hive/lib/src/hive_impl.dart @@ -12,8 +12,8 @@ import 'package:hive/src/box/box_impl.dart'; import 'package:hive/src/box/default_compaction_strategy.dart'; import 'package:hive/src/box/default_key_comparator.dart'; import 'package:hive/src/box/lazy_box_impl.dart'; -import 'package:hive/src/util/extensions.dart'; import 'package:hive/src/registry/type_registry_impl.dart'; +import 'package:hive/src/util/extensions.dart'; import 'package:meta/meta.dart'; import 'backend/storage_backend.dart'; @@ -107,8 +107,8 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface { newBox = BoxImpl(this, name, comparator, compaction, backend); } - await newBox.initialize(); _boxes[name] = newBox; + await newBox.initialize(); completer.complete(); return newBox; @@ -131,7 +131,7 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface { bool crashRecovery = true, String? path, Uint8List? bytes, - @deprecated List? encryptionKey, + @Deprecated('Use encryptionCipher instead') List? encryptionKey, }) async { if (encryptionKey != null) { encryptionCipher = HiveAesCipher(encryptionKey); @@ -148,7 +148,7 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface { CompactionStrategy compactionStrategy = defaultCompactionStrategy, bool crashRecovery = true, String? path, - @deprecated List? encryptionKey, + @Deprecated('Use encryptionCipher instead') List? encryptionKey, }) async { if (encryptionKey != null) { encryptionCipher = HiveAesCipher(encryptionKey); diff --git a/hive/lib/src/object/hive_object.dart b/hive/lib/src/object/hive_object.dart index e35faf08c..7fcaa0281 100644 --- a/hive/lib/src/object/hive_object.dart +++ b/hive/lib/src/object/hive_object.dart @@ -1,8 +1,8 @@ library hive_object_internal; import 'package:hive/hive.dart'; -import 'package:meta/meta.dart'; import 'package:hive/src/object/hive_list_impl.dart'; +import 'package:meta/meta.dart'; part 'hive_object_internal.dart'; diff --git a/hive/pubspec.yaml b/hive/pubspec.yaml index 924c602d7..47d4d2549 100644 --- a/hive/pubspec.yaml +++ b/hive/pubspec.yaml @@ -1,6 +1,6 @@ name: hive description: Lightweight and blazing fast key-value database written in pure Dart. Strongly encrypted using AES-256. -version: 2.0.4 +version: 2.0.5 homepage: https://github.com/hivedb/hive/tree/master/hive documentation: https://docs.hivedb.dev/ @@ -12,10 +12,9 @@ dependencies: crypto: ^3.0.0 dev_dependencies: - test: ^1.15.7 - # TODO: Fix & update mockito version - mockito: 5.0.0-nullsafety.5 - pedantic: ^1.9.0 + test: ^1.17.12 + mocktail: ^0.2.0 + lints: ^1.0.0 path: ^1.7.0 pointycastle: ^3.0.1 - build_runner: ^1.10.0 + build_runner: ^2.1.2 diff --git a/hive/test/integration/hive_list_test.dart b/hive/test/integration/hive_list_test.dart index 0cd52a80e..2f09d65a7 100644 --- a/hive/test/integration/hive_list_test.dart +++ b/hive/test/integration/hive_list_test.dart @@ -1,7 +1,6 @@ import 'package:hive/hive.dart'; import 'package:hive/src/hive_impl.dart'; import 'package:hive/src/object/hive_list_impl.dart'; -import 'package:hive/src/object/hive_object.dart'; import 'package:test/test.dart'; import 'integration.dart'; @@ -15,6 +14,9 @@ class _TestObject extends HiveObject { @override bool operator ==(dynamic other) => other is _TestObject && other.name == name; + + @override + int get hashCode => runtimeType.hashCode ^ name.hashCode; } class _TestObjectAdapter extends TypeAdapter<_TestObject> { diff --git a/hive/test/integration/hive_object_test.dart b/hive/test/integration/hive_object_test.dart index da3c66a42..9d02d83f0 100644 --- a/hive/test/integration/hive_object_test.dart +++ b/hive/test/integration/hive_object_test.dart @@ -11,6 +11,9 @@ class _TestObject with HiveObjectMixin { @override bool operator ==(dynamic other) => other is _TestObject && other.name == name; + + @override + int get hashCode => runtimeType.hashCode ^ name.hashCode; } class _TestObjectAdapter extends TypeAdapter<_TestObject> { diff --git a/hive/test/integration/recovery_test.dart b/hive/test/integration/recovery_test.dart index f19e7ca2f..410f08a9b 100644 --- a/hive/test/integration/recovery_test.dart +++ b/hive/test/integration/recovery_test.dart @@ -5,8 +5,8 @@ import 'dart:io'; import 'package:hive/src/box/keystore.dart'; import 'package:hive/src/hive_impl.dart'; -import 'package:test/test.dart'; import 'package:path/path.dart' as path; +import 'package:test/test.dart'; import '../tests/backend/vm/storage_backend_vm_test.dart'; import '../tests/common.dart'; diff --git a/hive/test/tests/adapters/date_time_adapter_test.dart b/hive/test/tests/adapters/date_time_adapter_test.dart index 1a1db5937..fafe02176 100644 --- a/hive/test/tests/adapters/date_time_adapter_test.dart +++ b/hive/test/tests/adapters/date_time_adapter_test.dart @@ -1,5 +1,5 @@ import 'package:hive/src/adapters/date_time_adapter.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; import '../mocks.dart'; @@ -9,10 +9,10 @@ void main() { test('.read()', () { var now = DateTime.now(); var binaryReader = MockBinaryReader(); - when(binaryReader.readInt()).thenReturn(now.millisecondsSinceEpoch); + when(() => binaryReader.readInt()).thenReturn(now.millisecondsSinceEpoch); var date = DateTimeAdapter().read(binaryReader); - verify(binaryReader.readInt()); + verify(() => binaryReader.readInt()); expect(date, now.subtract(Duration(microseconds: now.microsecond))); }); @@ -21,7 +21,7 @@ void main() { var binaryWriter = MockBinaryWriter(); DateTimeAdapter().write(binaryWriter, now); - verify(binaryWriter.writeInt(now.millisecondsSinceEpoch)); + verify(() => binaryWriter.writeInt(now.millisecondsSinceEpoch)); }); }); @@ -30,22 +30,30 @@ void main() { test('local', () { var now = DateTime.now(); var binaryReader = MockBinaryReader(); - when(binaryReader.readInt()).thenReturn(now.millisecondsSinceEpoch); - when(binaryReader.readBool()).thenReturn(false); + when(() => binaryReader.readInt()) + .thenReturn(now.millisecondsSinceEpoch); + when(() => binaryReader.readBool()).thenReturn(false); var date = DateTimeWithTimezoneAdapter().read(binaryReader); - verifyInOrder([binaryReader.readInt(), binaryReader.readBool()]); + verifyInOrder([ + () => binaryReader.readInt(), + () => binaryReader.readBool(), + ]); expect(date, now.subtract(Duration(microseconds: now.microsecond))); }); test('UTC', () { var now = DateTime.now().toUtc(); var binaryReader = MockBinaryReader(); - when(binaryReader.readInt()).thenReturn(now.millisecondsSinceEpoch); - when(binaryReader.readBool()).thenReturn(true); + when(() => binaryReader.readInt()) + .thenReturn(now.millisecondsSinceEpoch); + when(() => binaryReader.readBool()).thenReturn(true); var date = DateTimeWithTimezoneAdapter().read(binaryReader); - verifyInOrder([binaryReader.readInt(), binaryReader.readBool()]); + verifyInOrder([ + () => binaryReader.readInt(), + () => binaryReader.readBool(), + ]); expect(date, now.subtract(Duration(microseconds: now.microsecond))); expect(date.isUtc, true); }); @@ -58,8 +66,8 @@ void main() { DateTimeWithTimezoneAdapter().write(binaryWriter, now); verifyInOrder([ - binaryWriter.writeInt(now.millisecondsSinceEpoch), - binaryWriter.writeBool(false), + () => binaryWriter.writeInt(now.millisecondsSinceEpoch), + () => binaryWriter.writeBool(false), ]); }); @@ -69,8 +77,8 @@ void main() { DateTimeWithTimezoneAdapter().write(binaryWriter, now); verifyInOrder([ - binaryWriter.writeInt(now.millisecondsSinceEpoch), - binaryWriter.writeBool(true), + () => binaryWriter.writeInt(now.millisecondsSinceEpoch), + () => binaryWriter.writeBool(true), ]); }); }); diff --git a/hive/test/tests/adapters/ignored_type_adapter_test.dart b/hive/test/tests/adapters/ignored_type_adapter_test.dart index e590babf6..e8a85ded4 100644 --- a/hive/test/tests/adapters/ignored_type_adapter_test.dart +++ b/hive/test/tests/adapters/ignored_type_adapter_test.dart @@ -1,5 +1,5 @@ import 'package:hive/src/adapters/ignored_type_adapter.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; import '../mocks.dart'; @@ -9,14 +9,14 @@ void main() { test('.read()', () { var binaryReader = MockBinaryReader(); var value = IgnoredTypeAdapter().read(binaryReader); - verifyNever(binaryReader.read()); + verifyNever(() => binaryReader.read()); expect(value, null); }); test('.write()', () { var binaryWriter = MockBinaryWriter(); IgnoredTypeAdapter().write(binaryWriter, 42); - verifyNever(binaryWriter.writeInt(42)); + verifyNever(() => binaryWriter.writeInt(42)); }); }); } diff --git a/hive/test/tests/backend/vm/backend_manager_test.dart b/hive/test/tests/backend/vm/backend_manager_test.dart index e16d4a845..f08023346 100644 --- a/hive/test/tests/backend/vm/backend_manager_test.dart +++ b/hive/test/tests/backend/vm/backend_manager_test.dart @@ -1,8 +1,8 @@ @TestOn('vm') import 'package:hive/src/backend/vm/backend_manager.dart'; -import 'package:test/test.dart'; import 'package:path/path.dart' as path; +import 'package:test/test.dart'; import '../../common.dart'; diff --git a/hive/test/tests/backend/vm/storage_backend_vm_test.dart b/hive/test/tests/backend/vm/storage_backend_vm_test.dart index d0061c751..ae9e93a4a 100644 --- a/hive/test/tests/backend/vm/storage_backend_vm_test.dart +++ b/hive/test/tests/backend/vm/storage_backend_vm_test.dart @@ -1,5 +1,4 @@ @TestOn('vm') - import 'dart:io'; import 'dart:typed_data'; @@ -10,12 +9,11 @@ import 'package:hive/src/binary/binary_writer_impl.dart'; import 'package:hive/src/binary/frame.dart'; import 'package:hive/src/io/frame_io_helper.dart'; import 'package:hive/src/registry/type_registry_impl.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; import '../../common.dart'; import '../../frames.dart'; - import '../../mocks.dart'; const testMap = { @@ -63,6 +61,11 @@ StorageBackendVm _getBackend({ } void main() { + setUpAll(() { + registerFallbackValue(KeystoreFake()); + registerFallbackValue(TypeRegistryFake()); + }); + group('StorageBackendVm', () { test('.path returns path for of open box file', () { var file = File('some/path'); @@ -80,10 +83,10 @@ void main() { var file = MockFile(); var readRaf = MockRandomAccessFile(); var writeRaf = MockRandomAccessFile(); - when(file.open()).thenAnswer((i) => Future.value(readRaf)); - when(file.open(mode: FileMode.writeOnlyAppend)) + when(() => file.open()).thenAnswer((i) => Future.value(readRaf)); + when(() => file.open(mode: FileMode.writeOnlyAppend)) .thenAnswer((i) => Future.value(writeRaf)); - when(writeRaf.length()).thenAnswer((_) => Future.value(0)); + when(() => writeRaf.length()).thenAnswer((_) => Future.value(0)); var backend = _getBackend(file: file); await backend.open(); @@ -95,10 +98,10 @@ void main() { var file = MockFile(); var writeFile = MockRandomAccessFile(); var readRaf = MockRandomAccessFile(); - when(file.open(mode: FileMode.writeOnlyAppend)) + when(() => file.open(mode: FileMode.writeOnlyAppend)) .thenAnswer((i) => Future.value(writeFile)); - when(file.open()).thenAnswer((i) => Future.value(readRaf)); - when(writeFile.length()).thenAnswer((i) => Future.value(123)); + when(() => file.open()).thenAnswer((i) => Future.value(readRaf)); + when(() => writeFile.length()).thenAnswer((i) => Future.value(123)); var backend = _getBackend(file: file); await backend.open(); @@ -109,19 +112,24 @@ void main() { group('.initialize()', () { File getLockFile() { var lockMockFile = MockFile(); - when(lockMockFile.open(mode: FileMode.write)) + when(() => lockMockFile.open(mode: FileMode.write)) .thenAnswer((i) => Future.value(MockRandomAccessFile())); return lockMockFile; } FrameIoHelper getFrameIoHelper(int recoveryOffset) { var helper = MockFrameIoHelper(); - when(helper.framesFromFile(any, any, any, any)).thenAnswer((i) { - return Future.value(recoveryOffset); - }); - when(helper.keysFromFile(any, any, any)).thenAnswer((i) { - return Future.value(recoveryOffset); - }); + when(() => helper.framesFromFile( + any(), + any(), + any(), + any(), + )).thenAnswer((i) => Future.value(recoveryOffset)); + when(() => helper.keysFromFile( + any(), + any(), + any(), + )).thenAnswer((i) => Future.value(recoveryOffset)); return helper; } @@ -129,19 +137,19 @@ void main() { test('opens lock file and acquires lock', () async { var lockFile = MockFile(); var lockRaf = MockRandomAccessFile(); - when(lockFile.open(mode: FileMode.write)) + when(() => lockFile.open(mode: FileMode.write)) .thenAnswer((i) => Future.value(lockRaf)); - when(lockRaf.lock()).thenAnswer((i) => Future.value(lockRaf)); + when(() => lockRaf.lock()).thenAnswer((i) => Future.value(lockRaf)); var backend = _getBackend( lockFile: lockFile, ioHelper: getFrameIoHelper(-1), ); - when(backend.path).thenReturn('nullPath'); + when(() => backend.path).thenReturn('nullPath'); await backend.initialize( TypeRegistryImpl.nullImpl, MockKeystore(), lazy); - verify(lockRaf.lock()); + verify(() => lockRaf.lock()); }); test('recoveryOffset with crash recovery', () async { @@ -155,15 +163,16 @@ void main() { crashRecovery: true, writeRaf: writeRaf, ); - when(backend.path).thenReturn('nullPath'); - when(lockFile.open(mode: FileMode.write)) + when(() => backend.path).thenReturn('nullPath'); + when(() => lockFile.open(mode: FileMode.write)) .thenAnswer((i) => Future.value(lockRaf)); - when(lockRaf.lock()).thenAnswer((i) => Future.value(lockRaf)); - when(writeRaf.truncate(20)).thenAnswer((i) => Future.value(writeRaf)); + when(() => lockRaf.lock()).thenAnswer((i) => Future.value(lockRaf)); + when(() => writeRaf.truncate(20)) + .thenAnswer((i) => Future.value(writeRaf)); await backend.initialize( TypeRegistryImpl.nullImpl, MockKeystore(), lazy); - verify(writeRaf.truncate(20)); + verify(() => writeRaf.truncate(20)); }); test('recoveryOffset without crash recovery', () async { @@ -175,10 +184,10 @@ void main() { ioHelper: getFrameIoHelper(20), crashRecovery: false, ); - when(backend.path).thenReturn('nullPath'); - when(lockFile.open(mode: FileMode.write)) + when(() => backend.path).thenReturn('nullPath'); + when(() => lockFile.open(mode: FileMode.write)) .thenAnswer((i) => Future.value(lockRaf)); - when(lockRaf.lock()).thenAnswer((i) => Future.value(lockRaf)); + when(() => lockRaf.lock()).thenAnswer((i) => Future.value(lockRaf)); await expectLater( () => backend.initialize( @@ -236,8 +245,9 @@ void main() { var bytes = getFrameBytes(frames); var writeRaf = MockRandomAccessFile(); - when(writeRaf.setPosition(0)).thenAnswer((i) => Future.value(writeRaf)); - when(writeRaf.writeFrom(bytes)) + when(() => writeRaf.setPosition(0)) + .thenAnswer((i) => Future.value(writeRaf)); + when(() => writeRaf.writeFrom(bytes)) .thenAnswer((i) => Future.value(writeRaf)); var backend = _getBackend(writeRaf: writeRaf) @@ -247,15 +257,17 @@ void main() { ..registry = TypeRegistryImpl.nullImpl; await backend.writeFrames(frames); - verify(writeRaf.writeFrom(bytes)); + verify(() => writeRaf.writeFrom(bytes)); }); test('updates offsets', () async { var frames = [Frame('key1', 'value'), Frame('key2', null)]; var writeRaf = MockRandomAccessFile(); - when(writeRaf.setPosition(5)).thenAnswer((i) => Future.value(writeRaf)); - when(writeRaf.writeFrom(any)).thenAnswer((i) => Future.value(writeRaf)); + when(() => writeRaf.setPosition(5)) + .thenAnswer((i) => Future.value(writeRaf)); + when(() => writeRaf.writeFrom(any())) + .thenAnswer((i) => Future.value(writeRaf)); var backend = _getBackend(writeRaf: writeRaf) // The registry needs to be initialized before writing values, and @@ -274,7 +286,7 @@ void main() { test('resets writeOffset on error', () async { var writeRaf = MockRandomAccessFile(); - when(writeRaf.writeFrom(any)).thenThrow('error'); + when(() => writeRaf.writeFrom(any())).thenThrow('error'); var backend = _getBackend(writeRaf: writeRaf) // The registry needs to be initialized before writing values, and // because we do not call StorageBackendVM.initialize(), we set it @@ -284,7 +296,7 @@ void main() { await expectLater(() => backend.writeFrames([Frame('key1', 'value')]), throwsA(anything)); - verify(writeRaf.setPosition(123)); + verify(() => writeRaf.setPosition(123)); expect(backend.writeOffset, 123); }); }); @@ -357,14 +369,16 @@ void main() { test('.clear()', () async { var writeRaf = MockRandomAccessFile(); - when(writeRaf.truncate(0)).thenAnswer((i) => Future.value(writeRaf)); - when(writeRaf.setPosition(0)).thenAnswer((i) => Future.value(writeRaf)); + when(() => writeRaf.truncate(0)) + .thenAnswer((i) => Future.value(writeRaf)); + when(() => writeRaf.setPosition(0)) + .thenAnswer((i) => Future.value(writeRaf)); var backend = _getBackend(writeRaf: writeRaf); backend.writeOffset = 111; await backend.clear(); - verify(writeRaf.truncate(0)); - verify(writeRaf.setPosition(0)); + verify(() => writeRaf.truncate(0)); + verify(() => writeRaf.setPosition(0)); expect(backend.writeOffset, 0); }); @@ -374,10 +388,10 @@ void main() { var lockRaf = MockRandomAccessFile(); var lockFile = MockFile(); - returnFutureVoid(when(readRaf.close())); - returnFutureVoid(when(writeRaf.close())); - returnFutureVoid(when(lockRaf.close())); - when(lockFile.delete()).thenAnswer((i) => Future.value(lockFile)); + returnFutureVoid(when(() => readRaf.close())); + returnFutureVoid(when(() => writeRaf.close())); + returnFutureVoid(when(() => lockRaf.close())); + when(() => lockFile.delete()).thenAnswer((i) => Future.value(lockFile)); var backend = _getBackend( lockFile: lockFile, @@ -388,10 +402,10 @@ void main() { await backend.close(); verifyInOrder([ - readRaf.close(), - writeRaf.close(), - lockRaf.close(), - lockFile.delete(), + () => readRaf.close(), + () => writeRaf.close(), + () => lockRaf.close(), + () => lockFile.delete(), ]); }); @@ -402,11 +416,11 @@ void main() { var lockFile = MockFile(); var file = MockFile(); - returnFutureVoid(when(readRaf.close())); - returnFutureVoid(when(writeRaf.close())); - returnFutureVoid(when(lockRaf.close())); - when(lockFile.delete()).thenAnswer((i) => Future.value(lockFile)); - when(file.delete()).thenAnswer((i) => Future.value(file)); + returnFutureVoid(when(() => readRaf.close())); + returnFutureVoid(when(() => writeRaf.close())); + returnFutureVoid(when(() => lockRaf.close())); + when(() => lockFile.delete()).thenAnswer((i) => Future.value(lockFile)); + when(() => file.delete()).thenAnswer((i) => Future.value(file)); var backend = _getBackend( file: file, @@ -418,11 +432,11 @@ void main() { await backend.deleteFromDisk(); verifyInOrder([ - readRaf.close(), - writeRaf.close(), - lockRaf.close(), - lockFile.delete(), - file.delete() + () => readRaf.close(), + () => writeRaf.close(), + () => lockRaf.close(), + () => lockFile.delete(), + () => file.delete() ]); }); }); diff --git a/hive/test/tests/binary/binary_writer_test.dart b/hive/test/tests/binary/binary_writer_test.dart index 3e5e4c1b1..1c3f03ccb 100644 --- a/hive/test/tests/binary/binary_writer_test.dart +++ b/hive/test/tests/binary/binary_writer_test.dart @@ -5,7 +5,7 @@ import 'package:hive/src/binary/binary_writer_impl.dart'; import 'package:hive/src/binary/frame.dart'; import 'package:hive/src/object/hive_object.dart'; import 'package:hive/src/registry/type_registry_impl.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; import '../frames.dart'; @@ -353,7 +353,7 @@ void main() { group('.writeHiveList()', () { var box = MockBox(); - when(box.name).thenReturn('Box'); + when(() => box.name).thenReturn('Box'); var obj = TestHiveObject()..init('key', box); @@ -458,7 +458,7 @@ void main() { test('HiveList', () { var box = MockBox(); - when(box.name).thenReturn('Box'); + when(() => box.name).thenReturn('Box'); var obj = TestHiveObject()..init('key', box); var list = HiveList(box, objects: [obj]); diff --git a/hive/test/tests/box/box_base_test.dart b/hive/test/tests/box/box_base_test.dart index c9df1fac3..6c881aec0 100644 --- a/hive/test/tests/box/box_base_test.dart +++ b/hive/test/tests/box/box_base_test.dart @@ -6,7 +6,7 @@ import 'package:hive/src/box/box_base_impl.dart'; import 'package:hive/src/box/change_notifier.dart'; import 'package:hive/src/box/keystore.dart'; import 'package:hive/src/hive_impl.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; import '../common.dart'; @@ -26,20 +26,6 @@ class _BoxBaseMock extends BoxBaseImpl with Mock { compactionStrategy, backend, ); - - @override - Future putAll(Map entries) => - (super.noSuchMethod(Invocation.method(#putAll, [entries]), Future.value()) - as Future); - - @override - Future deleteAll(Iterable keys) => - (super.noSuchMethod(Invocation.method(#deleteAll, [keys]), Future.value()) - as Future); - - @override - bool get lazy => - (super.noSuchMethod(Invocation.getter(#lazy), false) as bool); } _BoxBaseMock _openBoxBaseMock({ @@ -64,6 +50,11 @@ _BoxBaseMock _openBoxBaseMock({ } void main() { + setUpAll(() { + registerFallbackValue(KeystoreFake()); + registerFallbackValue(TypeRegistryFake()); + }); + group('BoxBase', () { test('.name', () { var box = _openBoxBaseMock(name: 'testName'); @@ -72,7 +63,7 @@ void main() { test('.path', () { var backend = MockStorageBackend(); - when(backend.path).thenReturn('some/path'); + when(() => backend.path).thenReturn('some/path'); var box = _openBoxBaseMock(backend: backend); expect(box.path, 'some/path'); @@ -90,7 +81,7 @@ void main() { test('throws if box is closed', () async { var backend = MockStorageBackend(); - returnFutureVoid(when(backend.close())); + returnFutureVoid(when(() => backend.close())); var box = _openBoxBaseMock(backend: backend); await box.close(); @@ -119,7 +110,7 @@ void main() { test('throws if box is closed', () async { var backend = MockStorageBackend(); - returnFutureVoid(when(backend.close())); + returnFutureVoid(when(() => backend.close())); var box = _openBoxBaseMock(backend: backend); await box.close(); @@ -133,15 +124,15 @@ void main() { test('calls keystore.watch()', () { var keystore = MockKeystore(); var box = _openBoxBaseMock(keystore: keystore); - when(keystore.watch(key: 123)).thenAnswer((_) => Stream.empty()); + when(() => keystore.watch(key: 123)).thenAnswer((_) => Stream.empty()); box.watch(key: 123); - verify(keystore.watch(key: 123)); + verify(() => keystore.watch(key: 123)); }); test('throws if box is closed', () async { var backend = MockStorageBackend(); - returnFutureVoid(when(backend.close())); + returnFutureVoid(when(() => backend.close())); var box = _openBoxBaseMock(backend: backend); await box.close(); @@ -152,13 +143,15 @@ void main() { group('.keyAt()', () { test('returns key at index', () { var box = _openBoxBaseMock(); - box.keystore..insert(Frame.lazy(0))..insert(Frame.lazy('test')); + box.keystore + ..insert(Frame.lazy(0)) + ..insert(Frame.lazy('test')); expect(box.keyAt(1), 'test'); }); test('throws if box is closed', () async { var backend = MockStorageBackend(); - returnFutureVoid(when(backend.close())); + returnFutureVoid(when(() => backend.close())); var box = _openBoxBaseMock(backend: backend); await box.close(); @@ -169,9 +162,9 @@ void main() { test('.initialize()', () async { var backend = MockStorageBackend(); var box = _openBoxBaseMock(backend: backend); - when(box.lazy).thenReturn(false); + when(() => box.lazy).thenReturn(false); - when(backend.initialize(any, any, any)).thenAnswer((i) async { + when(() => backend.initialize(any(), any(), any())).thenAnswer((i) async { i.positionalArguments[1].insert(Frame('key1', 1)); }); @@ -204,7 +197,7 @@ void main() { test('throws if box is closed', () async { var backend = MockStorageBackend(); - returnFutureVoid(when(backend.close())); + returnFutureVoid(when(() => backend.close())); var box = _openBoxBaseMock(backend: backend); await box.close(); @@ -215,15 +208,15 @@ void main() { group('.add()', () { test('calls put()', () async { var box = _openBoxBaseMock(); - when(box.put(0, 123)).thenAnswer((i) => Future.value(0)); + when(() => box.put(0, 123)).thenAnswer((i) => Future.value()); expect(await box.add(123), 0); - verify(box.put(0, 123)); + verify(() => box.put(0, 123)); }); test('updates auto increment', () async { var box = _openBoxBaseMock(); - returnFutureVoid(when(box.putAll({5: 123}))); + returnFutureVoid(when(() => box.putAll({5: 123}))); box.keystore.updateAutoIncrement(4); expect(await box.add(123), 5); @@ -234,23 +227,23 @@ void main() { var box = _openBoxBaseMock(); box.keystore.updateAutoIncrement(4); final vals = {5: 1, 6: 2, 7: 3}; - returnFutureVoid(when(box.putAll(vals))); + returnFutureVoid(when(() => box.putAll(vals))); expect(await box.addAll([1, 2, 3]), [5, 6, 7]); expect(box.keystore.autoIncrement(), 8); - verify(box.putAll(vals)); + verify(() => box.putAll(vals)); }); group('.putAt()', () { test('override existing', () async { var box = _openBoxBaseMock(); - returnFutureVoid(when(box.putAll({'b': 'test'}))); + returnFutureVoid(when(() => box.putAll({'b': 'test'}))); box.keystore.insert(Frame.lazy('a')); box.keystore.insert(Frame.lazy('b')); await box.putAt(1, 'test'); - verify(box.put('b', 'test')); + verify(() => box.put('b', 'test')); }); test('throws RangeError for negative index', () async { @@ -273,13 +266,13 @@ void main() { group('.deleteAt()', () { test('delete frame', () async { var box = _openBoxBaseMock(); - returnFutureVoid(when(box.deleteAll(['b']))); + returnFutureVoid(when(() => box.deleteAll(['b']))); box.keystore.insert(Frame.lazy('a')); box.keystore.insert(Frame.lazy('b')); await box.deleteAt(1); - verify(box.delete('b')); + verify(() => box.delete('b')); }); test('throws RangeError for negative index', () async { @@ -302,21 +295,21 @@ void main() { var backend = MockStorageBackend(); var keystore = MockKeystore(); - returnFutureVoid(when(backend.clear())); - when(keystore.clear()).thenReturn(2); + returnFutureVoid(when(() => backend.clear())); + when(() => keystore.clear()).thenReturn(2); var box = _openBoxBaseMock(backend: backend, keystore: keystore); expect(await box.clear(), 2); verifyInOrder([ - backend.clear(), - keystore.clear(), + () => backend.clear(), + () => keystore.clear(), ]); }); test('throws if box is closed', () async { var backend = MockStorageBackend(); - returnFutureVoid(when(backend.close())); + returnFutureVoid(when(() => backend.close())); var box = _openBoxBaseMock(backend: backend); await box.close(); @@ -327,22 +320,22 @@ void main() { group('.compact()', () { test('does nothing if backend does not support compaction', () async { var backend = MockStorageBackend(); - when(backend.supportsCompaction).thenReturn(false); + when(() => backend.supportsCompaction).thenReturn(false); var box = _openBoxBaseMock(backend: backend); await box.compact(); - verify(backend.supportsCompaction); + verify(() => backend.supportsCompaction); verifyNoMoreInteractions(backend); }); test('does nothing if there are no deleted entries', () async { var backend = MockStorageBackend(); - when(backend.supportsCompaction).thenReturn(true); + when(() => backend.supportsCompaction).thenReturn(true); var box = _openBoxBaseMock(backend: backend); box.keystore.insert(Frame.lazy('key1')); await box.compact(); - verify(backend.supportsCompaction); + verify(() => backend.supportsCompaction); verifyNoMoreInteractions(backend); }); @@ -350,25 +343,27 @@ void main() { var backend = MockStorageBackend(); var keystore = MockKeystore(); - when(keystore.frames) + when(() => keystore.frames) .thenReturn([Frame('key', 1, length: 22, offset: 33)]); - when(backend.supportsCompaction).thenReturn(true); + when(() => backend.supportsCompaction).thenReturn(true); // In case it is 0, we will bail out before compaction - when(keystore.deletedEntries).thenReturn(1); + when(() => keystore.deletedEntries).thenReturn(1); returnFutureVoid( - when(backend.compact([Frame('key', 1, length: 22, offset: 33)])), + when( + () => backend.compact([Frame('key', 1, length: 22, offset: 33)])), ); var box = _openBoxBaseMock(backend: backend, keystore: keystore); await box.compact(); - verify(backend.compact([Frame('key', 1, length: 22, offset: 33)])); - verify(keystore.resetDeletedEntries()); + verify( + () => backend.compact([Frame('key', 1, length: 22, offset: 33)])); + verify(() => keystore.resetDeletedEntries()); }); test('throws if box is closed', () async { var backend = MockStorageBackend(); - returnFutureVoid(when(backend.close())); + returnFutureVoid(when(() => backend.close())); var box = _openBoxBaseMock(backend: backend); await box.close(); @@ -386,14 +381,14 @@ void main() { keystore: keystore, backend: backend, ); - returnFutureVoid(when(keystore.close())); - returnFutureVoid(when(backend.close())); + returnFutureVoid(when(() => keystore.close())); + returnFutureVoid(when(() => backend.close())); await box.close(); verifyInOrder([ - keystore.close(), - hive.unregisterBox('myBox'), - backend.close(), + () => keystore.close(), + () => hive.unregisterBox('myBox'), + () => backend.close(), ]); expect(box.isOpen, false); }); @@ -403,14 +398,14 @@ void main() { var backend = MockStorageBackend(); var keystore = MockKeystore(); var box = _openBoxBaseMock(backend: backend, keystore: keystore); - returnFutureVoid(when(keystore.close())); - returnFutureVoid(when(backend.close())); - returnFutureVoid(when(backend.deleteFromDisk())); + returnFutureVoid(when(() => keystore.close())); + returnFutureVoid(when(() => backend.close())); + returnFutureVoid(when(() => backend.deleteFromDisk())); await box.close(); await box.deleteFromDisk(); - verify(backend.deleteFromDisk()); + verify(() => backend.deleteFromDisk()); }); test('closes and deletes box', () async { @@ -423,15 +418,15 @@ void main() { keystore: keystore, backend: backend, ); - returnFutureVoid(when(keystore.close())); - returnFutureVoid(when(backend.close())); - returnFutureVoid(when(backend.deleteFromDisk())); + returnFutureVoid(when(() => keystore.close())); + returnFutureVoid(when(() => backend.close())); + returnFutureVoid(when(() => backend.deleteFromDisk())); await box.deleteFromDisk(); verifyInOrder([ - keystore.close(), - hive.unregisterBox('myBox'), - backend.deleteFromDisk(), + () => keystore.close(), + () => hive.unregisterBox('myBox'), + () => backend.deleteFromDisk(), ]); expect(box.isOpen, false); }); diff --git a/hive/test/tests/box/box_impl_test.dart b/hive/test/tests/box/box_impl_test.dart index 0ad8fcab6..7cd2d297b 100644 --- a/hive/test/tests/box/box_impl_test.dart +++ b/hive/test/tests/box/box_impl_test.dart @@ -5,7 +5,7 @@ import 'package:hive/src/box/box_impl.dart'; import 'package:hive/src/box/change_notifier.dart'; import 'package:hive/src/box/keystore.dart'; import 'package:hive/src/hive_impl.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; import '../common.dart'; import '../mocks.dart'; @@ -95,13 +95,13 @@ void main() { var backend = MockStorageBackend(); var keystore = MockKeystore(); - when(keystore.frames).thenReturn(keystoreFrames); - when(keystore.beginTransaction(any)).thenReturn(true); - returnFutureVoid(when(backend.writeFrames(frames))); - returnFutureVoid(when(backend.compact(keystoreFrames))); - when(backend.supportsCompaction).thenReturn(true); - when(keystore.length).thenReturn(-1); - when(keystore.deletedEntries).thenReturn(-1); + when(() => keystore.frames).thenReturn(keystoreFrames); + when(() => keystore.beginTransaction(any())).thenReturn(true); + returnFutureVoid(when(() => backend.writeFrames(frames))); + returnFutureVoid(when(() => backend.compact(keystoreFrames))); + when(() => backend.supportsCompaction).thenReturn(true); + when(() => keystore.length).thenReturn(-1); + when(() => keystore.deletedEntries).thenReturn(-1); var box = _getBox( keystore: keystore, @@ -111,22 +111,22 @@ void main() { await box.putAll({'key1': 'value1', 'key2': 'value2'}); verifyInOrder([ - keystore.beginTransaction(frames), - backend.writeFrames(frames), - keystore.commitTransaction(), - backend.compact([Frame('keystoreFrames', 123)]), + () => keystore.beginTransaction(frames), + () => backend.writeFrames(frames), + () => keystore.commitTransaction(), + () => backend.compact([Frame('keystoreFrames', 123)]), ]); }); test('does nothing if no frames are provided', () async { var backend = MockStorageBackend(); var keystore = MockKeystore(); - when(keystore.beginTransaction([])).thenReturn(false); + when(() => keystore.beginTransaction([])).thenReturn(false); var box = _getBox(backend: backend, keystore: keystore); await box.putAll({}); - verify(keystore.beginTransaction([])); + verify(() => keystore.beginTransaction([])); verifyZeroInteractions(backend); }); @@ -134,8 +134,8 @@ void main() { var backend = MockStorageBackend(); var keystore = MockKeystore(); - when(backend.writeFrames(any)).thenThrow('Some error'); - when(keystore.beginTransaction(any)).thenReturn(true); + when(() => backend.writeFrames(any())).thenThrow('Some error'); + when(() => keystore.beginTransaction(any())).thenReturn(true); var box = _getBox(backend: backend, keystore: keystore); @@ -145,9 +145,9 @@ void main() { ); var frames = [Frame('key1', 'value1'), Frame('key2', 'value2')]; verifyInOrder([ - keystore.beginTransaction(frames), - backend.writeFrames(frames), - keystore.cancelTransaction(), + () => keystore.beginTransaction(frames), + () => backend.writeFrames(frames), + () => keystore.cancelTransaction(), ]); }); }); @@ -159,10 +159,10 @@ void main() { var backend = MockStorageBackend(); var keystore = MockKeystore(); var box = _getBox(backend: backend, keystore: keystore); - when(keystore.frames).thenReturn(frames); - when(keystore.containsKey(any)).thenReturn(false); - returnFutureVoid(when(backend.compact(frames))); - when(keystore.beginTransaction(frames)).thenReturn(false); + when(() => keystore.frames).thenReturn(frames); + when(() => keystore.containsKey(any())).thenReturn(false); + returnFutureVoid(when(() => backend.compact(frames))); + when(() => keystore.beginTransaction(frames)).thenReturn(false); await box.deleteAll(['key1', 'key2', 'key3']); verifyZeroInteractions(backend); @@ -173,14 +173,14 @@ void main() { var backend = MockStorageBackend(); var keystore = MockKeystore(); - when(backend.supportsCompaction).thenReturn(true); - when(keystore.beginTransaction(any)).thenReturn(true); - returnFutureVoid(when(backend.writeFrames(frames))); - when(keystore.containsKey(any)).thenReturn(true); - when(keystore.length).thenReturn(-1); - when(keystore.deletedEntries).thenReturn(-1); - when(keystore.frames).thenReturn(frames); - returnFutureVoid(when(backend.compact(frames))); + when(() => backend.supportsCompaction).thenReturn(true); + when(() => keystore.beginTransaction(any())).thenReturn(true); + returnFutureVoid(when(() => backend.writeFrames(frames))); + when(() => keystore.containsKey(any())).thenReturn(true); + when(() => keystore.length).thenReturn(-1); + when(() => keystore.deletedEntries).thenReturn(-1); + when(() => keystore.frames).thenReturn(frames); + returnFutureVoid(when(() => backend.compact(frames))); var box = _getBox( backend: backend, @@ -190,12 +190,12 @@ void main() { await box.deleteAll(['key1', 'key2']); verifyInOrder([ - keystore.containsKey('key1'), - keystore.containsKey('key2'), - keystore.beginTransaction(frames), - backend.writeFrames(frames), - keystore.commitTransaction(), - backend.compact(any), + () => keystore.containsKey('key1'), + () => keystore.containsKey('key2'), + () => keystore.beginTransaction(frames), + () => backend.writeFrames(frames), + () => keystore.commitTransaction(), + () => backend.compact(any()), ]); }); }); diff --git a/hive/test/tests/box/change_notifier_test.dart b/hive/test/tests/box/change_notifier_test.dart index f814e2da0..1a8686ecb 100644 --- a/hive/test/tests/box/change_notifier_test.dart +++ b/hive/test/tests/box/change_notifier_test.dart @@ -3,17 +3,12 @@ import 'dart:async'; import 'package:hive/hive.dart'; import 'package:hive/src/binary/frame.dart'; import 'package:hive/src/box/change_notifier.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; import '../common.dart'; -class StreamControllerMock extends Mock implements StreamController { - @override - Future close() => - (super.noSuchMethod(Invocation.method(#close, []), Future.value()) - as Future); -} +class StreamControllerMock extends Mock implements StreamController {} void main() { group('ChangeNotifier', () { @@ -50,11 +45,11 @@ void main() { test('close', () async { var controller = StreamControllerMock(); - returnFutureVoid(when(controller.close())); + returnFutureVoid(when(() => controller.close())); var notifier = ChangeNotifier.debug(controller); await notifier.close(); - verify(controller.close()); + verify(() => controller.close()); }); }); } diff --git a/hive/test/tests/box/keystore_test.dart b/hive/test/tests/box/keystore_test.dart index 6325270c3..0bfdb9d3b 100644 --- a/hive/test/tests/box/keystore_test.dart +++ b/hive/test/tests/box/keystore_test.dart @@ -1,6 +1,6 @@ import 'package:hive/src/binary/frame.dart'; import 'package:hive/src/box/keystore.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; import '../mocks.dart'; @@ -252,10 +252,10 @@ void main() { var keystore = Keystore.debug(notifier: notifier); keystore.insert(Frame('key1', 'val1')); - verify(notifier.notify(Frame('key1', 'val1'))); + verify(() => notifier.notify(Frame('key1', 'val1'))); keystore.insert(Frame('key1', 'val2')); - verify(notifier.notify(Frame('key1', 'val2'))); + verify(() => notifier.notify(Frame('key1', 'val2'))); }); }); @@ -307,7 +307,7 @@ void main() { reset(notifier); keystore.insert(Frame.deleted('key1')); - verify(notifier.notify(Frame.deleted('key1'))); + verify(() => notifier.notify(Frame.deleted('key1'))); keystore.insert(Frame.deleted('key1')); verifyNoMoreInteractions(notifier); @@ -328,8 +328,8 @@ void main() { expect(created, true); expect(keystore.transactions.first.added, ['key1', 'key2']); expect(keystore.frames, [Frame('key1', 'val1'), Frame('key2', 'val2')]); - verify(notifier.notify(Frame('key1', 'val1'))); - verify(notifier.notify(Frame('key2', 'val2'))); + verify(() => notifier.notify(Frame('key1', 'val1'))); + verify(() => notifier.notify(Frame('key2', 'val2'))); }); test('overriding existing keys', () { @@ -350,8 +350,8 @@ void main() { 'key1': Frame('key1', 'val1'), }); expect(keystore.frames, [Frame('key1', 'val2'), Frame('key2', 'val3')]); - verify(notifier.notify(Frame('key1', 'val2'))); - verify(notifier.notify(Frame('key2', 'val3'))); + verify(() => notifier.notify(Frame('key1', 'val2'))); + verify(() => notifier.notify(Frame('key2', 'val3'))); }); test('empty transaction', () { @@ -390,7 +390,7 @@ void main() { 'key1': Frame('key1', 'val1'), }); expect(keystore.frames, [Frame('key2', 'val2')]); - verify(notifier.notify(Frame.deleted('key1'))); + verify(() => notifier.notify(Frame.deleted('key1'))); }); }); @@ -429,7 +429,7 @@ void main() { keystore.transactions, [KeyTransaction()..added.add('otherKey')], ); - verify(notifier.notify(Frame.deleted('key'))); + verify(() => notifier.notify(Frame.deleted('key'))); }); test('add then override', () { @@ -482,7 +482,7 @@ void main() { keystore.cancelTransaction(); expect(keystore.frames, [Frame('key', 'val1')]); expectTrx(keystore.transactions, []); - verify(notifier.notify(Frame('key', 'val1'))); + verify(() => notifier.notify(Frame('key', 'val1'))); }); test('override then add', () { @@ -535,7 +535,7 @@ void main() { keystore.cancelTransaction(); expect(keystore.frames, [Frame('key', 'val1')]); expectTrx(keystore.transactions, []); - verify(notifier.notify(Frame('key', 'val1'))); + verify(() => notifier.notify(Frame('key', 'val1'))); }); test('delete then add', () { @@ -612,8 +612,8 @@ void main() { reset(notifier); keystore.clear(); - verify(notifier.notify(Frame.deleted('key1'))); - verify(notifier.notify(Frame.deleted('key2'))); + verify(() => notifier.notify(Frame.deleted('key1'))); + verify(() => notifier.notify(Frame.deleted('key2'))); }); }); }); diff --git a/hive/test/tests/box/lazy_box_impl_test.dart b/hive/test/tests/box/lazy_box_impl_test.dart index 8bce83768..fcf920a9d 100644 --- a/hive/test/tests/box/lazy_box_impl_test.dart +++ b/hive/test/tests/box/lazy_box_impl_test.dart @@ -5,7 +5,7 @@ import 'package:hive/src/box/change_notifier.dart'; import 'package:hive/src/box/keystore.dart'; import 'package:hive/src/box/lazy_box_impl.dart'; import 'package:hive/src/hive_impl.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; import '../common.dart'; @@ -30,6 +30,10 @@ LazyBoxImpl _getBox({ } void main() { + setUpAll(() { + registerFallbackValue(Frame.deleted(0)); + }); + group('LazyBoxImpl', () { group('.get()', () { test('returns defaultValue if key does not exist', () async { @@ -43,14 +47,14 @@ void main() { test('reads value from backend', () async { var backend = MockStorageBackend(); - when(backend.readValue(any)).thenAnswer((i) async => 'testVal'); + when(() => backend.readValue(any())).thenAnswer((i) async => 'testVal'); var box = _getBox(backend: backend); var frame = Frame.lazy('testKey', length: 123, offset: 456); box.keystore.insert(frame); expect(await box.get('testKey'), 'testVal'); - verify(backend.readValue(frame)); + verify(() => backend.readValue(frame)); }); }); @@ -60,7 +64,7 @@ void main() { Frame.lazy('a'), ]); var backend = MockStorageBackend(); - when(backend.readValue(any)).thenAnswer((i) { + when(() => backend.readValue(any())).thenAnswer((i) { return Future.value('A'); }); var box = _getBox(keystore: keystore, backend: backend); @@ -72,10 +76,10 @@ void main() { test('values', () async { var backend = MockStorageBackend(); var keystore = MockKeystore(); - when(keystore.containsKey(any)).thenReturn(false); - returnFutureVoid(when(backend.writeFrames(any))); - when(keystore.length).thenReturn(-1); - when(keystore.deletedEntries).thenReturn(-1); + when(() => keystore.containsKey(any())).thenReturn(false); + returnFutureVoid(when(() => backend.writeFrames(any()))); + when(() => keystore.length).thenReturn(-1); + when(() => keystore.deletedEntries).thenReturn(-1); var box = _getBox( backend: backend, @@ -84,12 +88,12 @@ void main() { await box.putAll({'key1': 'value1', 'key2': 'value2'}); verifyInOrder([ - backend.writeFrames([ - Frame('key1', 'value1'), - Frame('key2', 'value2'), - ]), - keystore.insert(Frame('key1', 'value1'), lazy: true), - keystore.insert(Frame('key2', 'value2'), lazy: true), + () => backend.writeFrames([ + Frame('key1', 'value1'), + Frame('key2', 'value2'), + ]), + () => keystore.insert(Frame('key1', 'value1'), lazy: true), + () => keystore.insert(Frame('key2', 'value2'), lazy: true), ]); }); @@ -98,8 +102,8 @@ void main() { var keystore = MockKeystore(); final theError = 'Some error'; - when(backend.writeFrames(any)).thenThrow(theError); - when(keystore.containsKey(any)).thenReturn(true); + when(() => backend.writeFrames(any())).thenThrow(theError); + when(() => keystore.containsKey(any())).thenReturn(true); var box = _getBox( backend: backend, @@ -112,12 +116,10 @@ void main() { ), throwsA(theError), ); - verifyInOrder([ - backend.writeFrames([ - Frame('key1', 'value1'), - Frame('key2', 'value2'), - ]), - ]); + verify(() => backend.writeFrames([ + Frame('key1', 'value1'), + Frame('key2', 'value2'), + ])); verifyNoMoreInteractions(keystore); }); }); @@ -126,7 +128,7 @@ void main() { test('does nothing when deleting non existing keys', () async { var backend = MockStorageBackend(); var keystore = MockKeystore(); - when(keystore.containsKey(any)).thenReturn(false); + when(() => keystore.containsKey(any())).thenReturn(false); var box = _getBox( backend: backend, keystore: keystore, @@ -139,10 +141,10 @@ void main() { test('delete keys', () async { var backend = MockStorageBackend(); var keystore = MockKeystore(); - when(keystore.containsKey(any)).thenReturn(true); - returnFutureVoid(when(backend.writeFrames(any))); - when(keystore.length).thenReturn(-1); - when(keystore.deletedEntries).thenReturn(-1); + when(() => keystore.containsKey(any())).thenReturn(true); + returnFutureVoid(when(() => backend.writeFrames(any()))); + when(() => keystore.length).thenReturn(-1); + when(() => keystore.deletedEntries).thenReturn(-1); var box = _getBox( backend: backend, @@ -151,11 +153,12 @@ void main() { await box.deleteAll(['key1', 'key2']); verifyInOrder([ - keystore.containsKey('key1'), - keystore.containsKey('key2'), - backend.writeFrames([Frame.deleted('key1'), Frame.deleted('key2')]), - keystore.insert(Frame.deleted('key1')), - keystore.insert(Frame.deleted('key2')), + () => keystore.containsKey('key1'), + () => keystore.containsKey('key2'), + () => backend + .writeFrames([Frame.deleted('key1'), Frame.deleted('key2')]), + () => keystore.insert(Frame.deleted('key1')), + () => keystore.insert(Frame.deleted('key2')), ]); }); }); diff --git a/hive/test/tests/common.dart b/hive/test/tests/common.dart index b6dfccfdd..457a2a2d8 100644 --- a/hive/test/tests/common.dart +++ b/hive/test/tests/common.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'dart:math'; import 'package:hive/hive.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:path/path.dart' as path; import 'package:test/test.dart'; @@ -112,7 +112,7 @@ Future expectDirEqualsAssetDir(Directory dir1, String part1, return expectDirsEqual(dir1, assetDir); } -void returnFutureVoid(PostExpectation> v) => +void returnFutureVoid(When> v) => v.thenAnswer((i) => Future.value(null)); final bool soundNullSafety = (() { diff --git a/hive/test/tests/io/buffered_file_writer_test.dart b/hive/test/tests/io/buffered_file_writer_test.dart index 405c7afe4..9d2514c86 100644 --- a/hive/test/tests/io/buffered_file_writer_test.dart +++ b/hive/test/tests/io/buffered_file_writer_test.dart @@ -1,6 +1,6 @@ @TestOn('vm') import 'package:hive/src/io/buffered_file_writer.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; import '../mocks.dart'; @@ -15,22 +15,22 @@ void main() { await writer.write([7, 8, 9]); verifyZeroInteractions(file); - when(file.writeFrom(any)).thenAnswer((i) => Future.value(file)); + when(() => file.writeFrom(any())).thenAnswer((i) => Future.value(file)); await writer.write([10]); - verify(file.writeFrom([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])); + verify(() => file.writeFrom([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])); reset(file); await writer.flush(); verifyZeroInteractions(file); - when(file.writeFrom(any)).thenAnswer((i) => Future.value(file)); + when(() => file.writeFrom(any())).thenAnswer((i) => Future.value(file)); await writer.write([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]); - verify(file.writeFrom([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13])); + verify(() => file.writeFrom([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13])); }); test('flush()', () async { var file = MockRandomAccessFile(); - when(file.writeFrom(any)).thenAnswer((i) => Future.value(file)); + when(() => file.writeFrom(any())).thenAnswer((i) => Future.value(file)); var writer = BufferedFileWriter(file, 10); await writer.flush(); @@ -38,7 +38,7 @@ void main() { await writer.write([1, 2, 3]); await writer.flush(); - verify(file.writeFrom([1, 2, 3])); + verify(() => file.writeFrom([1, 2, 3])); await writer.flush(); verifyNoMoreInteractions(file); diff --git a/hive/test/tests/mocks.dart b/hive/test/tests/mocks.dart index b5c32933a..81ae6261d 100644 --- a/hive/test/tests/mocks.dart +++ b/hive/test/tests/mocks.dart @@ -9,26 +9,40 @@ import 'package:hive/src/box/keystore.dart'; import 'package:hive/src/hive_impl.dart'; import 'package:hive/src/io/frame_io_helper.dart'; import 'package:hive/src/object/hive_list_impl.dart'; -import 'package:hive/src/object/hive_object.dart'; -import 'package:mockito/annotations.dart'; - -export 'mocks.mocks.dart'; - -@GenerateMocks([], customMocks: [ - MockSpec(returnNullOnMissingStub: true), - MockSpec(returnNullOnMissingStub: true), - MockSpec(returnNullOnMissingStub: true), - MockSpec(returnNullOnMissingStub: true), - MockSpec(returnNullOnMissingStub: true), - MockSpec(returnNullOnMissingStub: true), - MockSpec(returnNullOnMissingStub: true), - MockSpec(returnNullOnMissingStub: true), - MockSpec(returnNullOnMissingStub: true), - MockSpec(returnNullOnMissingStub: true), - MockSpec(returnNullOnMissingStub: true), - MockSpec(returnNullOnMissingStub: true), -]) -// ignore: prefer_typing_uninitialized_variables, unused_element -var _mocks; +import 'package:mocktail/mocktail.dart'; + +// Mocks + +class MockBox extends Mock implements Box {} + +class MockChangeNotifier extends Mock implements ChangeNotifier {} + +class MockStorageBackend extends Mock implements StorageBackend {} + +class MockKeystore extends Mock implements Keystore {} + +class MockHiveImpl extends Mock implements HiveImpl {} + +class MockHiveList extends Mock implements HiveList {} + +class MockHiveListImpl extends Mock implements HiveListImpl {} + +class MockRandomAccessFile extends Mock implements RandomAccessFile {} + +class MockBinaryReader extends Mock implements BinaryReader {} + +class MockBinaryWriter extends Mock implements BinaryWriter {} + +class MockFile extends Mock implements File {} + +class MockFrameIoHelper extends Mock implements FrameIoHelper {} + +// Fakes + +class KeystoreFake extends Fake implements Keystore {} + +class TypeRegistryFake extends Fake implements TypeRegistry {} + +// Dumb objects class TestHiveObject extends HiveObject {} diff --git a/hive/test/tests/mocks.mocks.dart b/hive/test/tests/mocks.mocks.dart deleted file mode 100644 index 3c514909e..000000000 --- a/hive/test/tests/mocks.mocks.dart +++ /dev/null @@ -1,1284 +0,0 @@ -import 'dart:async' as _i7; -import 'dart:collection' as _i2; -import 'dart:convert' as _i15; -import 'dart:io' as _i6; -import 'dart:io' show File, RandomAccessFile; -import 'dart:typed_data' as _i5; - -import 'package:hive/hive.dart' as _i3; -import 'package:hive/src/backend/storage_backend.dart' as _i10; -import 'package:hive/src/binary/frame.dart' as _i9; -import 'package:hive/src/box/change_notifier.dart' as _i8; -import 'package:hive/src/box/default_compaction_strategy.dart'; -import 'package:hive/src/box/default_key_comparator.dart'; -import 'package:hive/src/box/keystore.dart' as _i11; -import 'package:hive/src/hive_impl.dart' as _i12; -import 'package:hive/src/io/frame_io_helper.dart' as _i16; -import 'package:hive/src/object/hive_list_impl.dart' as _i14; -import 'package:hive/src/object/hive_object.dart' as _i4; -import 'package:hive/src/registry/type_registry_impl.dart' as _i13; -import 'package:mockito/mockito.dart' as _i1; - -// Imports for documentation -import 'package:hive/hive.dart' show Box, HiveList, BinaryReader, BinaryWriter; -import 'package:hive/src/io/frame_io_helper.dart' show FrameIoHelper; -import 'package:hive/src/box/change_notifier.dart' show ChangeNotifier; -import 'package:hive/src/hive_impl.dart' show HiveImpl; -import 'package:hive/src/backend/storage_backend.dart' show StorageBackend; -import 'package:hive/src/object/hive_list_impl.dart'; -import 'package:hive/src/box/keystore.dart' show Keystore; - -class _FakeListQueue extends _i1.Fake implements _i2.ListQueue {} - -class _FakeBox extends _i1.Fake implements _i3.Box {} - -class _FakeLazyBox extends _i1.Fake implements _i3.LazyBox {} - -class _FakeBoxBase extends _i1.Fake implements _i3.BoxBase {} - -class _FakeHiveList extends _i1.Fake - implements _i3.HiveList {} - -class _FakeIterator extends _i1.Fake implements Iterator {} - -class _FakeHiveObject extends _i1.Fake implements _i4.HiveObject {} - -class _FakeUint8List extends _i1.Fake implements _i5.Uint8List {} - -class _FakeRandomAccessFile extends _i1.Fake implements _i6.RandomAccessFile {} - -class _FakeFile extends _i1.Fake implements _i6.File {} - -class _FakeDateTime extends _i1.Fake implements DateTime {} - -class _FakeIOSink extends _i1.Fake implements _i6.IOSink {} - -/// A class which mocks [Box]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockBox extends _i1.Mock implements _i3.Box { - @override - Iterable get values => - (super.noSuchMethod(Invocation.getter(#values), []) as Iterable); - - @override - Iterable valuesBetween({dynamic startKey, dynamic endKey}) => - (super.noSuchMethod( - Invocation.method( - #valuesBetween, [], {#startKey: startKey, #endKey: endKey}), - []) as Iterable); - - @override - E? getAt(int? index) => - (super.noSuchMethod(Invocation.method(#getAt, [index])) as E?); - - @override - Map toMap() => - (super.noSuchMethod(Invocation.method(#toMap, []), {}) - as Map); - - @override - String get name => - (super.noSuchMethod(Invocation.getter(#name), '') as String); - - @override - bool get lazy => - (super.noSuchMethod(Invocation.getter(#lazy), false) as bool); - - @override - Future put(dynamic key, E value) => - (super.noSuchMethod(Invocation.method(#put, [key, value]), Future.value()) - as Future); - - @override - _i7.Future delete(key) => - (super.noSuchMethod(Invocation.method(#delete, [key]), Future.value()) - as Future); - - @override - _i7.Future deleteAll(Iterable keys) => - (super.noSuchMethod(Invocation.method(#deleteAll, [keys]), Future.value()) - as Future); - - @override - bool containsKey(key) => - (super.noSuchMethod(Invocation.method(#containsKey, [key]), false) - as bool); -} - -/// A class which mocks [ChangeNotifier]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockChangeNotifier extends _i1.Mock implements _i8.ChangeNotifier { - @override - void notify(_i9.Frame? frame) => - super.noSuchMethod(Invocation.method(#notify, [frame])); - - @override - _i7.Stream<_i3.BoxEvent> watch({dynamic key}) => (super.noSuchMethod( - Invocation.method(#watch, [], {#key: key}), - Stream<_i3.BoxEvent>.empty()) as _i7.Stream<_i3.BoxEvent>); - - @override - _i7.Future close() => - (super.noSuchMethod(Invocation.method(#close, []), Future.value(null)) - as _i7.Future); -} - -/// A class which mocks [StorageBackend]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockStorageBackend extends _i1.Mock implements _i10.StorageBackend { - @override - bool get supportsCompaction => - (super.noSuchMethod(Invocation.getter(#supportsCompaction), false) - as bool); - - @override - _i7.Future initialize(_i3.TypeRegistry? registry, - _i11.Keystore? keystore, bool? lazy) => - (super.noSuchMethod( - Invocation.method(#initialize, [registry, keystore, lazy]), - Future.value(null)) as _i7.Future); - - @override - _i7.Future readValue(_i9.Frame? frame) => (super.noSuchMethod( - Invocation.method(#readValue, [frame]), Future.value(null)) - as _i7.Future); - - @override - _i7.Future writeFrames(List<_i9.Frame>? frames) => (super.noSuchMethod( - Invocation.method(#writeFrames, [frames]), Future.value(null)) - as _i7.Future); - - @override - _i7.Future compact(Iterable<_i9.Frame>? frames) => (super.noSuchMethod( - Invocation.method(#compact, [frames]), Future.value(null)) - as _i7.Future); - - @override - _i7.Future clear() => - (super.noSuchMethod(Invocation.method(#clear, []), Future.value(null)) - as _i7.Future); - - @override - _i7.Future close() => - (super.noSuchMethod(Invocation.method(#close, []), Future.value(null)) - as _i7.Future); - - @override - _i7.Future deleteFromDisk() => (super.noSuchMethod( - Invocation.method(#deleteFromDisk, []), Future.value(null)) - as _i7.Future); -} - -/// A class which mocks [Keystore]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockKeystore extends _i1.Mock implements _i11.Keystore { - @override - _i2.ListQueue<_i11.KeyTransaction> get transactions => (super.noSuchMethod( - Invocation.getter(#transactions), - _FakeListQueue<_i11.KeyTransaction>()) - as _i2.ListQueue<_i11.KeyTransaction>); - - @override - int get deletedEntries => - (super.noSuchMethod(Invocation.getter(#deletedEntries), 0) as int); - - @override - int get length => (super.noSuchMethod(Invocation.getter(#length), 0) as int); - - @override - Iterable<_i9.Frame> get frames => - (super.noSuchMethod(Invocation.getter(#frames), <_i9.Frame>[]) - as Iterable<_i9.Frame>); - - @override - int autoIncrement() => - (super.noSuchMethod(Invocation.method(#autoIncrement, []), 0) as int); - - @override - void updateAutoIncrement(int? key) => - super.noSuchMethod(Invocation.method(#updateAutoIncrement, [key])); - - @override - bool containsKey(dynamic key) => - (super.noSuchMethod(Invocation.method(#containsKey, [key]), false) - as bool); - - @override - dynamic keyAt(int? index) => - (super.noSuchMethod(Invocation.method(#keyAt, [index])) as dynamic); - - @override - _i9.Frame? getAt(int? index) => - (super.noSuchMethod(Invocation.method(#getAt, [index])) as _i9.Frame?); - - @override - Iterable getKeys() => - (super.noSuchMethod(Invocation.method(#getKeys, []), []) - as Iterable); - - @override - Iterable getValues() => - (super.noSuchMethod(Invocation.method(#getValues, []), []) - as Iterable); - - @override - Iterable getValuesBetween([dynamic startKey, dynamic endKey]) => - (super.noSuchMethod( - Invocation.method(#getValuesBetween, [startKey, endKey]), []) - as Iterable); - - @override - _i7.Stream<_i3.BoxEvent> watch({dynamic key}) => (super.noSuchMethod( - Invocation.method(#watch, [], {#key: key}), - Stream<_i3.BoxEvent>.empty()) as _i7.Stream<_i3.BoxEvent>); - - @override - _i9.Frame? insert(_i9.Frame? frame, - {bool? notify = true, bool lazy = false}) => - (super.noSuchMethod( - Invocation.method(#insert, [frame], {#notify: notify})) - as _i9.Frame?); - - @override - bool beginTransaction(List<_i9.Frame>? newFrames) => (super.noSuchMethod( - Invocation.method(#beginTransaction, [newFrames]), false) as bool); - - @override - int clear() => (super.noSuchMethod(Invocation.method(#clear, []), 0) as int); - - @override - _i7.Future close() => - (super.noSuchMethod(Invocation.method(#close, []), Future.value(null)) - as _i7.Future); -} - -/// A class which mocks [HiveImpl]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockHiveImpl extends _i1.Mock implements _i12.HiveImpl { - @override - void init(String? path) => - super.noSuchMethod(Invocation.method(#init, [path])); - - @override - _i7.Future<_i3.Box> openBox(String? name, - {_i3.HiveCipher? encryptionCipher, - _i3.KeyComparator? keyComparator = defaultKeyComparator, - _i3.CompactionStrategy? compactionStrategy = - defaultCompactionStrategy, - bool? crashRecovery = true, - String? path, - _i5.Uint8List? bytes, - List? encryptionKey}) => - (super.noSuchMethod( - Invocation.method(#openBox, [ - name - ], { - #encryptionCipher: encryptionCipher, - #keyComparator: keyComparator, - #compactionStrategy: compactionStrategy, - #crashRecovery: crashRecovery, - #path: path, - #bytes: bytes, - #encryptionKey: encryptionKey - }), - Future.value(_FakeBox())) as _i7.Future<_i3.Box>); - - @override - _i7.Future<_i3.LazyBox> openLazyBox(String? name, - {_i3.HiveCipher? encryptionCipher, - _i3.KeyComparator? keyComparator = defaultKeyComparator, - _i3.CompactionStrategy? compactionStrategy = - defaultCompactionStrategy, - bool? crashRecovery = true, - String? path, - List? encryptionKey}) => - (super.noSuchMethod( - Invocation.method(#openLazyBox, [ - name - ], { - #encryptionCipher: encryptionCipher, - #keyComparator: keyComparator, - #compactionStrategy: compactionStrategy, - #crashRecovery: crashRecovery, - #path: path, - #encryptionKey: encryptionKey - }), - Future.value(_FakeLazyBox())) as _i7.Future<_i3.LazyBox>); - - @override - _i3.BoxBase? getBoxWithoutCheckInternal(String? name) => (super - .noSuchMethod(Invocation.method(#getBoxWithoutCheckInternal, [name])) - as _i3.BoxBase?); - - @override - _i3.Box box(String? name) => - (super.noSuchMethod(Invocation.method(#box, [name]), _FakeBox()) - as _i3.Box); - - @override - _i3.LazyBox lazyBox(String? name) => (super - .noSuchMethod(Invocation.method(#lazyBox, [name]), _FakeLazyBox()) - as _i3.LazyBox); - - @override - bool isBoxOpen(String? name) => - (super.noSuchMethod(Invocation.method(#isBoxOpen, [name]), false) - as bool); - - @override - _i7.Future close() => - (super.noSuchMethod(Invocation.method(#close, []), Future.value(null)) - as _i7.Future); - - @override - void unregisterBox(String? name) => - super.noSuchMethod(Invocation.method(#unregisterBox, [name])); - - @override - _i7.Future deleteBoxFromDisk(String? name, {String? path}) => - (super.noSuchMethod( - Invocation.method(#deleteBoxFromDisk, [name], {#path: path}), - Future.value(null)) as _i7.Future); - - @override - _i7.Future deleteFromDisk() => (super.noSuchMethod( - Invocation.method(#deleteFromDisk, []), Future.value(null)) - as _i7.Future); - - @override - List generateSecureKey() => - (super.noSuchMethod(Invocation.method(#generateSecureKey, []), []) - as List); - - @override - _i7.Future boxExists(String? name, {String? path}) => - (super.noSuchMethod(Invocation.method(#boxExists, [name], {#path: path}), - Future.value(false)) as _i7.Future); - - @override - _i13.ResolvedAdapter? findAdapterForTypeId(int? typeId) => - (super.noSuchMethod(Invocation.method(#findAdapterForTypeId, [typeId])) - as _i13.ResolvedAdapter?); - - @override - void registerAdapter(_i3.TypeAdapter? adapter, - {bool? internal = false, bool? override = false}) => - super.noSuchMethod(Invocation.method(#registerAdapter, [adapter], - {#internal: internal, #override: override})); - - @override - bool isAdapterRegistered(int? typeId, {bool? internal = false}) => - (super.noSuchMethod( - Invocation.method( - #isAdapterRegistered, [typeId], {#internal: internal}), - false) as bool); - - @override - void ignoreTypeId(int? typeId) => - super.noSuchMethod(Invocation.method(#ignoreTypeId, [typeId])); -} - -/// A class which mocks [HiveList]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockHiveList extends _i1.Mock - implements _i3.HiveList { - @override - _i3.BoxBase get box => - (super.noSuchMethod(Invocation.getter(#box), _FakeBoxBase()) - as _i3.BoxBase); - - @override - Iterable get keys => - (super.noSuchMethod(Invocation.getter(#keys), []) as Iterable); - - @override - _i3.HiveList castHiveList() => - (super.noSuchMethod( - Invocation.method(#castHiveList, []), _FakeHiveList()) - as _i3.HiveList); - - @override - _i7.Future deleteAllFromHive() => (super.noSuchMethod( - Invocation.method(#deleteAllFromHive, []), Future.value(null)) - as _i7.Future); - - @override - _i7.Future deleteFirstFromHive() => (super.noSuchMethod( - Invocation.method(#deleteFirstFromHive, []), Future.value(null)) - as _i7.Future); - - @override - _i7.Future deleteLastFromHive() => (super.noSuchMethod( - Invocation.method(#deleteLastFromHive, []), Future.value(null)) - as _i7.Future); - - @override - _i7.Future deleteFromHive(int? index) => (super.noSuchMethod( - Invocation.method(#deleteFromHive, [index]), Future.value(null)) - as _i7.Future); - - @override - Map toMap() => - (super.noSuchMethod(Invocation.method(#toMap, []), {}) - as Map); -} - -/// A class which mocks [HiveListImpl]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockHiveListImpl extends _i1.Mock - implements _i14.HiveListImpl { - @override - String get boxName => - (super.noSuchMethod(Invocation.getter(#boxName), '') as String); - - @override - Iterable get keys => - (super.noSuchMethod(Invocation.getter(#keys), []) as Iterable); - - @override - _i3.Box get box => - (super.noSuchMethod(Invocation.getter(#box), _FakeBox()) - as _i3.Box); - - @override - List get delegate => - (super.noSuchMethod(Invocation.getter(#delegate), []) as List); - - @override - set length(int? newLength) => - super.noSuchMethod(Invocation.setter(#length, [newLength])); - - @override - set debugHive(_i3.HiveInterface? hive) => - super.noSuchMethod(Invocation.setter(#debugHive, [hive])); - - @override - Iterator get iterator => - (super.noSuchMethod(Invocation.getter(#iterator), _FakeIterator()) - as Iterator); - - @override - bool get isEmpty => - (super.noSuchMethod(Invocation.getter(#isEmpty), false) as bool); - - @override - bool get isNotEmpty => - (super.noSuchMethod(Invocation.getter(#isNotEmpty), false) as bool); - - @override - E get first => (super.noSuchMethod(Invocation.getter(#first), null) as E); - - @override - set first(E? value) => super.noSuchMethod(Invocation.setter(#first, [value])); - - @override - E get last => (super.noSuchMethod(Invocation.getter(#last), null) as E); - - @override - set last(E? value) => super.noSuchMethod(Invocation.setter(#last, [value])); - - @override - E get single => (super.noSuchMethod(Invocation.getter(#single), null) as E); - - @override - Iterable get reversed => - (super.noSuchMethod(Invocation.getter(#reversed), []) as Iterable); - - @override - void operator []=(int? index, E? value) => - super.noSuchMethod(Invocation.method(#[]=, [index, value])); - - @override - void add(E? element) => - super.noSuchMethod(Invocation.method(#add, [element])); - - @override - void addAll(Iterable? iterable) => - super.noSuchMethod(Invocation.method(#addAll, [iterable])); - - @override - _i3.HiveList castHiveList() => - (super.noSuchMethod( - Invocation.method(#castHiveList, []), _FakeHiveList()) - as _i3.HiveList); - - @override - _i7.Future deleteAllFromHive() => (super.noSuchMethod( - Invocation.method(#deleteAllFromHive, []), Future.value(null)) - as _i7.Future); - - @override - _i7.Future deleteFirstFromHive() => (super.noSuchMethod( - Invocation.method(#deleteFirstFromHive, []), Future.value(null)) - as _i7.Future); - - @override - _i7.Future deleteLastFromHive() => (super.noSuchMethod( - Invocation.method(#deleteLastFromHive, []), Future.value(null)) - as _i7.Future); - - @override - _i7.Future deleteFromHive(int? index) => (super.noSuchMethod( - Invocation.method(#deleteFromHive, [index]), Future.value(null)) - as _i7.Future); - - @override - Map toMap() => - (super.noSuchMethod(Invocation.method(#toMap, []), {}) - as Map); - - @override - E elementAt(int? index) => (super.noSuchMethod( - Invocation.method(#elementAt, [index]), _FakeHiveObject()) as E); - - @override - Iterable followedBy(Iterable? other) => - (super.noSuchMethod(Invocation.method(#followedBy, [other]), []) - as Iterable); - - @override - void forEach(void Function(E)? action) => - super.noSuchMethod(Invocation.method(#forEach, [action])); - - @override - bool contains(Object? element) => - (super.noSuchMethod(Invocation.method(#contains, [element]), false) - as bool); - - @override - bool every(bool Function(E)? test) => - (super.noSuchMethod(Invocation.method(#every, [test]), false) as bool); - - @override - bool any(bool Function(E)? test) => - (super.noSuchMethod(Invocation.method(#any, [test]), false) as bool); - - @override - E firstWhere(bool Function(E)? test, {E Function()? orElse}) => - (super.noSuchMethod( - Invocation.method(#firstWhere, [test], {#orElse: orElse}), - _FakeHiveObject()) as E); - - @override - E lastWhere(bool Function(E)? test, {E Function()? orElse}) => - (super.noSuchMethod( - Invocation.method(#lastWhere, [test], {#orElse: orElse}), - _FakeHiveObject()) as E); - - @override - E singleWhere(bool Function(E)? test, {E Function()? orElse}) => - (super.noSuchMethod( - Invocation.method(#singleWhere, [test], {#orElse: orElse}), - _FakeHiveObject()) as E); - - @override - String join([String? separator]) => - (super.noSuchMethod(Invocation.method(#join, [separator]), '') as String); - - @override - Iterable where(bool Function(E)? test) => - (super.noSuchMethod(Invocation.method(#where, [test]), []) - as Iterable); - - @override - Iterable whereType() => - (super.noSuchMethod(Invocation.method(#whereType, []), []) - as Iterable); - - @override - Iterable map(T Function(E)? f) => - (super.noSuchMethod(Invocation.method(#map, [f]), []) as Iterable); - - @override - Iterable expand(Iterable Function(E)? f) => - (super.noSuchMethod(Invocation.method(#expand, [f]), []) as Iterable); - - @override - E reduce(E Function(E, E)? combine) => (super.noSuchMethod( - Invocation.method(#reduce, [combine]), _FakeHiveObject()) as E); - - @override - T fold(T? initialValue, T Function(T, E)? combine) => (super.noSuchMethod( - Invocation.method(#fold, [initialValue, combine]), null) as T); - - @override - Iterable skip(int? count) => - (super.noSuchMethod(Invocation.method(#skip, [count]), []) - as Iterable); - - @override - Iterable skipWhile(bool Function(E)? test) => - (super.noSuchMethod(Invocation.method(#skipWhile, [test]), []) - as Iterable); - - @override - Iterable take(int? count) => - (super.noSuchMethod(Invocation.method(#take, [count]), []) - as Iterable); - - @override - Iterable takeWhile(bool Function(E)? test) => - (super.noSuchMethod(Invocation.method(#takeWhile, [test]), []) - as Iterable); - - @override - List toList({bool? growable}) => (super.noSuchMethod( - Invocation.method(#toList, [], {#growable: growable}), []) as List); - - @override - Set toSet() => - (super.noSuchMethod(Invocation.method(#toSet, []), {}) as Set); - - @override - bool remove(Object? element) => - (super.noSuchMethod(Invocation.method(#remove, [element]), false) - as bool); - - @override - void removeWhere(bool Function(E)? test) => - super.noSuchMethod(Invocation.method(#removeWhere, [test])); - - @override - void retainWhere(bool Function(E)? test) => - super.noSuchMethod(Invocation.method(#retainWhere, [test])); - - @override - List cast() => - (super.noSuchMethod(Invocation.method(#cast, []), []) as List); - - @override - E removeLast() => - (super.noSuchMethod(Invocation.method(#removeLast, []), _FakeHiveObject()) - as E); - - @override - Map asMap() => - (super.noSuchMethod(Invocation.method(#asMap, []), {}) - as Map); - - @override - List operator +(List? other) => - (super.noSuchMethod(Invocation.method(#+, [other]), []) as List); - - @override - List sublist(int? start, [int? end]) => - (super.noSuchMethod(Invocation.method(#sublist, [start, end]), []) - as List); - - @override - Iterable getRange(int? start, int? end) => - (super.noSuchMethod(Invocation.method(#getRange, [start, end]), []) - as Iterable); - - @override - void removeRange(int? start, int? end) => - super.noSuchMethod(Invocation.method(#removeRange, [start, end])); - - @override - void fillRange(int? start, int? end, [E? fill]) => - super.noSuchMethod(Invocation.method(#fillRange, [start, end, fill])); - - @override - void setRange(int? start, int? end, Iterable? iterable, - [int? skipCount]) => - super.noSuchMethod( - Invocation.method(#setRange, [start, end, iterable, skipCount])); - - @override - void replaceRange(int? start, int? end, Iterable? newContents) => - super.noSuchMethod( - Invocation.method(#replaceRange, [start, end, newContents])); - - @override - int indexOf(Object? element, [int? start]) => - (super.noSuchMethod(Invocation.method(#indexOf, [element, start]), 0) - as int); - - @override - int indexWhere(bool Function(E)? test, [int? start]) => - (super.noSuchMethod(Invocation.method(#indexWhere, [test, start]), 0) - as int); - - @override - int lastIndexOf(Object? element, [int? start]) => - (super.noSuchMethod(Invocation.method(#lastIndexOf, [element, start]), 0) - as int); - - @override - int lastIndexWhere(bool Function(E)? test, [int? start]) => - (super.noSuchMethod(Invocation.method(#lastIndexWhere, [test, start]), 0) - as int); - - @override - void insert(int? index, E? element) => - super.noSuchMethod(Invocation.method(#insert, [index, element])); - - @override - E removeAt(int? index) => (super.noSuchMethod( - Invocation.method(#removeAt, [index]), _FakeHiveObject()) as E); - - @override - void insertAll(int? index, Iterable? iterable) => - super.noSuchMethod(Invocation.method(#insertAll, [index, iterable])); - - @override - void setAll(int? index, Iterable? iterable) => - super.noSuchMethod(Invocation.method(#setAll, [index, iterable])); -} - -/// A class which mocks [RandomAccessFile]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockRandomAccessFile extends _i1.Mock implements _i6.RandomAccessFile { - @override - String get path => - (super.noSuchMethod(Invocation.getter(#path), '') as String); - - @override - _i7.Future close() => - (super.noSuchMethod(Invocation.method(#close, []), Future.value(null)) - as _i7.Future); - - @override - _i7.Future readByte() => - (super.noSuchMethod(Invocation.method(#readByte, []), Future.value(0)) - as _i7.Future); - - @override - int readByteSync() => - (super.noSuchMethod(Invocation.method(#readByteSync, []), 0) as int); - - @override - _i7.Future<_i5.Uint8List> read(int? bytes) => (super.noSuchMethod( - Invocation.method(#read, [bytes]), Future.value(_FakeUint8List())) - as _i7.Future<_i5.Uint8List>); - - @override - _i5.Uint8List readSync(int? bytes) => (super - .noSuchMethod(Invocation.method(#readSync, [bytes]), _FakeUint8List()) - as _i5.Uint8List); - - @override - _i7.Future readInto(List? buffer, [int? start, int? end]) => - (super.noSuchMethod(Invocation.method(#readInto, [buffer, start, end]), - Future.value(0)) as _i7.Future); - - @override - int readIntoSync(List? buffer, [int? start, int? end]) => - (super.noSuchMethod( - Invocation.method(#readIntoSync, [buffer, start, end]), 0) as int); - - @override - _i7.Future<_i6.RandomAccessFile> writeByte(int? value) => (super.noSuchMethod( - Invocation.method(#writeByte, [value]), - Future.value(_FakeRandomAccessFile())) - as _i7.Future<_i6.RandomAccessFile>); - - @override - int writeByteSync(int? value) => - (super.noSuchMethod(Invocation.method(#writeByteSync, [value]), 0) - as int); - - @override - _i7.Future<_i6.RandomAccessFile> writeFrom(List? buffer, - [int? start, int? end]) => - (super.noSuchMethod(Invocation.method(#writeFrom, [buffer, start, end]), - Future.value(_FakeRandomAccessFile())) - as _i7.Future<_i6.RandomAccessFile>); - - @override - void writeFromSync(List? buffer, [int? start, int? end]) => super - .noSuchMethod(Invocation.method(#writeFromSync, [buffer, start, end])); - - @override - _i7.Future<_i6.RandomAccessFile> writeString(String? string, - {_i15.Encoding? encoding}) => - (super.noSuchMethod( - Invocation.method(#writeString, [string], {#encoding: encoding}), - Future.value(_FakeRandomAccessFile())) - as _i7.Future<_i6.RandomAccessFile>); - - @override - void writeStringSync(String? string, {_i15.Encoding? encoding}) => - super.noSuchMethod( - Invocation.method(#writeStringSync, [string], {#encoding: encoding})); - - @override - _i7.Future position() => - (super.noSuchMethod(Invocation.method(#position, []), Future.value(0)) - as _i7.Future); - - @override - int positionSync() => - (super.noSuchMethod(Invocation.method(#positionSync, []), 0) as int); - - @override - _i7.Future<_i6.RandomAccessFile> setPosition(int? position) => - (super.noSuchMethod(Invocation.method(#setPosition, [position]), - Future.value(_FakeRandomAccessFile())) - as _i7.Future<_i6.RandomAccessFile>); - - @override - void setPositionSync(int? position) => - super.noSuchMethod(Invocation.method(#setPositionSync, [position])); - - @override - _i7.Future<_i6.RandomAccessFile> truncate(int? length) => (super.noSuchMethod( - Invocation.method(#truncate, [length]), - Future.value(_FakeRandomAccessFile())) - as _i7.Future<_i6.RandomAccessFile>); - - @override - void truncateSync(int? length) => - super.noSuchMethod(Invocation.method(#truncateSync, [length])); - - @override - _i7.Future length() => - (super.noSuchMethod(Invocation.method(#length, []), Future.value(0)) - as _i7.Future); - - @override - int lengthSync() => - (super.noSuchMethod(Invocation.method(#lengthSync, []), 0) as int); - - @override - _i7.Future<_i6.RandomAccessFile> flush() => (super.noSuchMethod( - Invocation.method(#flush, []), Future.value(_FakeRandomAccessFile())) - as _i7.Future<_i6.RandomAccessFile>); - - @override - _i7.Future<_i6.RandomAccessFile> lock( - [_i6.FileLock? mode, int? start, int? end]) => - (super.noSuchMethod(Invocation.method(#lock, [mode, start, end]), - Future.value(_FakeRandomAccessFile())) - as _i7.Future<_i6.RandomAccessFile>); - - @override - void lockSync([_i6.FileLock? mode, int? start, int? end]) => - super.noSuchMethod(Invocation.method(#lockSync, [mode, start, end])); - - @override - _i7.Future<_i6.RandomAccessFile> unlock([int? start, int? end]) => - (super.noSuchMethod(Invocation.method(#unlock, [start, end]), - Future.value(_FakeRandomAccessFile())) - as _i7.Future<_i6.RandomAccessFile>); - - @override - void unlockSync([int? start, int? end]) => - super.noSuchMethod(Invocation.method(#unlockSync, [start, end])); -} - -/// A class which mocks [BinaryReader]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockBinaryReader extends _i1.Mock implements _i3.BinaryReader { - @override - int get availableBytes => - (super.noSuchMethod(Invocation.getter(#availableBytes), 0) as int); - - @override - int get usedBytes => - (super.noSuchMethod(Invocation.getter(#usedBytes), 0) as int); - - @override - void skip(int? bytes) => - super.noSuchMethod(Invocation.method(#skip, [bytes])); - - @override - int readByte() => - (super.noSuchMethod(Invocation.method(#readByte, []), 0) as int); - - @override - _i5.Uint8List viewBytes(int? bytes) => (super.noSuchMethod( - Invocation.method(#viewBytes, [bytes]), _FakeUint8List()) - as _i5.Uint8List); - - @override - _i5.Uint8List peekBytes(int? bytes) => (super.noSuchMethod( - Invocation.method(#peekBytes, [bytes]), _FakeUint8List()) - as _i5.Uint8List); - - @override - int readWord() => - (super.noSuchMethod(Invocation.method(#readWord, []), 0) as int); - - @override - int readInt32() => - (super.noSuchMethod(Invocation.method(#readInt32, []), 0) as int); - - @override - int readUint32() => - (super.noSuchMethod(Invocation.method(#readUint32, []), 0) as int); - - @override - int readInt() => - (super.noSuchMethod(Invocation.method(#readInt, []), 0) as int); - - @override - double readDouble() => - (super.noSuchMethod(Invocation.method(#readDouble, []), 0.0) as double); - - @override - bool readBool() => - (super.noSuchMethod(Invocation.method(#readBool, []), false) as bool); - - @override - String readString( - [int? byteCount, - _i15.Converter, String>? decoder = - const _i15.Utf8Decoder()]) => - (super.noSuchMethod( - Invocation.method(#readString, [byteCount, decoder]), '') as String); - - @override - _i5.Uint8List readByteList([int? length]) => (super.noSuchMethod( - Invocation.method(#readByteList, [length]), _FakeUint8List()) - as _i5.Uint8List); - - @override - List readIntList([int? length]) => - (super.noSuchMethod(Invocation.method(#readIntList, [length]), []) - as List); - - @override - List readDoubleList([int? length]) => (super.noSuchMethod( - Invocation.method(#readDoubleList, [length]), []) - as List); - - @override - List readBoolList([int? length]) => - (super.noSuchMethod(Invocation.method(#readBoolList, [length]), []) - as List); - - @override - List readStringList( - [int? length, - _i15.Converter, String>? decoder = - const _i15.Utf8Decoder()]) => - (super.noSuchMethod( - Invocation.method(#readStringList, [length, decoder]), []) - as List); - - @override - List readList([int? length]) => - (super.noSuchMethod(Invocation.method(#readList, [length]), []) - as List); - - @override - Map readMap([int? length]) => (super.noSuchMethod( - Invocation.method(#readMap, [length]), {}) - as Map); - - @override - _i3.HiveList<_i4.HiveObject> readHiveList([int? length]) => - (super.noSuchMethod(Invocation.method(#readHiveList, [length]), - _FakeHiveList<_i4.HiveObject>()) as _i3.HiveList<_i4.HiveObject>); -} - -/// A class which mocks [BinaryWriter]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockBinaryWriter extends _i1.Mock implements _i3.BinaryWriter { - @override - void writeByte(int? byte) => - super.noSuchMethod(Invocation.method(#writeByte, [byte])); - - @override - void writeWord(int? value) => - super.noSuchMethod(Invocation.method(#writeWord, [value])); - - @override - void writeInt32(int? value) => - super.noSuchMethod(Invocation.method(#writeInt32, [value])); - - @override - void writeUint32(int? value) => - super.noSuchMethod(Invocation.method(#writeUint32, [value])); - - @override - void writeInt(int? value) => - super.noSuchMethod(Invocation.method(#writeInt, [value])); - - @override - void writeDouble(double? value) => - super.noSuchMethod(Invocation.method(#writeDouble, [value])); - - @override - void writeBool(bool? value) => - super.noSuchMethod(Invocation.method(#writeBool, [value])); - - @override - void writeString(String? value, - {bool? writeByteCount = true, - _i15.Converter>? encoder = - const _i15.Utf8Encoder()}) => - super.noSuchMethod(Invocation.method(#writeString, [value], - {#writeByteCount: writeByteCount, #encoder: encoder})); - - @override - void writeByteList(List? bytes, {bool? writeLength = true}) => - super.noSuchMethod(Invocation.method( - #writeByteList, [bytes], {#writeLength: writeLength})); - - @override - void writeIntList(List? list, {bool? writeLength = true}) => - super.noSuchMethod(Invocation.method( - #writeIntList, [list], {#writeLength: writeLength})); - - @override - void writeDoubleList(List? list, {bool? writeLength = true}) => - super.noSuchMethod(Invocation.method( - #writeDoubleList, [list], {#writeLength: writeLength})); - - @override - void writeBoolList(List? list, {bool? writeLength = true}) => - super.noSuchMethod(Invocation.method( - #writeBoolList, [list], {#writeLength: writeLength})); - - @override - void writeStringList(List? list, - {bool? writeLength = true, - _i15.Converter>? encoder = - const _i15.Utf8Encoder()}) => - super.noSuchMethod(Invocation.method(#writeStringList, [list], - {#writeLength: writeLength, #encoder: encoder})); - - @override - void writeList(List? list, {bool? writeLength = true}) => - super.noSuchMethod( - Invocation.method(#writeList, [list], {#writeLength: writeLength})); - - @override - void writeMap(Map? map, {bool? writeLength = true}) => - super.noSuchMethod( - Invocation.method(#writeMap, [map], {#writeLength: writeLength})); - - @override - void writeHiveList(_i3.HiveList<_i4.HiveObjectMixin>? list, - {bool? writeLength = true}) => - super.noSuchMethod(Invocation.method( - #writeHiveList, [list], {#writeLength: writeLength})); - - @override - void write(T? value, {bool? writeTypeId = true}) => super.noSuchMethod( - Invocation.method(#write, [value], {#writeTypeId: writeTypeId})); -} - -/// A class which mocks [File]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockFile extends _i1.Mock implements _i6.File { - @override - _i6.File get absolute => - (super.noSuchMethod(Invocation.getter(#absolute), _FakeFile()) - as _i6.File); - - @override - String get path => - (super.noSuchMethod(Invocation.getter(#path), '') as String); - - @override - _i7.Future<_i6.File> create({bool? recursive}) => (super.noSuchMethod( - Invocation.method(#create, [], {#recursive: recursive}), - Future.value(_FakeFile())) as _i7.Future<_i6.File>); - - @override - void createSync({bool? recursive}) => super.noSuchMethod( - Invocation.method(#createSync, [], {#recursive: recursive})); - - @override - _i7.Future<_i6.File> rename(String? newPath) => (super.noSuchMethod( - Invocation.method(#rename, [newPath]), Future.value(_FakeFile())) - as _i7.Future<_i6.File>); - - @override - _i6.File renameSync(String? newPath) => (super.noSuchMethod( - Invocation.method(#renameSync, [newPath]), _FakeFile()) as _i6.File); - - @override - _i7.Future<_i6.File> copy(String? newPath) => (super.noSuchMethod( - Invocation.method(#copy, [newPath]), Future.value(_FakeFile())) - as _i7.Future<_i6.File>); - - @override - _i6.File copySync(String? newPath) => - (super.noSuchMethod(Invocation.method(#copySync, [newPath]), _FakeFile()) - as _i6.File); - - @override - _i7.Future length() => - (super.noSuchMethod(Invocation.method(#length, []), Future.value(0)) - as _i7.Future); - - @override - int lengthSync() => - (super.noSuchMethod(Invocation.method(#lengthSync, []), 0) as int); - - @override - _i7.Future lastAccessed() => (super.noSuchMethod( - Invocation.method(#lastAccessed, []), Future.value(_FakeDateTime())) - as _i7.Future); - - @override - DateTime lastAccessedSync() => (super.noSuchMethod( - Invocation.method(#lastAccessedSync, []), _FakeDateTime()) as DateTime); - - @override - _i7.Future setLastAccessed(DateTime? time) => (super.noSuchMethod( - Invocation.method(#setLastAccessed, [time]), Future.value(null)) - as _i7.Future); - - @override - void setLastAccessedSync(DateTime? time) => - super.noSuchMethod(Invocation.method(#setLastAccessedSync, [time])); - - @override - _i7.Future lastModified() => (super.noSuchMethod( - Invocation.method(#lastModified, []), Future.value(_FakeDateTime())) - as _i7.Future); - - @override - DateTime lastModifiedSync() => (super.noSuchMethod( - Invocation.method(#lastModifiedSync, []), _FakeDateTime()) as DateTime); - - @override - _i7.Future setLastModified(DateTime? time) => (super.noSuchMethod( - Invocation.method(#setLastModified, [time]), Future.value(null)) - as _i7.Future); - - @override - void setLastModifiedSync(DateTime? time) => - super.noSuchMethod(Invocation.method(#setLastModifiedSync, [time])); - - @override - _i7.Future<_i6.RandomAccessFile> open({_i6.FileMode? mode}) => - (super.noSuchMethod(Invocation.method(#open, [], {#mode: mode}), - Future.value(_FakeRandomAccessFile())) - as _i7.Future<_i6.RandomAccessFile>); - - @override - _i6.RandomAccessFile openSync({_i6.FileMode? mode}) => (super.noSuchMethod( - Invocation.method(#openSync, [], {#mode: mode}), - _FakeRandomAccessFile()) as _i6.RandomAccessFile); - - @override - _i7.Stream> openRead([int? start, int? end]) => (super.noSuchMethod( - Invocation.method(#openRead, [start, end]), Stream>.empty()) - as _i7.Stream>); - - @override - _i6.IOSink openWrite({_i6.FileMode? mode, _i15.Encoding? encoding}) => - (super.noSuchMethod( - Invocation.method(#openWrite, [], {#mode: mode, #encoding: encoding}), - _FakeIOSink()) as _i6.IOSink); - - @override - _i7.Future<_i5.Uint8List> readAsBytes() => (super.noSuchMethod( - Invocation.method(#readAsBytes, []), Future.value(_FakeUint8List())) - as _i7.Future<_i5.Uint8List>); - - @override - _i5.Uint8List readAsBytesSync() => (super.noSuchMethod( - Invocation.method(#readAsBytesSync, []), _FakeUint8List()) - as _i5.Uint8List); - - @override - _i7.Future readAsString({_i15.Encoding? encoding}) => - (super.noSuchMethod( - Invocation.method(#readAsString, [], {#encoding: encoding}), - Future.value('')) as _i7.Future); - - @override - String readAsStringSync({_i15.Encoding? encoding}) => (super.noSuchMethod( - Invocation.method(#readAsStringSync, [], {#encoding: encoding}), '') - as String); - - @override - _i7.Future> readAsLines({_i15.Encoding? encoding}) => - (super.noSuchMethod( - Invocation.method(#readAsLines, [], {#encoding: encoding}), - Future.value([])) as _i7.Future>); - - @override - List readAsLinesSync({_i15.Encoding? encoding}) => - (super.noSuchMethod( - Invocation.method(#readAsLinesSync, [], {#encoding: encoding}), - []) as List); - @override - _i7.Future<_i6.File> writeAsBytes(List? bytes, - {_i6.FileMode? mode, bool? flush}) => - (super.noSuchMethod( - Invocation.method( - #writeAsBytes, [bytes], {#mode: mode, #flush: flush}), - Future.value(_FakeFile())) as _i7.Future<_i6.File>); - - @override - void writeAsBytesSync(List? bytes, {_i6.FileMode? mode, bool? flush}) => - super.noSuchMethod(Invocation.method( - #writeAsBytesSync, [bytes], {#mode: mode, #flush: flush})); - @override - _i7.Future<_i6.File> writeAsString(String? contents, - {_i6.FileMode? mode, _i15.Encoding? encoding, bool? flush}) => - (super.noSuchMethod( - Invocation.method(#writeAsString, [contents], - {#mode: mode, #encoding: encoding, #flush: flush}), - Future.value(_FakeFile())) as _i7.Future<_i6.File>); - - @override - void writeAsStringSync(String? contents, - {_i6.FileMode? mode, _i15.Encoding? encoding, bool? flush}) => - super.noSuchMethod(Invocation.method(#writeAsStringSync, [contents], - {#mode: mode, #encoding: encoding, #flush: flush})); - - @override - _i7.Future<_i6.FileSystemEntity> delete({bool recursive = false}) => - (super.noSuchMethod( - Invocation.method(#delete, [], {#recursive: recursive}), - Future.value(_FakeFile())) as _i7.Future<_i6.FileSystemEntity>); -} - -/// A class which mocks [FrameIoHelper]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockFrameIoHelper extends _i1.Mock implements _i16.FrameIoHelper { - @override - _i7.Future<_i6.RandomAccessFile> openFile(String? path) => - (super.noSuchMethod(Invocation.method(#openFile, [path]), - Future.value(_FakeRandomAccessFile())) - as _i7.Future<_i6.RandomAccessFile>); - - @override - _i7.Future> readFile(String? path) => (super.noSuchMethod( - Invocation.method(#readFile, [path]), Future.value([])) - as _i7.Future>); - - @override - _i7.Future keysFromFile(String? path, _i11.Keystore? keystore, - _i3.HiveCipher? cipher) => - (super.noSuchMethod( - Invocation.method(#keysFromFile, [path, keystore, cipher]), - Future.value(0)) as _i7.Future); - - @override - _i7.Future framesFromFile(String? path, _i11.Keystore? keystore, - _i3.TypeRegistry? registry, _i3.HiveCipher? cipher) => - (super.noSuchMethod( - Invocation.method( - #framesFromFile, [path, keystore, registry, cipher]), - Future.value(0)) as _i7.Future); - - @override - int framesFromBytes(_i5.Uint8List? bytes, _i11.Keystore? keystore, - _i3.TypeRegistry? registry, _i3.HiveCipher? cipher) => - (super.noSuchMethod( - Invocation.method( - #framesFromBytes, [bytes, keystore, registry, cipher]), - 0) as int); -} diff --git a/hive/test/tests/object/hive_collection_mixin_test.dart b/hive/test/tests/object/hive_collection_mixin_test.dart index 54cb8645f..4406b2fc1 100644 --- a/hive/test/tests/object/hive_collection_mixin_test.dart +++ b/hive/test/tests/object/hive_collection_mixin_test.dart @@ -1,12 +1,12 @@ import 'package:hive/hive.dart'; import 'package:hive/src/object/hive_object.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; import '../common.dart'; import '../mocks.dart'; HiveList _getTestList(MockBox box) { - when(box.name).thenReturn('testBox'); + when(() => box.name).thenReturn('testBox'); var obj1 = TestHiveObject(); obj1.init('key1', box); var obj2 = TestHiveObject(); @@ -30,44 +30,44 @@ void main() { final keys = ['key1', 'key2', 'key3']; var box = MockBox(); var hiveList = _getTestList(box); - returnFutureVoid(when(box.deleteAll( - keys.map((e) => e), // Turn the List into an regular Iterable - ))); + returnFutureVoid(when(() => box.deleteAll( + keys.map((e) => e), // Turn the List into an regular Iterable + ))); hiveList.deleteAllFromHive(); - verify(box.deleteAll(keys)); + verify(() => box.deleteAll(keys)); }); test('.deleteFirstFromHive()', () { var box = MockBox(); var hiveList = _getTestList(box); - returnFutureVoid(when(box.delete('key1'))); + returnFutureVoid(when(() => box.delete('key1'))); hiveList.deleteFirstFromHive(); - verify(box.delete('key1')); + verify(() => box.delete('key1')); }); test('.deleteLastFromHive()', () { var box = MockBox(); var hiveList = _getTestList(box); - returnFutureVoid(when(box.delete('key3'))); + returnFutureVoid(when(() => box.delete('key3'))); hiveList.deleteLastFromHive(); - verify(box.delete('key3')); + verify(() => box.delete('key3')); }); test('.deleteFromHive()', () { var box = MockBox(); var hiveList = _getTestList(box); - returnFutureVoid(when(box.delete('key2'))); + returnFutureVoid(when(() => box.delete('key2'))); hiveList.deleteFromHive(1); - verify(box.delete('key2')); + verify(() => box.delete('key2')); }); test('.toMap()', () { var box = MockBox(); - when(box.name).thenReturn('testBox'); + when(() => box.name).thenReturn('testBox'); var obj1 = TestHiveObject(); obj1.init('key1', box); var obj2 = TestHiveObject(); diff --git a/hive/test/tests/object/hive_list_impl_test.dart b/hive/test/tests/object/hive_list_impl_test.dart index b27fea22f..9a8be3dda 100644 --- a/hive/test/tests/object/hive_list_impl_test.dart +++ b/hive/test/tests/object/hive_list_impl_test.dart @@ -1,10 +1,9 @@ import 'dart:typed_data'; -import 'package:hive/hive.dart'; import 'package:hive/src/hive_impl.dart'; import 'package:hive/src/object/hive_list_impl.dart'; import 'package:hive/src/object/hive_object.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; import '../common.dart'; @@ -13,9 +12,10 @@ import '../mocks.dart'; HiveObject _getHiveObject(String key, MockBox box) { var hiveObject = TestHiveObject(); hiveObject.init(key, box); - when(box.get(key, defaultValue: argThat(isNotNull, named: 'defaultValue'))) + when(() => box.get(key, + defaultValue: captureAny(that: isNotNull, named: 'defaultValue'))) .thenReturn(hiveObject); - when(box.get(key)).thenReturn(hiveObject); + when(() => box.get(key)).thenReturn(hiveObject); return hiveObject; } @@ -23,7 +23,7 @@ MockBox _mockBox() { var box = MockBox(); // The HiveListImpl constructor sets the boxName property to box.name, // therefore we need to return an valid String on sound null safety. - when(box.name).thenReturn('testBox'); + when(() => box.name).thenReturn('testBox'); return box; } @@ -83,10 +83,10 @@ void main() { test('creates delegate and links HiveList if delegate == null', () { var hive = MockHiveImpl(); var box = _mockBox(); - when(box.containsKey('item1')).thenReturn(true); - when(box.containsKey('item2')).thenReturn(true); - when(box.containsKey('none')).thenReturn(false); - when(hive.getBoxWithoutCheckInternal('box')).thenReturn(box); + when(() => box.containsKey('item1')).thenReturn(true); + when(() => box.containsKey('item2')).thenReturn(true); + when(() => box.containsKey('none')).thenReturn(false); + when(() => hive.getBoxWithoutCheckInternal('box')).thenReturn(box); var item1 = _getHiveObject('item1', box); var item2 = _getHiveObject('item2', box); diff --git a/hive/test/tests/object/hive_object_test.dart b/hive/test/tests/object/hive_object_test.dart index 560b95cc5..bfa5e3278 100644 --- a/hive/test/tests/object/hive_object_test.dart +++ b/hive/test/tests/object/hive_object_test.dart @@ -1,5 +1,5 @@ import 'package:hive/src/object/hive_object.dart'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; import '../common.dart'; @@ -70,7 +70,7 @@ void main() { obj.linkHiveList(list); obj.dispose(); - verify(list.invalidate()); + verify(() => list.invalidate()); }); }); @@ -106,13 +106,13 @@ void main() { test('updates object in box', () { var obj = TestHiveObject(); var box = MockBox(); - returnFutureVoid(when(box.put('key', obj))); + returnFutureVoid(when(() => box.put('key', obj))); obj.init('key', box); verifyZeroInteractions(box); obj.save(); - verify(box.put('key', obj)); + verify(() => box.put('key', obj)); }); test('throws HiveError if object is not in a box', () async { @@ -125,13 +125,13 @@ void main() { test('removes object from box', () { var obj = TestHiveObject(); var box = MockBox(); - returnFutureVoid(when(box.delete('key'))); + returnFutureVoid(when(() => box.delete('key'))); obj.init('key', box); verifyZeroInteractions(box); obj.delete(); - verify(box.delete('key')); + verify(() => box.delete('key')); }); test('throws HiveError if object is not in a box', () async { @@ -149,7 +149,7 @@ void main() { test('returns true if object is in normal box', () { var obj = TestHiveObject(); var box = MockBox(); - when(box.lazy).thenReturn(false); + when(() => box.lazy).thenReturn(false); obj.init('key', box); expect(obj.isInBox, true); @@ -159,13 +159,13 @@ void main() { () { var obj = TestHiveObject(); var box = MockBox(); - when(box.lazy).thenReturn(true); + when(() => box.lazy).thenReturn(true); obj.init('key', box); - when(box.containsKey('key')).thenReturn(true); + when(() => box.containsKey('key')).thenReturn(true); expect(obj.isInBox, true); - when(box.containsKey('key')).thenReturn(false); + when(() => box.containsKey('key')).thenReturn(false); expect(obj.isInBox, false); }); }); diff --git a/hive/test/tests/util/delegating_list_view_mixin_test.dart b/hive/test/tests/util/delegating_list_view_mixin_test.dart index 953f42291..fa675b9d5 100644 --- a/hive/test/tests/util/delegating_list_view_mixin_test.dart +++ b/hive/test/tests/util/delegating_list_view_mixin_test.dart @@ -41,7 +41,6 @@ void main() { }); test('.every()', () { - expect(testList.every((e) => e is String), isTrue); expect(testList.every((e) => e == 'b'), isFalse); }); diff --git a/hive_flutter/lib/hive_flutter.dart b/hive_flutter/lib/hive_flutter.dart index a4b2492e3..ac7f52d31 100644 --- a/hive_flutter/lib/hive_flutter.dart +++ b/hive_flutter/lib/hive_flutter.dart @@ -5,10 +5,10 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'package:hive/hive.dart'; -import 'package:path_provider/path_provider.dart' - if (dart.library.html) 'src/stub/path_provider.dart'; import 'package:path/path.dart' if (dart.library.html) 'src/stub/path.dart' as path_helper; +import 'package:path_provider/path_provider.dart' + if (dart.library.html) 'src/stub/path_provider.dart'; export 'package:hive/hive.dart'; diff --git a/hive_flutter/test/adapters/color_adapter_test.dart b/hive_flutter/test/adapters/color_adapter_test.dart index 723b96ae5..9c8a6251b 100644 --- a/hive_flutter/test/adapters/color_adapter_test.dart +++ b/hive_flutter/test/adapters/color_adapter_test.dart @@ -1,9 +1,8 @@ import 'dart:ui' show Color; -import 'package:test/test.dart'; -import 'package:hive/hive.dart'; import 'package:hive_flutter/adapters.dart'; import 'package:mockito/mockito.dart'; +import 'package:test/test.dart'; import '../mocks.dart'; diff --git a/hive_flutter/test/adapters/time_adapter_test.dart b/hive_flutter/test/adapters/time_adapter_test.dart index 1743f5279..72ae9546d 100644 --- a/hive_flutter/test/adapters/time_adapter_test.dart +++ b/hive_flutter/test/adapters/time_adapter_test.dart @@ -1,8 +1,7 @@ import 'package:flutter/material.dart' show TimeOfDay; -import 'package:test/test.dart'; -import 'package:hive/hive.dart'; import 'package:hive_flutter/adapters.dart'; import 'package:mockito/mockito.dart'; +import 'package:test/test.dart'; import '../mocks.dart'; diff --git a/hive_generator/CHANGELOG.md b/hive_generator/CHANGELOG.md index 5dc1db599..45dfed3e8 100644 --- a/hive_generator/CHANGELOG.md +++ b/hive_generator/CHANGELOG.md @@ -1,3 +1,11 @@ +## 1.1.2 + +- Updated `analyzer` version constraints + +## 1.1.1 + +- Updated dependency versions + ## 1.1.0 - Fixes empty class generates adapter with warnings - [#638](https://github.com/hivedb/hive/issues/638) diff --git a/hive_generator/lib/src/class_builder.dart b/hive_generator/lib/src/class_builder.dart index beeeba790..8b9ce0202 100644 --- a/hive_generator/lib/src/class_builder.dart +++ b/hive_generator/lib/src/class_builder.dart @@ -93,7 +93,7 @@ class ClassBuilder extends Builder { String _cast(DartType type, String variable) { var suffix = _suffixFromType(type); if (hiveListChecker.isAssignableFromType(type)) { - return '($variable as HiveList$suffix)?.castHiveList()'; + return '($variable as HiveList$suffix)$suffix.castHiveList()'; } else if (iterableChecker.isAssignableFromType(type) && !isUint8List(type)) { return '($variable as List$suffix)${_castIterable(type)}'; diff --git a/hive_generator/lib/src/type_adapter_generator.dart b/hive_generator/lib/src/type_adapter_generator.dart index 704128ad8..7f00d4a90 100644 --- a/hive_generator/lib/src/type_adapter_generator.dart +++ b/hive_generator/lib/src/type_adapter_generator.dart @@ -1,11 +1,11 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; +import 'package:hive/hive.dart'; import 'package:hive_generator/src/builder.dart'; import 'package:hive_generator/src/class_builder.dart'; import 'package:hive_generator/src/enum_builder.dart'; import 'package:hive_generator/src/helper.dart'; import 'package:source_gen/source_gen.dart'; -import 'package:hive/hive.dart'; class TypeAdapterGenerator extends GeneratorForAnnotation { static String generateName(String typeName) { @@ -136,7 +136,7 @@ class TypeAdapterGenerator extends GeneratorForAnnotation { void verifyFieldIndices(List fields) { for (var field in fields) { - check(field.index >= 0 || field.index <= 255, + check(field.index >= 0 && field.index <= 255, 'Field numbers can only be in the range 0-255.'); for (var otherField in fields) { diff --git a/hive_generator/pubspec.yaml b/hive_generator/pubspec.yaml index 655f8f816..5d041e0dc 100644 --- a/hive_generator/pubspec.yaml +++ b/hive_generator/pubspec.yaml @@ -1,22 +1,21 @@ name: hive_generator description: Extension for Hive. Automatically generates TypeAdapters to store any class. -version: 1.1.0 +version: 1.1.2 homepage: https://github.com/hivedb/hive/tree/master/hive_generator documentation: https://docs.hivedb.dev/ -environment: +environment: sdk: ">=2.12.0 <3.0.0" dependencies: build: ^2.0.0 source_gen: ^1.0.0 hive: ^2.0.4 - analyzer: ^1.0.0 + analyzer: ">=1.0.0 <4.0.0" source_helper: ^1.1.0 dev_dependencies: - test: ^1.16.0 + test: ^1.17.11 build_test: any build_runner: any - pedantic: ^1.10.0 - \ No newline at end of file + pedantic: ^1.11.1