diff --git a/boulder-dash/test/fr/enssat/BoulderDash/models/LevelModelTest.java b/boulder-dash/test/fr/enssat/BoulderDash/models/LevelModelTest.java index fe9ed99a..ae475ae1 100644 --- a/boulder-dash/test/fr/enssat/BoulderDash/models/LevelModelTest.java +++ b/boulder-dash/test/fr/enssat/BoulderDash/models/LevelModelTest.java @@ -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"); } }