mirror of https://github.com/flutter/pinball.git
parent
18e1f950ad
commit
fbf9b39ee3
@ -1 +1,2 @@
|
|||||||
export 'ball.dart';
|
export 'ball.dart';
|
||||||
|
export 'score_points.dart';
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
// ignore_for_file: avoid_renaming_method_parameters
|
||||||
|
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:pinball/game/game.dart';
|
||||||
|
|
||||||
|
mixin ScorePoints {
|
||||||
|
int get points;
|
||||||
|
}
|
||||||
|
|
||||||
|
class BallHasScoreCallback extends ContactCallback<Ball, ScorePoints> {
|
||||||
|
@override
|
||||||
|
void begin(
|
||||||
|
Ball ball,
|
||||||
|
ScorePoints hasPoints,
|
||||||
|
Contact _,
|
||||||
|
) {
|
||||||
|
ball.gameRef.read<GameBloc>().add(Scored(points: hasPoints.points));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void end(Ball _, ScorePoints __, Contact ___) {}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
import 'package:pinball/game/game.dart';
|
||||||
|
|
||||||
|
class MockHasScore extends Mock with ScorePoints {}
|
||||||
|
|
||||||
|
class MockBall extends Mock implements Ball {}
|
||||||
|
|
||||||
|
class MockGameBloc extends Mock implements GameBloc {}
|
||||||
|
|
||||||
|
class MockPinballGame extends Mock implements PinballGame {}
|
||||||
|
|
||||||
|
class FakeContact extends Fake implements Contact {}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('BallHasScoreCallback', () {
|
||||||
|
late MockPinballGame game;
|
||||||
|
late MockGameBloc bloc;
|
||||||
|
late MockBall ball;
|
||||||
|
late MockHasScore hasScore;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
game = MockPinballGame();
|
||||||
|
bloc = MockGameBloc();
|
||||||
|
ball = MockBall();
|
||||||
|
hasScore = MockHasScore();
|
||||||
|
});
|
||||||
|
|
||||||
|
group('begin', () {
|
||||||
|
test(
|
||||||
|
'emits Scored event with points',
|
||||||
|
() {
|
||||||
|
const points = 2;
|
||||||
|
|
||||||
|
when<PinballGame>(() => ball.gameRef).thenReturn(game);
|
||||||
|
when<GameBloc>(game.read).thenReturn(bloc);
|
||||||
|
when<int>(() => hasScore.points).thenReturn(points);
|
||||||
|
|
||||||
|
BallHasScoreCallback().begin(
|
||||||
|
ball,
|
||||||
|
hasScore,
|
||||||
|
FakeContact(),
|
||||||
|
);
|
||||||
|
|
||||||
|
verify(
|
||||||
|
() => bloc.add(const Scored(points: points)),
|
||||||
|
).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('end', () {
|
||||||
|
test('does nothing', () {
|
||||||
|
// TODO(alestiago): Write test.
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue