From 7ed1a6e33d313811715a763565d7cb6f157f0992 Mon Sep 17 00:00:00 2001 From: alestiago Date: Mon, 28 Feb 2022 18:16:23 +0000 Subject: [PATCH] feat: tested and improved GameEvent --- lib/game/bloc/game_event.dart | 6 +++++- test/game/bloc/game_event_test.dart | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/game/bloc/game_event_test.dart diff --git a/lib/game/bloc/game_event.dart b/lib/game/bloc/game_event.dart index 807da83b..dcbafe58 100644 --- a/lib/game/bloc/game_event.dart +++ b/lib/game/bloc/game_event.dart @@ -5,12 +5,16 @@ abstract class GameEvent { const GameEvent(); } +/// Event added when a user drops a ball off the screen. class BallLost extends GameEvent { const BallLost(); } +/// Event added when a user increases it's score. class Scored extends GameEvent { - const Scored(this.points); + const Scored({ + required this.points, + }) : assert(points > 0, 'Points must be greater than 0'); final int points; } diff --git a/test/game/bloc/game_event_test.dart b/test/game/bloc/game_event_test.dart new file mode 100644 index 00000000..27f867c1 --- /dev/null +++ b/test/game/bloc/game_event_test.dart @@ -0,0 +1,24 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:pinball/game/game.dart'; + +void main() { + group('GameEvent', () { + group('BallLost', () { + test('BallLost can be instantiated', () { + expect(const BallLost(), isNotNull); + }); + }); + + group('Scored', () { + test('Scored can be instantiated', () { + expect(const Scored(points: 1), isNotNull); + }); + + test( + 'throws AssertionError ' + 'when score is smaller than 1', () { + expect(() => Scored(points: 0), throwsAssertionError); + }); + }); + }); +}