Skip to content
Snippets Groups Projects
Commit 18d4f4a5 authored by Gehrung Jonas's avatar Gehrung Jonas
Browse files

Add: Tests (Unit) for SFX that are not random

parent 00349901
No related branches found
No related tags found
5 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development,!62Sound,!60Merge: Sound
package de.hdm_stuttgart.battlearena.Model.Sound;
import de.hdm_stuttgart.battlearena.Controller.GameSceneController;
import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.AppSettings;
import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Persistence;
import de.hdm_stuttgart.battlearena.Model.Entity.IEntity;
import de.hdm_stuttgart.battlearena.Model.Inputs.InputHandler;
import de.hdm_stuttgart.battlearena.Model.Map.ITile;
import de.hdm_stuttgart.battlearena.Model.Map.TileManager;
import javafx.scene.media.AudioClip;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.nio.file.Path;
......@@ -26,6 +23,7 @@ public class SoundEffects {
private SoundFileManager fileManager = new SoundFileManager();
private Persistence persistence = Persistence.getInstance();
private boolean soundEffectPlayedTest = false;
......@@ -57,15 +55,16 @@ public class SoundEffects {
public void playSoundEffectOnce(SFX soundEffect){
String path = soundEffect.getPath();
log.info(path);
String resource = path.substring(18); // Begins at Ressource Folder
Thread sfx = new Thread(()->{
AudioClip audioClip = new AudioClip(getClass().getResource(resource).toExternalForm());
audioClip.setVolume((double) persistence.getSettings().getSfxVolume()/100);
audioClip.play();
});
sfx.setDaemon(true);
sfx.start();
soundEffectPlayedTest = true;
}
......@@ -76,4 +75,8 @@ public class SoundEffects {
public int getVolume(){
return Persistence.getInstance().getSettings().getSfxVolume();
}
public boolean isSoundEffectPlayedTest() {
return soundEffectPlayedTest;
}
}
import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.DatabaseException;
import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Persistence;
import de.hdm_stuttgart.battlearena.Model.Sound.SFX;
import de.hdm_stuttgart.battlearena.Model.Sound.SoundEffects;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class SoundEffectsTest {
private static final Logger log = LogManager.getLogger(SoundEffectsTest.class);
private SoundEffects soundEffects;
private Persistence persistence;
@BeforeEach
void SetUp(){
soundEffects = new SoundEffects();
persistence = Persistence.getInstance();
try {
persistence.loadSettings();
} catch (DatabaseException e) {
throw new RuntimeException(e);
}
}
@Test
void playSoundEffectOnceTest(){
soundEffects.playSoundEffectOnce(SFX.BOMB);
Assertions.assertTrue(soundEffects.isSoundEffectPlayedTest());
}
@Test
void playSoundEffectOnceVolumeTest(){
soundEffects.playSoundEffectOnce(SFX.SWORD_HIT);
soundEffects.setSfxVolume(50);
Assertions.assertAll(()->{
Assertions.assertTrue(soundEffects.isSoundEffectPlayedTest());
Assertions.assertEquals(50, persistence.getSettings().getSfxVolume());
});
}
@Test
void playSoundEffectTest(){
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment