mirror of https://github.com/flutter/pinball.git
parent
1f72366ec5
commit
dc98eefcc1
@ -0,0 +1,103 @@
|
||||
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';
|
||||
|
||||
import '../../helpers/helpers.dart';
|
||||
|
||||
void main() {
|
||||
group('Spaceship', () {
|
||||
late Filter filterData;
|
||||
late Fixture fixture;
|
||||
late Body body;
|
||||
late PinballGame game;
|
||||
late Ball ball;
|
||||
late SpaceshipEntrance entrance;
|
||||
late SpaceshipHole hole;
|
||||
|
||||
setUp(() {
|
||||
filterData = MockFilter();
|
||||
|
||||
fixture = MockFixture();
|
||||
when(() => fixture.filterData).thenReturn(filterData);
|
||||
|
||||
body = MockBody();
|
||||
when(() => body.fixtures).thenReturn([fixture]);
|
||||
|
||||
game = MockPinballGame();
|
||||
|
||||
ball = MockBall();
|
||||
when(() => ball.gameRef).thenReturn(game);
|
||||
when(() => ball.body).thenReturn(body);
|
||||
|
||||
entrance = MockSpaceshipEntrance();
|
||||
hole = MockSpaceshipHole();
|
||||
});
|
||||
|
||||
group('SpaceshipEntranceBallContactCallback', () {
|
||||
test('changes the ball priority on contact', () {
|
||||
SpaceshipEntranceBallContactCallback().begin(
|
||||
entrance,
|
||||
ball,
|
||||
MockContact(),
|
||||
);
|
||||
|
||||
verify(() => ball.priority = 3).called(1);
|
||||
});
|
||||
|
||||
test('re order the game children', () {
|
||||
SpaceshipEntranceBallContactCallback().begin(
|
||||
entrance,
|
||||
ball,
|
||||
MockContact(),
|
||||
);
|
||||
|
||||
verify(game.reorderChildren).called(1);
|
||||
});
|
||||
|
||||
test('changes the filter data from the ball fixtures', () {
|
||||
SpaceshipEntranceBallContactCallback().begin(
|
||||
entrance,
|
||||
ball,
|
||||
MockContact(),
|
||||
);
|
||||
|
||||
verify(() => filterData.maskBits = 0x0002).called(1);
|
||||
verify(() => filterData.categoryBits = 0x0002).called(1);
|
||||
});
|
||||
});
|
||||
|
||||
group('SpaceshipHoleBallContactCallback', () {
|
||||
test('changes the ball priority on contact', () {
|
||||
SpaceshipHoleBallContactCallback().begin(
|
||||
hole,
|
||||
ball,
|
||||
MockContact(),
|
||||
);
|
||||
|
||||
verify(() => ball.priority = 1).called(1);
|
||||
});
|
||||
|
||||
test('re order the game children', () {
|
||||
SpaceshipHoleBallContactCallback().begin(
|
||||
hole,
|
||||
ball,
|
||||
MockContact(),
|
||||
);
|
||||
|
||||
verify(game.reorderChildren).called(1);
|
||||
});
|
||||
|
||||
test('changes the filter data from the ball fixtures', () {
|
||||
SpaceshipHoleBallContactCallback().begin(
|
||||
hole,
|
||||
ball,
|
||||
MockContact(),
|
||||
);
|
||||
|
||||
verify(() => filterData.categoryBits = 0xFFFF).called(1);
|
||||
verify(() => filterData.maskBits = 0x0001).called(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in new issue