suggestions

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

@ -51,7 +51,7 @@ void main() {
late _MockLoopSingleAudio loopSingleAudio;
late _PreCacheSingleAudio preCacheSingleAudio;
late Random seed;
late PinballAudioPlayer player;
late PinballAudioPlayer audioPlayer;
setUpAll(() {
registerFallbackValue(_MockAudioCache());
@ -81,7 +81,7 @@ void main() {
seed = _MockRandom();
player = PinballAudioPlayer(
audioPlayer = PinballAudioPlayer(
configureAudioCache: configureAudioCache.onCall,
createAudioPool: createAudioPool.onCall,
playSingleAudio: playSingleAudio.onCall,
@ -97,7 +97,7 @@ void main() {
group('load', () {
test('creates the bumpers pools', () async {
await Future.wait(player.load());
await Future.wait(audioPlayer.load());
verify(
() => createAudioPool.onCall(
@ -117,25 +117,25 @@ void main() {
});
test('configures the audio cache instance', () async {
await Future.wait(player.load());
await Future.wait(audioPlayer.load());
verify(() => configureAudioCache.onCall(FlameAudio.audioCache))
.called(1);
});
test('sets the correct prefix', () async {
player = PinballAudioPlayer(
audioPlayer = PinballAudioPlayer(
createAudioPool: createAudioPool.onCall,
playSingleAudio: playSingleAudio.onCall,
preCacheSingleAudio: preCacheSingleAudio.onCall,
);
await Future.wait(player.load());
await Future.wait(audioPlayer.load());
expect(FlameAudio.audioCache.prefix, equals(''));
});
test('pre cache the assets', () async {
await Future.wait(player.load());
await Future.wait(audioPlayer.load());
verify(
() => preCacheSingleAudio
@ -209,8 +209,8 @@ void main() {
group('when seed is true', () {
test('plays the bumper A sound pool', () async {
when(seed.nextBool).thenReturn(true);
await Future.wait(player.load());
player.play(PinballAudio.bumper);
await Future.wait(audioPlayer.load());
audioPlayer.play(PinballAudio.bumper);
verify(() => bumperAPool.start(volume: 0.6)).called(1);
});
@ -219,8 +219,8 @@ void main() {
group('when seed is false', () {
test('plays the bumper B sound pool', () async {
when(seed.nextBool).thenReturn(false);
await Future.wait(player.load());
player.play(PinballAudio.bumper);
await Future.wait(audioPlayer.load());
audioPlayer.play(PinballAudio.bumper);
verify(() => bumperBPool.start(volume: 0.6)).called(1);
});
@ -229,8 +229,8 @@ void main() {
group('google', () {
test('plays the correct file', () async {
await Future.wait(player.load());
player.play(PinballAudio.google);
await Future.wait(audioPlayer.load());
audioPlayer.play(PinballAudio.google);
verify(
() => playSingleAudio
@ -241,8 +241,8 @@ void main() {
group('sparky', () {
test('plays the correct file', () async {
await Future.wait(player.load());
player.play(PinballAudio.sparky);
await Future.wait(audioPlayer.load());
audioPlayer.play(PinballAudio.sparky);
verify(
() => playSingleAudio
@ -253,8 +253,8 @@ void main() {
group('dino', () {
test('plays the correct file', () async {
await Future.wait(player.load());
player.play(PinballAudio.dino);
await Future.wait(audioPlayer.load());
audioPlayer.play(PinballAudio.dino);
verify(
() => playSingleAudio
@ -265,8 +265,8 @@ void main() {
group('android', () {
test('plays the correct file', () async {
await Future.wait(player.load());
player.play(PinballAudio.android);
await Future.wait(audioPlayer.load());
audioPlayer.play(PinballAudio.android);
verify(
() => playSingleAudio
@ -277,8 +277,8 @@ void main() {
group('dash', () {
test('plays the correct file', () async {
await Future.wait(player.load());
player.play(PinballAudio.dash);
await Future.wait(audioPlayer.load());
audioPlayer.play(PinballAudio.dash);
verify(
() => playSingleAudio
@ -289,8 +289,8 @@ void main() {
group('launcher', () {
test('plays the correct file', () async {
await Future.wait(player.load());
player.play(PinballAudio.launcher);
await Future.wait(audioPlayer.load());
audioPlayer.play(PinballAudio.launcher);
verify(
() => playSingleAudio
@ -301,8 +301,8 @@ void main() {
group('ioPinballVoiceOver', () {
test('plays the correct file', () async {
await Future.wait(player.load());
player.play(PinballAudio.ioPinballVoiceOver);
await Future.wait(audioPlayer.load());
audioPlayer.play(PinballAudio.ioPinballVoiceOver);
verify(
() => playSingleAudio.onCall(
@ -314,8 +314,8 @@ void main() {
group('gameOverVoiceOver', () {
test('plays the correct file', () async {
await Future.wait(player.load());
player.play(PinballAudio.gameOverVoiceOver);
await Future.wait(audioPlayer.load());
audioPlayer.play(PinballAudio.gameOverVoiceOver);
verify(
() => playSingleAudio.onCall(
@ -327,8 +327,8 @@ void main() {
group('backgroundMusic', () {
test('plays the correct file', () async {
await Future.wait(player.load());
player.play(PinballAudio.backgroundMusic);
await Future.wait(audioPlayer.load());
audioPlayer.play(PinballAudio.backgroundMusic);
verify(
() => loopSingleAudio
@ -340,10 +340,13 @@ void main() {
test(
'throws assertions error when playing an unregistered audio',
() async {
player.audios.remove(PinballAudio.google);
await Future.wait(player.load());
audioPlayer.audios.remove(PinballAudio.google);
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 {
Future<void> pump(
BonusNoiseBehavior child, {
required PinballAudioPlayer player,
required PinballAudioPlayer audioPlayer,
required GameBloc bloc,
}) {
return ensureAdd(
@ -22,7 +22,7 @@ class _TestGame extends Forge2DGame {
value: bloc,
children: [
FlameProvider<PinballAudioPlayer>.value(
player,
audioPlayer,
children: [
child,
],
@ -41,7 +41,7 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('BonusNoiseBehavior', () {
late PinballAudioPlayer player;
late PinballAudioPlayer audioPlayer;
late GameBloc bloc;
final flameTester = FlameTester(_TestGame.new);
@ -50,8 +50,8 @@ void main() {
});
setUp(() {
player = _MockPinballAudioPlayer();
when(() => player.play(any())).thenAnswer((_) {});
audioPlayer = _MockPinballAudioPlayer();
when(() => audioPlayer.play(any())).thenAnswer((_) {});
bloc = _MockGameBloc();
});
@ -73,10 +73,10 @@ void main() {
initialState: initialState,
);
final behavior = BonusNoiseBehavior();
await game.pump(behavior, player: player, bloc: bloc);
await game.pump(behavior, audioPlayer: audioPlayer, bloc: bloc);
},
verify: (_, __) async {
verify(() => player.play(PinballAudio.google)).called(1);
verify(() => audioPlayer.play(PinballAudio.google)).called(1);
},
);
@ -98,10 +98,10 @@ void main() {
initialState: initialState,
);
final behavior = BonusNoiseBehavior();
await game.pump(behavior, player: player, bloc: bloc);
await game.pump(behavior, audioPlayer: audioPlayer, bloc: bloc);
},
verify: (_, __) async {
verify(() => player.play(PinballAudio.sparky)).called(1);
verify(() => audioPlayer.play(PinballAudio.sparky)).called(1);
},
);
@ -123,10 +123,10 @@ void main() {
initialState: initialState,
);
final behavior = BonusNoiseBehavior();
await game.pump(behavior, player: player, bloc: bloc);
await game.pump(behavior, audioPlayer: audioPlayer, bloc: bloc);
},
verify: (_, __) async {
verify(() => player.play(PinballAudio.dino)).called(1);
verify(() => audioPlayer.play(PinballAudio.dino)).called(1);
},
);
@ -148,10 +148,10 @@ void main() {
initialState: initialState,
);
final behavior = BonusNoiseBehavior();
await game.pump(behavior, player: player, bloc: bloc);
await game.pump(behavior, audioPlayer: audioPlayer, bloc: bloc);
},
verify: (_, __) async {
verify(() => player.play(PinballAudio.android)).called(1);
verify(() => audioPlayer.play(PinballAudio.android)).called(1);
},
);
@ -173,10 +173,10 @@ void main() {
initialState: initialState,
);
final behavior = BonusNoiseBehavior();
await game.pump(behavior, player: player, bloc: bloc);
await game.pump(behavior, audioPlayer: audioPlayer, bloc: bloc);
},
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 {
Future<void> pump(
_TestBodyComponent child, {
required PinballAudioPlayer player,
required PinballAudioPlayer audioPlayer,
}) {
return ensureAdd(
FlameProvider<PinballAudioPlayer>.value(
player,
audioPlayer,
children: [
child,
],
@ -38,11 +38,11 @@ void main() {
group('BumperNoiseBehavior', () {});
late PinballAudioPlayer player;
late PinballAudioPlayer audioPlayer;
final flameTester = FlameTester(_TestGame.new);
setUp(() {
player = _MockPinballAudioPlayer();
audioPlayer = _MockPinballAudioPlayer();
});
flameTester.testGameWidget(
@ -50,12 +50,12 @@ void main() {
setUp: (game, _) async {
final behavior = BumperNoiseBehavior();
final parent = _TestBodyComponent();
await game.pump(parent, player: player);
await game.pump(parent, audioPlayer: audioPlayer);
await parent.ensureAdd(behavior);
behavior.beginContact(Object(), _MockContact());
},
verify: (_, __) async {
verify(() => player.play(PinballAudio.bumper)).called(1);
verify(() => audioPlayer.play(PinballAudio.bumper)).called(1);
},
);
}

@ -158,17 +158,17 @@ void main() {
});
group('PlungerNoiseBehavior', () {
late PinballAudioPlayer player;
late PinballAudioPlayer audioPlayer;
setUp(() {
player = _MockPinballAudioPlayer();
audioPlayer = _MockPinballAudioPlayer();
});
flameTester.test('plays the correct sound on load', (game) async {
final parent = ControlledPlunger(compressionDistance: 10);
await game.pump(parent, pinballAudioPlayer: player);
await game.pump(parent, pinballAudioPlayer: audioPlayer);
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', () {

Loading…
Cancel
Save