|
|
|
@ -14,6 +14,28 @@ class MyBlueprint extends Blueprint {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyOtherBlueprint extends Blueprint {
|
|
|
|
|
@override
|
|
|
|
|
void build(_) {
|
|
|
|
|
add(Component());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class YetMyOtherBlueprint extends Blueprint {
|
|
|
|
|
@override
|
|
|
|
|
void build(_) {
|
|
|
|
|
add(Component());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyComposedBlueprint extends Blueprint {
|
|
|
|
|
@override
|
|
|
|
|
void build(_) {
|
|
|
|
|
addBlueprint(MyBlueprint());
|
|
|
|
|
addAllBlueprints([MyOtherBlueprint(), YetMyOtherBlueprint()]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyForge2dBlueprint extends Forge2DBlueprint {
|
|
|
|
|
@override
|
|
|
|
|
void build(_) {
|
|
|
|
@ -24,12 +46,23 @@ class MyForge2dBlueprint extends Forge2DBlueprint {
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
group('Blueprint', () {
|
|
|
|
|
setUpAll(() {
|
|
|
|
|
registerFallbackValue(MyBlueprint());
|
|
|
|
|
registerFallbackValue(Component());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('components can be added to it', () {
|
|
|
|
|
final blueprint = MyBlueprint()..build(MockPinballGame());
|
|
|
|
|
|
|
|
|
|
expect(blueprint.components.length, equals(3));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('blueprints can be added to it', () {
|
|
|
|
|
final blueprint = MyComposedBlueprint()..build(MockPinballGame());
|
|
|
|
|
|
|
|
|
|
expect(blueprint.blueprints.length, equals(3));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('adds the components to a game on attach', () {
|
|
|
|
|
final mockGame = MockPinballGame();
|
|
|
|
|
when(() => mockGame.addAll(any())).thenAnswer((_) async {});
|
|
|
|
@ -38,6 +71,14 @@ void main() {
|
|
|
|
|
verify(() => mockGame.addAll(any())).called(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('adds components from a child Blueprint the to a game on attach', () {
|
|
|
|
|
final mockGame = MockPinballGame();
|
|
|
|
|
when(() => mockGame.addAll(any())).thenAnswer((_) async {});
|
|
|
|
|
MyComposedBlueprint().attach(mockGame);
|
|
|
|
|
|
|
|
|
|
verify(() => mockGame.addAll(any())).called(4);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
'throws assertion error when adding to an already attached blueprint',
|
|
|
|
|
() async {
|
|
|
|
|