From 7fdacfac37eecf72002b369a602f70c1eb065723 Mon Sep 17 00:00:00 2001 From: Vadim Date: Fri, 9 Jun 2023 23:22:21 +0200 Subject: [PATCH] overriden `==` for `MeasuredState` --- .../state_communication_metering.dart | 28 ++++++++++++++++--- .../bloc_communication_metering_test.dart | 3 +- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/screens/metering/communication/state_communication_metering.dart b/lib/screens/metering/communication/state_communication_metering.dart index 06bedaf..2923cf1 100644 --- a/lib/screens/metering/communication/state_communication_metering.dart +++ b/lib/screens/metering/communication/state_communication_metering.dart @@ -1,4 +1,4 @@ -abstract class MeteringCommunicationState { +sealed class MeteringCommunicationState { const MeteringCommunicationState(); } @@ -6,11 +6,11 @@ class InitState extends MeteringCommunicationState { const InitState(); } -abstract class SourceState extends MeteringCommunicationState { +sealed class SourceState extends MeteringCommunicationState { const SourceState(); } -abstract class ScreenState extends MeteringCommunicationState { +sealed class ScreenState extends MeteringCommunicationState { const ScreenState(); } @@ -18,7 +18,7 @@ class MeasureState extends SourceState { const MeasureState(); } -abstract class MeasuredState extends ScreenState { +sealed class MeasuredState extends ScreenState { final double? ev100; const MeasuredState(this.ev100); @@ -26,8 +26,28 @@ abstract class MeasuredState extends ScreenState { class MeteringInProgressState extends MeasuredState { const MeteringInProgressState(super.ev100); + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + if (other.runtimeType != runtimeType) return false; + return other is MeteringInProgressState && other.ev100 == ev100; + } + + @override + int get hashCode => Object.hash(ev100, runtimeType); } class MeteringEndedState extends MeasuredState { const MeteringEndedState(super.ev100); + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + if (other.runtimeType != runtimeType) return false; + return other is MeteringEndedState && other.ev100 == ev100; + } + + @override + int get hashCode => Object.hash(ev100, runtimeType); } diff --git a/test/screens/metering/communication/bloc_communication_metering_test.dart b/test/screens/metering/communication/bloc_communication_metering_test.dart index 1313c6b..23e5a4b 100644 --- a/test/screens/metering/communication/bloc_communication_metering_test.dart +++ b/test/screens/metering/communication/bloc_communication_metering_test.dart @@ -67,6 +67,8 @@ void main() { 'Multiple consequtive in progress events', build: () => bloc, act: (bloc) async { + bloc.add(const MeteringInProgressEvent(1)); + bloc.add(const MeteringInProgressEvent(1)); bloc.add(const MeteringInProgressEvent(1)); bloc.add(const MeteringInProgressEvent(null)); bloc.add(const MeteringInProgressEvent(null)); @@ -75,7 +77,6 @@ void main() { expect: () => [ isA().having((state) => state.ev100, 'ev100', 1), isA().having((state) => state.ev100, 'ev100', null), - isA().having((state) => state.ev100, 'ev100', null), isA().having((state) => state.ev100, 'ev100', 2), ], );