Skip to content

Commit

Permalink
(#3, #23) add missing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasstarsz committed Aug 9, 2021
1 parent 9c105db commit d484873
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ void checkSetLoopCount_toAudioStopLooping() {
assertFalse(audio.shouldLoop(), "Setting the loop to \"Audio.StopLooping\" should cause the audio to not need to loop.");
}

@Test
void checkSetLoopCount_toContinuousLoop() {
MemoryAudio audio = AudioManager.loadMemoryAudio(TestAudioPath);

int expectedLoopCount = MemoryAudio.ContinuousLoop;
audio.setLoopCount(expectedLoopCount);

assertEquals(expectedLoopCount, audio.getLoopCount(), "The audio loop count should be set.");
assertTrue(audio.shouldLoop(), "Setting the loop to \"Audio.ContinuousLoop\" should cause the audio to need to loop.");
}

@Test
void trySetLoopCount_toInvalidValue() {
MemoryAudio audio = AudioManager.loadMemoryAudio(TestAudioPath);
Expand All @@ -135,6 +146,20 @@ void trySetLoopCount_toInvalidValue() {
assertEquals(expectedExceptionMessage, exception.getMessage(), "The expected error message should match the actual error message.");
}

@Test
void checkSetShouldLoopToFalse_whenLoopCountSaysToLoopContinuously() {
MemoryAudio audio = AudioManager.loadMemoryAudio(TestAudioPath);

int expectedLoopCount = MemoryAudio.ContinuousLoop;
boolean expectedShouldLoop = false;

audio.setLoopCount(expectedLoopCount);
audio.setShouldLoop(expectedShouldLoop);

assertEquals(expectedLoopCount, audio.getLoopCount(), "The audio loop count should be set.");
assertEquals(expectedShouldLoop, audio.shouldLoop(), "Setting the loop to \"Audio.ContinuousLoop\" then changing the \"shouldLoop\" variable to false should cause the audio to not need to loop.");
}

@Test
void checkPlayMemoryAudio_shouldTriggerOpenAndStartEvents() throws InterruptedException {
MemoryAudio audio = AudioManager.loadMemoryAudio(TestAudioPath);
Expand Down Expand Up @@ -212,6 +237,16 @@ void checkStopMemoryAudio_shouldTriggerStopAndCloseEvents() throws InterruptedEx
assertEquals(PlaybackState.Playing, audio.getPreviousPlaybackState(), "After stopping the audio, the gotten audio's previous playback state should be \"playing\" because its last state was not paused.");
}

@Test
void checkStopLoopingNow_whilePlayingAudio() throws InterruptedException {
MemoryAudio audio = AudioManager.loadMemoryAudio(TestAudioURL);
audio.play();
TimeUnit.MILLISECONDS.sleep(20);
audio.stopLoopingNow();

assertEquals(MemoryAudio.StopLooping, audio.getLoopCount(), "After being told to stop looping, the audio file's loop count should match the \"stop looping value\".");
}

@Test
void checkGetAudioAfterUnloading() {
MemoryAudio audio = AudioManager.loadMemoryAudio(TestAudioPath);
Expand Down

0 comments on commit d484873

Please sign in to comment.