From 33945a9932186c73c1ff1f0f6f8d82d2d664a361 Mon Sep 17 00:00:00 2001 From: zin- Date: Sat, 31 Aug 2024 11:50:14 +0900 Subject: [PATCH] fix: `Analyze Test code` wip #377 --- .../database_tuple_repository_tests.dart | 28 +++++++++---------- .../repository/key_with_value_repository.dart | 9 ++++-- .../notification_repository.dart | 4 +-- .../database_tuple_entity_test.dart | 26 ----------------- test/framework/repository/entity_test.dart | 15 ---------- 5 files changed, 21 insertions(+), 61 deletions(-) diff --git a/integration_test/framework/database_tuple_repository_tests.dart b/integration_test/framework/database_tuple_repository_tests.dart index e9a17d3d3..17967eb06 100644 --- a/integration_test/framework/database_tuple_repository_tests.dart +++ b/integration_test/framework/database_tuple_repository_tests.dart @@ -248,21 +248,19 @@ void main() => group( }, ); - test( - ': updated.', - () async { - final updatedAt = DateTime.now(); - final updating = savedFalseSample.copiedWith( - a: () => true, - ); - - final updated = await repository.replace(updating, - updatedAt: updatedAt); - - expect(updated.a, equals(updating.a)); - expect(updated.updatedAt, equals(updatedAt)); - }, - ); + test(': updated.', () async { + final updatedAt = DateTime.now(); + final updating = TestObjectDatabaseTupleEntity.fromMap( + savedFalseSample.toMap + ..update( + TestObjectEntity.fieldNames[0], (value) => false)); + + final updated = + await repository.replace(updating, updatedAt: updatedAt); + + expect(updated.a, equals(updating.a)); + expect(updated.updatedAt, equals(updatedAt)); + }); }, ); diff --git a/lib/framework/repository/key_with_value_repository.dart b/lib/framework/repository/key_with_value_repository.dart index a092f65ac..ee6be118d 100644 --- a/lib/framework/repository/key_with_value_repository.dart +++ b/lib/framework/repository/key_with_value_repository.dart @@ -3,9 +3,12 @@ import 'package:mem/framework/repository/repository.dart'; abstract class KeyWithValueRepository, KEY> extends Repository { - Future receive(ENTITY entity) => throw UnimplementedError(); + Future receive(ENTITY entity); - Future discard(KEY key) => throw UnimplementedError(); + Future discard(KEY key); +} - Future discardAll() => throw UnimplementedError(); +mixin DiscardAll, KEY> + on KeyWithValueRepository { + Future discardAll(); } diff --git a/lib/notifications/notification_repository.dart b/lib/notifications/notification_repository.dart index d75a4bebe..0ad7cc595 100644 --- a/lib/notifications/notification_repository.dart +++ b/lib/notifications/notification_repository.dart @@ -9,8 +9,8 @@ import 'package:mem/values/paths.dart'; import 'notification/notification.dart'; import 'flutter_local_notifications_wrapper.dart'; -class NotificationRepository - extends KeyWithValueRepository { +class NotificationRepository extends KeyWithValueRepository + with DiscardAll { final FlutterLocalNotificationsWrapper? _flutterLocalNotificationsWrapper = defaultTargetPlatform == TargetPlatform.android ? FlutterLocalNotificationsWrapper(androidDefaultIconPath) diff --git a/test/framework/repository/database_tuple_entity_test.dart b/test/framework/repository/database_tuple_entity_test.dart index 6c2e1d0fe..536d42ea9 100644 --- a/test/framework/repository/database_tuple_entity_test.dart +++ b/test/framework/repository/database_tuple_entity_test.dart @@ -14,11 +14,6 @@ class TestObjectDatabaseTupleEntity extends TestObjectEntity : super.fromMap(map) { withMap(map); } - - @override - TestObjectDatabaseTupleEntity copiedWith({bool Function()? a}) => - TestObjectDatabaseTupleEntity.fromMap( - toMap..addAll(super.copiedWith(a: a).toMap)); } void main() => group( @@ -68,26 +63,5 @@ void main() => group( expect(testObject.toMap, map); }, ); - - test( - '#copiedWith', - () { - final from = TestObjectDatabaseTupleEntity.fromMap({ - TestObjectEntity.fieldNames[0]: false, - defPkId.name: 1, - defColCreatedAt.name: DateTime.now(), - defColUpdatedAt.name: DateTime.now(), - defColArchivedAt.name: DateTime.now() - }); - - final copied = from.copiedWith(a: () => true); - - expect(copied.a, equals(true)); - expect(copied.id, equals(from.id)); - expect(copied.createdAt, equals(from.createdAt)); - expect(copied.updatedAt, equals(from.updatedAt)); - expect(copied.archivedAt, equals(from.archivedAt)); - }, - ); }, ); diff --git a/test/framework/repository/entity_test.dart b/test/framework/repository/entity_test.dart index 549276528..47bc819b6 100644 --- a/test/framework/repository/entity_test.dart +++ b/test/framework/repository/entity_test.dart @@ -19,10 +19,6 @@ class TestObjectEntity extends _TestObject with Entity { @override Map get toMap => {fieldNames[0]: a}; - - @override - TestObjectEntity copiedWith({bool Function()? a}) => - TestObjectEntity(a == null ? this.a : a()); } void main() => group( @@ -74,16 +70,5 @@ void main() => group( expect(testObjectA, equals(testObjectB)); }, ); - - test( - '#copiedWith', - () { - final from = TestObjectEntity(false); - - final copied = from.copiedWith(a: () => true); - - expect(copied.a, equals(true)); - }, - ); }, );