ueb10 1+2: fix delayed sound playback

This commit is contained in:
Daniel Langbein 2025-01-16 14:56:38 +01:00
parent ff0cbe4973
commit 84b42aaccd
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002

View File

@ -67,6 +67,14 @@ public class LevelModelTest {
assertEquals(2, levelModel.getRockfordPositionX());
assertEquals(2,levelModel.getRockfordPositionY());
// The sounds are played in a different thread after an action occurred.
// This might happen after we verify the number of method calls.
// To avoid this, we sleep one second.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// No sound is played
verify(audioLoadHelper, never()).playSound(anyString());
}
@ -113,7 +121,15 @@ public class LevelModelTest {
// The starting field of Rockford becomes an empty field
assertInstanceOf(EmptyModel.class, groundLevelModel[1][1]);
//The sound for collecting a diamond is played.
// The sounds are played in a different thread after an action occurred.
// This might happen after we verify the number of method calls (which would make this test fail).
// To avoid this, we sleep one second.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// The sound for collecting a diamond is played.
verify(audioLoadHelper).playSound("coin");
}
@ -172,7 +188,15 @@ public class LevelModelTest {
// `this.groundGrid[oldX][oldY] = new EmptyModel();`
assertInstanceOf(EmptyModel.class, groundLevelModel[1][1]);
// play sound
// The sounds are played in a different thread after an action occurred.
// This might happen after we verify the number of method calls (which would make this test fail).
// To avoid this, we sleep one second.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// The sound for collecting a diamond is played.
verify(audioLoadHelper).playSound("coin");
}
}