From 251b0a6112f9576ac08fd3ab0cc33bfa86ea9873 Mon Sep 17 00:00:00 2001 From: BlairCannon97 Date: Fri, 29 Sep 2023 09:47:41 +1000 Subject: [PATCH] Added some basic tests into WaveTaskTest. Added a new method into WaveTask to return the sounds Array. --- .../game/components/tasks/waves/WaveTask.java | 9 ++++ .../components/tasks/waves/WaveTaskTest.java | 44 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java b/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java index bacb6aeff..b67f42edf 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java @@ -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 @@ -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 { diff --git a/source/core/src/test/com/csse3200/game/components/tasks/waves/WaveTaskTest.java b/source/core/src/test/com/csse3200/game/components/tasks/waves/WaveTaskTest.java index c76a889ad..4d6b2b566 100644 --- a/source/core/src/test/com/csse3200/game/components/tasks/waves/WaveTaskTest.java +++ b/source/core/src/test/com/csse3200/game/components/tasks/waves/WaveTaskTest.java @@ -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()); + } + }