|
| 1 | +/** |
| 2 | + * The MIT License |
| 3 | + * Copyright (c) 2014-2016 Ilkka Seppälä |
| 4 | + * |
| 5 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | + * of this software and associated documentation files (the "Software"), to deal |
| 7 | + * in the Software without restriction, including without limitation the rights |
| 8 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | + * copies of the Software, and to permit persons to whom the Software is |
| 10 | + * furnished to do so, subject to the following conditions: |
| 11 | + * |
| 12 | + * The above copyright notice and this permission notice shall be included in |
| 13 | + * all copies or substantial portions of the Software. |
| 14 | + * |
| 15 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | + * THE SOFTWARE. |
| 22 | + */ |
| 23 | + |
| 24 | +package com.iluwatar.event.queue; |
| 25 | +import static org.junit.Assert.*; |
| 26 | + |
| 27 | +import java.io.IOException; |
| 28 | + |
| 29 | +import javax.sound.sampled.UnsupportedAudioFileException; |
| 30 | + |
| 31 | +import org.junit.Test; |
| 32 | + |
| 33 | +/** |
| 34 | + * Testing the Audio service of the Queue |
| 35 | + * @author mkuprivecz |
| 36 | + * |
| 37 | + */ |
| 38 | +public class AudioTest { |
| 39 | + |
| 40 | + /** |
| 41 | + * Test here that the playSound method works correctly |
| 42 | + * @throws UnsupportedAudioFileException when the audio file is not supported |
| 43 | + * @throws IOException when the file is not readable |
| 44 | + * @throws InterruptedException when the test is interrupted externally |
| 45 | + */ |
| 46 | + @Test |
| 47 | + public void testPlaySound() throws UnsupportedAudioFileException, IOException, InterruptedException { |
| 48 | + Audio.playSound(Audio.getAudioStream("./etc/Bass-Drum-1.wav"), -10.0f); |
| 49 | + // test that service is started |
| 50 | + assertTrue(Audio.isServiceRunning()); |
| 51 | + // adding a small pause to be sure that the sound is ended |
| 52 | + Thread.sleep(5000); |
| 53 | + // test that service is finished |
| 54 | + assertFalse(!Audio.isServiceRunning()); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Test here that the Queue |
| 59 | + * @throws UnsupportedAudioFileException when the audio file is not supported |
| 60 | + * @throws IOException when the file is not readable |
| 61 | + * @throws InterruptedException when the test is interrupted externally |
| 62 | + */ |
| 63 | + @Test |
| 64 | + public void testQueue() throws UnsupportedAudioFileException, IOException, InterruptedException { |
| 65 | + Audio.playSound(Audio.getAudioStream("./etc/Bass-Drum-1.wav"), -10.0f); |
| 66 | + Audio.playSound(Audio.getAudioStream("./etc/Bass-Drum-1.wav"), -10.0f); |
| 67 | + Audio.playSound(Audio.getAudioStream("./etc/Bass-Drum-1.wav"), -10.0f); |
| 68 | + assertTrue(Audio.getPendingAudio().length > 0); |
| 69 | + // test that service is started |
| 70 | + assertTrue(Audio.isServiceRunning()); |
| 71 | + // adding a small pause to be sure that the sound is ended |
| 72 | + Thread.sleep(10000); |
| 73 | + // test that service is finished |
| 74 | + assertFalse(!Audio.isServiceRunning()); |
| 75 | + } |
| 76 | + |
| 77 | +} |
0 commit comments