Skip to content

Commit

Permalink
Added some basic tests into WaveTaskTest. Added a new method into Wav…
Browse files Browse the repository at this point in the history
…eTask to return the sounds Array.
  • Loading branch information
BlairCannon97 committed Sep 28, 2023
1 parent c1d2ad6 commit 251b0a6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public void loadSounds() {
resourceService.loadSounds(waveSounds);
}

/**
* Get the sounds to be played when a wave starts or ends
* @return String array of sounds
*/
public String[] getSounds() {
return waveSounds;
}

/**
* Gets the priority of the current task
* @return priority of the WaveTask
Expand Down Expand Up @@ -90,6 +98,7 @@ public void update() {
// Check if level has been completed - no more waves remaining
if (currentWaveIndex == this.level.getNumWaves()) {
logger.info("No waves remaining, level completed");
this.waveEnd.play();
ServiceLocator.getWaveService().setLevelCompleted();

} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,55 @@
package com.csse3200.game.components.tasks.waves;

import com.badlogic.gdx.audio.Sound;
import com.csse3200.game.components.tasks.DroidCombatTask;
import com.csse3200.game.extensions.GameExtension;
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.logging.Level;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;

@ExtendWith(GameExtension.class)
@ExtendWith(MockitoExtension.class)
class WaveTaskTest {

WaveTask waveTask;
ResourceService resourceService;
LevelWaves level;
@BeforeEach
void setUp() {
resourceService = ServiceLocator.getResourceService();
GameTime globalTime = mock(GameTime.class);
level = mock(LevelWaves.class);
ServiceLocator.registerTimeSource(globalTime);
waveTask = new WaveTask();
}

@Test
public void testLoadSounds() {
String[] sounds = waveTask.getSounds();
resourceService.getAsset(sounds[0], Sound.class);
resourceService.getAsset(sounds[1], Sound.class);
}

@Test
public void testGetPriority() {
int priority = waveTask.getPriority();
assertEquals(10, priority);
}

@Test
public void testStartWave() {
WaveTask waveTask = new WaveTask();
waveTask.start();
assertEquals(1, waveTask.getPriority());
}

}

0 comments on commit 251b0a6

Please sign in to comment.