suggestions

pull/396/head
Erick Zanardo 3 years ago
parent b316e9952e
commit 8cc309804a

@ -51,7 +51,7 @@ void main() {
late _MockLoopSingleAudio loopSingleAudio; late _MockLoopSingleAudio loopSingleAudio;
late _PreCacheSingleAudio preCacheSingleAudio; late _PreCacheSingleAudio preCacheSingleAudio;
late Random seed; late Random seed;
late PinballAudioPlayer player; late PinballAudioPlayer audioPlayer;
setUpAll(() { setUpAll(() {
registerFallbackValue(_MockAudioCache()); registerFallbackValue(_MockAudioCache());
@ -81,7 +81,7 @@ void main() {
seed = _MockRandom(); seed = _MockRandom();
player = PinballAudioPlayer( audioPlayer = PinballAudioPlayer(
configureAudioCache: configureAudioCache.onCall, configureAudioCache: configureAudioCache.onCall,
createAudioPool: createAudioPool.onCall, createAudioPool: createAudioPool.onCall,
playSingleAudio: playSingleAudio.onCall, playSingleAudio: playSingleAudio.onCall,
@ -97,7 +97,7 @@ void main() {
group('load', () { group('load', () {
test('creates the bumpers pools', () async { test('creates the bumpers pools', () async {
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
verify( verify(
() => createAudioPool.onCall( () => createAudioPool.onCall(
@ -117,25 +117,25 @@ void main() {
}); });
test('configures the audio cache instance', () async { test('configures the audio cache instance', () async {
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
verify(() => configureAudioCache.onCall(FlameAudio.audioCache)) verify(() => configureAudioCache.onCall(FlameAudio.audioCache))
.called(1); .called(1);
}); });
test('sets the correct prefix', () async { test('sets the correct prefix', () async {
player = PinballAudioPlayer( audioPlayer = PinballAudioPlayer(
createAudioPool: createAudioPool.onCall, createAudioPool: createAudioPool.onCall,
playSingleAudio: playSingleAudio.onCall, playSingleAudio: playSingleAudio.onCall,
preCacheSingleAudio: preCacheSingleAudio.onCall, preCacheSingleAudio: preCacheSingleAudio.onCall,
); );
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
expect(FlameAudio.audioCache.prefix, equals('')); expect(FlameAudio.audioCache.prefix, equals(''));
}); });
test('pre cache the assets', () async { test('pre cache the assets', () async {
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
verify( verify(
() => preCacheSingleAudio () => preCacheSingleAudio
@ -209,8 +209,8 @@ void main() {
group('when seed is true', () { group('when seed is true', () {
test('plays the bumper A sound pool', () async { test('plays the bumper A sound pool', () async {
when(seed.nextBool).thenReturn(true); when(seed.nextBool).thenReturn(true);
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
player.play(PinballAudio.bumper); audioPlayer.play(PinballAudio.bumper);
verify(() => bumperAPool.start(volume: 0.6)).called(1); verify(() => bumperAPool.start(volume: 0.6)).called(1);
}); });
@ -219,8 +219,8 @@ void main() {
group('when seed is false', () { group('when seed is false', () {
test('plays the bumper B sound pool', () async { test('plays the bumper B sound pool', () async {
when(seed.nextBool).thenReturn(false); when(seed.nextBool).thenReturn(false);
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
player.play(PinballAudio.bumper); audioPlayer.play(PinballAudio.bumper);
verify(() => bumperBPool.start(volume: 0.6)).called(1); verify(() => bumperBPool.start(volume: 0.6)).called(1);
}); });
@ -229,8 +229,8 @@ void main() {
group('google', () { group('google', () {
test('plays the correct file', () async { test('plays the correct file', () async {
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
player.play(PinballAudio.google); audioPlayer.play(PinballAudio.google);
verify( verify(
() => playSingleAudio () => playSingleAudio
@ -241,8 +241,8 @@ void main() {
group('sparky', () { group('sparky', () {
test('plays the correct file', () async { test('plays the correct file', () async {
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
player.play(PinballAudio.sparky); audioPlayer.play(PinballAudio.sparky);
verify( verify(
() => playSingleAudio () => playSingleAudio
@ -253,8 +253,8 @@ void main() {
group('dino', () { group('dino', () {
test('plays the correct file', () async { test('plays the correct file', () async {
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
player.play(PinballAudio.dino); audioPlayer.play(PinballAudio.dino);
verify( verify(
() => playSingleAudio () => playSingleAudio
@ -265,8 +265,8 @@ void main() {
group('android', () { group('android', () {
test('plays the correct file', () async { test('plays the correct file', () async {
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
player.play(PinballAudio.android); audioPlayer.play(PinballAudio.android);
verify( verify(
() => playSingleAudio () => playSingleAudio
@ -277,8 +277,8 @@ void main() {
group('dash', () { group('dash', () {
test('plays the correct file', () async { test('plays the correct file', () async {
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
player.play(PinballAudio.dash); audioPlayer.play(PinballAudio.dash);
verify( verify(
() => playSingleAudio () => playSingleAudio
@ -289,8 +289,8 @@ void main() {
group('launcher', () { group('launcher', () {
test('plays the correct file', () async { test('plays the correct file', () async {
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
player.play(PinballAudio.launcher); audioPlayer.play(PinballAudio.launcher);
verify( verify(
() => playSingleAudio () => playSingleAudio
@ -301,8 +301,8 @@ void main() {
group('ioPinballVoiceOver', () { group('ioPinballVoiceOver', () {
test('plays the correct file', () async { test('plays the correct file', () async {
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
player.play(PinballAudio.ioPinballVoiceOver); audioPlayer.play(PinballAudio.ioPinballVoiceOver);
verify( verify(
() => playSingleAudio.onCall( () => playSingleAudio.onCall(
@ -314,8 +314,8 @@ void main() {
group('gameOverVoiceOver', () { group('gameOverVoiceOver', () {
test('plays the correct file', () async { test('plays the correct file', () async {
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
player.play(PinballAudio.gameOverVoiceOver); audioPlayer.play(PinballAudio.gameOverVoiceOver);
verify( verify(
() => playSingleAudio.onCall( () => playSingleAudio.onCall(
@ -327,8 +327,8 @@ void main() {
group('backgroundMusic', () { group('backgroundMusic', () {
test('plays the correct file', () async { test('plays the correct file', () async {
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
player.play(PinballAudio.backgroundMusic); audioPlayer.play(PinballAudio.backgroundMusic);
verify( verify(
() => loopSingleAudio () => loopSingleAudio
@ -340,10 +340,13 @@ void main() {
test( test(
'throws assertions error when playing an unregistered audio', 'throws assertions error when playing an unregistered audio',
() async { () async {
player.audios.remove(PinballAudio.google); audioPlayer.audios.remove(PinballAudio.google);
await Future.wait(player.load()); await Future.wait(audioPlayer.load());
expect(() => player.play(PinballAudio.google), throwsAssertionError); expect(
() => audioPlayer.play(PinballAudio.google),
throwsAssertionError,
);
}, },
); );
}); });

@ -14,7 +14,7 @@ import 'package:pinball_flame/pinball_flame.dart';
class _TestGame extends Forge2DGame { class _TestGame extends Forge2DGame {
Future<void> pump( Future<void> pump(
BonusNoiseBehavior child, { BonusNoiseBehavior child, {
required PinballAudioPlayer player, required PinballAudioPlayer audioPlayer,
required GameBloc bloc, required GameBloc bloc,
}) { }) {
return ensureAdd( return ensureAdd(
@ -22,7 +22,7 @@ class _TestGame extends Forge2DGame {
value: bloc, value: bloc,
children: [ children: [
FlameProvider<PinballAudioPlayer>.value( FlameProvider<PinballAudioPlayer>.value(
player, audioPlayer,
children: [ children: [
child, child,
], ],
@ -41,7 +41,7 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
group('BonusNoiseBehavior', () { group('BonusNoiseBehavior', () {
late PinballAudioPlayer player; late PinballAudioPlayer audioPlayer;
late GameBloc bloc; late GameBloc bloc;
final flameTester = FlameTester(_TestGame.new); final flameTester = FlameTester(_TestGame.new);
@ -50,8 +50,8 @@ void main() {
}); });
setUp(() { setUp(() {
player = _MockPinballAudioPlayer(); audioPlayer = _MockPinballAudioPlayer();
when(() => player.play(any())).thenAnswer((_) {}); when(() => audioPlayer.play(any())).thenAnswer((_) {});
bloc = _MockGameBloc(); bloc = _MockGameBloc();
}); });
@ -73,10 +73,10 @@ void main() {
initialState: initialState, initialState: initialState,
); );
final behavior = BonusNoiseBehavior(); final behavior = BonusNoiseBehavior();
await game.pump(behavior, player: player, bloc: bloc); await game.pump(behavior, audioPlayer: audioPlayer, bloc: bloc);
}, },
verify: (_, __) async { verify: (_, __) async {
verify(() => player.play(PinballAudio.google)).called(1); verify(() => audioPlayer.play(PinballAudio.google)).called(1);
}, },
); );
@ -98,10 +98,10 @@ void main() {
initialState: initialState, initialState: initialState,
); );
final behavior = BonusNoiseBehavior(); final behavior = BonusNoiseBehavior();
await game.pump(behavior, player: player, bloc: bloc); await game.pump(behavior, audioPlayer: audioPlayer, bloc: bloc);
}, },
verify: (_, __) async { verify: (_, __) async {
verify(() => player.play(PinballAudio.sparky)).called(1); verify(() => audioPlayer.play(PinballAudio.sparky)).called(1);
}, },
); );
@ -123,10 +123,10 @@ void main() {
initialState: initialState, initialState: initialState,
); );
final behavior = BonusNoiseBehavior(); final behavior = BonusNoiseBehavior();
await game.pump(behavior, player: player, bloc: bloc); await game.pump(behavior, audioPlayer: audioPlayer, bloc: bloc);
}, },
verify: (_, __) async { verify: (_, __) async {
verify(() => player.play(PinballAudio.dino)).called(1); verify(() => audioPlayer.play(PinballAudio.dino)).called(1);
}, },
); );
@ -148,10 +148,10 @@ void main() {
initialState: initialState, initialState: initialState,
); );
final behavior = BonusNoiseBehavior(); final behavior = BonusNoiseBehavior();
await game.pump(behavior, player: player, bloc: bloc); await game.pump(behavior, audioPlayer: audioPlayer, bloc: bloc);
}, },
verify: (_, __) async { verify: (_, __) async {
verify(() => player.play(PinballAudio.android)).called(1); verify(() => audioPlayer.play(PinballAudio.android)).called(1);
}, },
); );
@ -173,10 +173,10 @@ void main() {
initialState: initialState, initialState: initialState,
); );
final behavior = BonusNoiseBehavior(); final behavior = BonusNoiseBehavior();
await game.pump(behavior, player: player, bloc: bloc); await game.pump(behavior, audioPlayer: audioPlayer, bloc: bloc);
}, },
verify: (_, __) async { verify: (_, __) async {
verify(() => player.play(PinballAudio.dash)).called(1); verify(() => audioPlayer.play(PinballAudio.dash)).called(1);
}, },
); );
}); });

@ -11,11 +11,11 @@ import 'package:pinball_flame/pinball_flame.dart';
class _TestGame extends Forge2DGame { class _TestGame extends Forge2DGame {
Future<void> pump( Future<void> pump(
_TestBodyComponent child, { _TestBodyComponent child, {
required PinballAudioPlayer player, required PinballAudioPlayer audioPlayer,
}) { }) {
return ensureAdd( return ensureAdd(
FlameProvider<PinballAudioPlayer>.value( FlameProvider<PinballAudioPlayer>.value(
player, audioPlayer,
children: [ children: [
child, child,
], ],
@ -38,11 +38,11 @@ void main() {
group('BumperNoiseBehavior', () {}); group('BumperNoiseBehavior', () {});
late PinballAudioPlayer player; late PinballAudioPlayer audioPlayer;
final flameTester = FlameTester(_TestGame.new); final flameTester = FlameTester(_TestGame.new);
setUp(() { setUp(() {
player = _MockPinballAudioPlayer(); audioPlayer = _MockPinballAudioPlayer();
}); });
flameTester.testGameWidget( flameTester.testGameWidget(
@ -50,12 +50,12 @@ void main() {
setUp: (game, _) async { setUp: (game, _) async {
final behavior = BumperNoiseBehavior(); final behavior = BumperNoiseBehavior();
final parent = _TestBodyComponent(); final parent = _TestBodyComponent();
await game.pump(parent, player: player); await game.pump(parent, audioPlayer: audioPlayer);
await parent.ensureAdd(behavior); await parent.ensureAdd(behavior);
behavior.beginContact(Object(), _MockContact()); behavior.beginContact(Object(), _MockContact());
}, },
verify: (_, __) async { verify: (_, __) async {
verify(() => player.play(PinballAudio.bumper)).called(1); verify(() => audioPlayer.play(PinballAudio.bumper)).called(1);
}, },
); );
} }

@ -158,17 +158,17 @@ void main() {
}); });
group('PlungerNoiseBehavior', () { group('PlungerNoiseBehavior', () {
late PinballAudioPlayer player; late PinballAudioPlayer audioPlayer;
setUp(() { setUp(() {
player = _MockPinballAudioPlayer(); audioPlayer = _MockPinballAudioPlayer();
}); });
flameTester.test('plays the correct sound on load', (game) async { flameTester.test('plays the correct sound on load', (game) async {
final parent = ControlledPlunger(compressionDistance: 10); final parent = ControlledPlunger(compressionDistance: 10);
await game.pump(parent, pinballAudioPlayer: player); await game.pump(parent, pinballAudioPlayer: audioPlayer);
await parent.ensureAdd(PlungerNoiseBehavior()); await parent.ensureAdd(PlungerNoiseBehavior());
verify(() => player.play(PinballAudio.launcher)).called(1); verify(() => audioPlayer.play(PinballAudio.launcher)).called(1);
}); });
test('is removed on the first update', () { test('is removed on the first update', () {

Loading…
Cancel
Save