org.apache.maven.plugins
maven-compiler-plugin
@@ -76,13 +63,6 @@
-
-
- jitpack.io
- https://jitpack.io
-
-
-
@@ -130,9 +110,9 @@
- com.github.goxr3plus
+ net.jthink
jaudiotagger
- 2.2.7
+ 3.0.0
@@ -141,39 +121,6 @@
2.7
-
-
- org.junit.jupiter
- junit-jupiter-engine
- ${junit.version}
- test
-
-
-
-
- org.junit.jupiter
- junit-jupiter-api
- ${junit.version}
- test
-
-
-
-
- org.junit.jupiter
- junit-jupiter-params
- ${junit.version}
- test
-
-
-
-
- org.mockito
- mockito-junit-jupiter
- 3.0.0
- test
-
-
-
diff --git a/src/test/java/com/goxr3plus/streamplayer/stream/SourceDataLineTest.java b/src/test/java/com/goxr3plus/streamplayer/stream/SourceDataLineTest.java
deleted file mode 100644
index e7ec583..0000000
--- a/src/test/java/com/goxr3plus/streamplayer/stream/SourceDataLineTest.java
+++ /dev/null
@@ -1,192 +0,0 @@
-package com.goxr3plus.streamplayer.stream;
-
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.BDDMockito;
-
-import javax.sound.sampled.SourceDataLine;
-import java.io.File;
-import java.util.logging.Logger;
-
-import static java.lang.Math.log10;
-import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.ArgumentMatchers.booleanThat;
-import static org.mockito.Mockito.mock;
-
-public class SourceDataLineTest {
-
- StreamPlayer player;
- private File audioFile;
-
- @BeforeEach
- void setup() {
- final Logger logger = mock(Logger.class);
- player = new StreamPlayer(logger);
- audioFile = new File("Logic - Ballin [Bass Boosted].mp3");
- }
-
- @AfterEach
- void tearDown() {
- player.stop();
- }
-
- @Test
- void gain() throws StreamPlayerException, InterruptedException {
- // Setup
- final double gain1 = 0.83;
- final double gain2 = 0.2;
- final double delta = 0.05;
- final boolean listen = false;
-
- // Exercise
- final float initialGain = player.getGainValue();
- player.open(audioFile);
- player.seekTo(30);
- player.play();
- player.setGain(gain1);
- final float actualGain1First = player.getGainValue();
- if (listen) Thread.sleep(2000);
- final float actualGain1 = player.getGainValue();
-
- player.setGain(gain2);
- if (listen) Thread.sleep(2000);
- final float actualGain2 = player.getGainValue();
-
- player.setGain(gain1);
- if (listen) Thread.sleep(2000);
-
- player.stop();
-
- // Verify
- assertEquals(0, initialGain);
- assertEquals(actualGain1First, actualGain1);
- assertEquals(20*log10(gain1), actualGain1, delta); // TODO: Investigate probable bug.
- // fail("Test not done");
- }
-
- /**
- * Plays music if "listen" is true.
- * Varies the gain, and checks that it can be read back.
- * If listen is true, it plays for 2 seconds per gain level.
- *
- * @throws StreamPlayerException
- * @throws InterruptedException
- */
- @Test
- void logScaleGain() throws StreamPlayerException, InterruptedException {
- // Setup
- final boolean listen = false;
-
- // Exercise
-
- player.open(audioFile);
- player.seekTo(30);
- player.play();
-
- assertGainCanBeSetTo(-10, listen);
- assertGainCanBeSetTo(-75, listen);
- assertGainCanBeSetTo(0, listen);
- assertGainCanBeSetTo(6, listen);
-
- player.stop();
- }
-
- private void assertGainCanBeSetTo(double gain, boolean listen) throws InterruptedException {
- final float atGain = playAtGain(listen, gain);
- assertEquals(gain, atGain, 0.01);
- }
-
- private float playAtGain(boolean listen, double gain) throws InterruptedException {
- player.setLogScaleGain(gain);
- if (listen) {
- Thread.sleep(2000);
- }
- return player.getGainValue();
- }
-
- @Test
- void balance() throws StreamPlayerException {
- // Setup
- final float wantedBalance = 0.5f;
-
- //Exercise
- player.open(audioFile);
- player.play(); // Necessary to be able to set the balance
-
- final float initialBalance = player.getBalance();
- player.setBalance(wantedBalance);
- player.stop(); // Probably not needed, but cleanup is good.
- final float actualBalance = player.getBalance(); // Can be made before or after stop()
-
- // Verify
- assertEquals(0, initialBalance);
- assertEquals(wantedBalance, actualBalance);
- }
-
- @Test
- void pan() throws StreamPlayerException {
- double delta = 1e-6;
- final float initialPan = player.getPan();
- assertEquals(0, initialPan);
-
- player.open(audioFile);
- player.play();
-
- double pan = -0.9;
- player.setPan(pan);
- assertEquals(pan, player.getPan(), delta);
-
- double outsideRange = 1.1;
- player.setPan(outsideRange);
- assertEquals(pan, player.getPan(), delta);
- }
-
- @Test
- void mute() throws StreamPlayerException {
- assertFalse(player.getMute());
- player.setMute(true);
- assertFalse(player.getMute());
- player.open(audioFile);
- player.setMute(true);
- assertFalse(player.getMute());
-
- player.play();
- player.setMute(true);
- assertTrue(player.getMute()); // setMute works only after play() has been called.
-
-
- player.setMute(false);
- assertFalse(player.getMute());
- }
-
- @Test
- void sourceDataLine() throws StreamPlayerException {
- assertNull(player.getSourceDataLine());
-
- player.open(audioFile);
- assertNotNull(player.getSourceDataLine());
-
- player.play();
-
- assertNotNull(player.getSourceDataLine());
- }
-
- @Test
- void playAndPause() throws StreamPlayerException, InterruptedException {
- boolean listen = true;
- player.open(audioFile);
- player.play();
- player.seekTo(30);
- if (listen) Thread.sleep(200);
-
- player.pause();
- if (listen) Thread.sleep(100);
-
- player.resume(); // TODO: Examine what happens if play() is called instead.
- if (listen) Thread.sleep(200);
- //player.stop();
-
- // TODO: asserts and listen=false
- }
-}
diff --git a/src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerEventTest.java b/src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerEventTest.java
deleted file mode 100644
index d8ed334..0000000
--- a/src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerEventTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.goxr3plus.streamplayer.stream;
-
-import com.goxr3plus.streamplayer.enums.Status;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.configuration.IMockitoConfiguration;
-
-import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.Mockito.mock;
-
-class StreamPlayerEventTest {
-
- private StreamPlayer source;
- private Object description;
- private Status status;
- private int encodededStreamPosition;
- private StreamPlayerEvent event;
-
- @BeforeEach
- void setUp() {
- description = new Object();
- source = mock(StreamPlayer.class);
- status = Status.RESUMED;
- encodededStreamPosition = 12345;
- event = new StreamPlayerEvent(source, status, encodededStreamPosition, description);
- }
-
- @Test
- void itReturnsTheStatus() {
- assertEquals(status, event.getPlayerStatus());
- }
-
- @Test
- void itReturnsTheEncodedStreamPosition() {
- assertEquals(encodededStreamPosition, event.getEncodedStreamPosition());
- }
-
- @Test
- void itReturnsTheSource() {
- assertSame(source, event.getSource());
- }
-
- @Test
- void itReturnsTheDescription() {
- assertSame(description, event.getDescription());
- }
-
- @Test
- void itReturnsAString() {
- final String actual = event.toString();
- final String expected = "Source :="
- + source.toString()
- + " , Player Status := RESUMED , EncodedStreamPosition :=12345 , Description :="
- + description.toString();
- assertEquals(expected, actual);
- }
-
-
-}
\ No newline at end of file
diff --git a/src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerFutureImprovementTest.java b/src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerFutureImprovementTest.java
deleted file mode 100644
index f32c25f..0000000
--- a/src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerFutureImprovementTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package com.goxr3plus.streamplayer.stream;
-
-import com.goxr3plus.streamplayer.enums.Status;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.Test;
-
-import javax.sound.sampled.AudioFileFormat;
-import javax.sound.sampled.AudioSystem;
-import javax.sound.sampled.SourceDataLine;
-import javax.sound.sampled.UnsupportedAudioFileException;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.logging.Logger;
-
-import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.Mockito.mock;
-
-/**
- * Tests of all or most of the public methods of StreamPlayer.
- * These unit tests are written primarily as documentation of the behavior and as example use case,
- * not as a part of test driven development.
- */
-public class StreamPlayerFutureImprovementTest {
- StreamPlayer player;
- private File audioFile;
-
- @BeforeEach
- void setup() {
- final Logger logger = mock(Logger.class);
- player = new StreamPlayer(logger);
- audioFile = new File("Logic - Ballin [Bass Boosted].mp3");
- }
-
- /**
- * This test fails if it's permitted to add a null to the StreamPlayer listener list.
- */
- @Test
- @Disabled("This test fails with the current implementation. The test exists to illustrate a future improvement.")
- void addStreamPlayerListener_dontAcceptNull() {
- // We can't allow nulls in the list of listeners, because they will cause NullPointerExceptions.
- // One way to handle it is to require that an exception is thrown immediately when we
- // try to add the null.
- assertThrows(NullPointerException.class, () -> player.addStreamPlayerListener(null));
-
- // An alternative way would be to use some kind of null annotation, to disallow
- // nulls being passed at compile time.
- }
-
-
- @Test
- @DisplayName("When play() is called without first calling open(), an exception is thrown")
- @Disabled("This test fails with the current implementation. The test exists to illustrate a future improvement.")
- void playingUnopenedSourceThrowsException() {
-
- assertThrows(Exception.class, () -> player.play());
- }
-
- @Test
- @Disabled("This test fails with the current implementation. The test exists to illustrate a future improvement.")
- void seekBytes() throws StreamPlayerException {
- player.open(audioFile);
- player.play();
- int positionByte1 = player.getPositionByte();
-
- player.seekBytes(100);
- int positionByte2 = player.getPositionByte();
-
- assertTrue( positionByte2 > positionByte1);
-
- // TODO: It seems that getPositionByte doesn't work.
- // It isn't called from within this project, except for in this test.
- // It is however called by XR3Player. If XR3Player needs this method, it must be tested
- // within this project. The method relies on a map, which doesn't seem to be updated by play()
- }
-
-}
diff --git a/src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerMethodsTest.java b/src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerMethodsTest.java
deleted file mode 100644
index 1cf1f47..0000000
--- a/src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerMethodsTest.java
+++ /dev/null
@@ -1,660 +0,0 @@
-package com.goxr3plus.streamplayer.stream;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.anyLong;
-import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.atMost;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import javax.sound.sampled.*;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Test;
-import org.mockito.ArgumentCaptor;
-
-import com.goxr3plus.streamplayer.enums.Status;
-
-/**
- * Tests of all or most of the public methods of StreamPlayer.
- * These unit tests are written primarily as documentation of the behavior and as example use case,
- * not as a part of test driven development.
- */
-public class StreamPlayerMethodsTest {
- StreamPlayer player;
- private File audioFile;
-
- @BeforeEach
- void setup() {
- final Logger logger = mock(Logger.class);
- player = new StreamPlayer(logger);
- audioFile = new File("Logic - Ballin [Bass Boosted].mp3");
- }
-
- @Test
- void duration() throws StreamPlayerException {
- audioFile = new File("Logic - Ballin [Bass Boosted].mp3");
- player.open(audioFile);
- assertEquals(245, player.getDurationInSeconds());
- assertEquals(245000, player.getDurationInMilliseconds());
- assertNotNull(player.getDuration());
- assertEquals(245, player.getDuration().getSeconds());
- assertEquals(player.getDuration().toMillis(), player.getDurationInMilliseconds());
-
- audioFile = new File("kick.wav");
- player.open(audioFile);
- assertEquals(0, player.getDurationInSeconds());
- assertEquals(111, player.getDurationInMilliseconds());
-
- audioFile = new File("kick.mp3");
- player.open(audioFile);
- assertEquals(0, player.getDurationInSeconds());
- // Note: the result of calculating a .mp3's duration is different than that of a .wav file
- assertEquals(156, player.getDurationInMilliseconds());
- }
-
- @Test
- void balance() throws StreamPlayerException {
- // Setup
- final float wantedBalance = 0.5f;
-
- //Exercise
- player.open(audioFile);
- player.play(); // Necessary to be able to set the balance
-
- final float initialBalance = player.getBalance();
- player.setBalance(wantedBalance);
- player.stop(); // Probably not needed, but cleanup is good.
- final float actualBalance = player.getBalance(); // Can be made before or after stop()
-
- // Verify
- assertEquals(0, initialBalance);
- assertEquals(wantedBalance, actualBalance);
- }
-
- @Test
- void status() throws StreamPlayerException {
- // Setup
- final File audioFile = new File("Logic - Ballin [Bass Boosted].mp3");
-
- // Exercise
- final Status initialStatus = player.getStatus();
-
- player.open(audioFile);
- final Status statusAfterOpen = player.getStatus();
-
- player.stop();
- final Status statusAfterFirstStop = player.getStatus();
-
- player.play();
- final Status statusAfterPlay = player.getStatus();
-
- player.pause();
- final Status statusAfterPause = player.getStatus();
-
- player.seekTo(40);
- final Status statusAfterSeeking = player.getStatus();
-
- player.stop();
- final Status statusAfterSecondStop = player.getStatus();
-
- // Verify
- assertEquals(Status.NOT_SPECIFIED, initialStatus);
- assertEquals(Status.OPENED, statusAfterOpen);
- assertEquals(Status.STOPPED, statusAfterFirstStop);
- assertEquals(Status.PLAYING, statusAfterPlay);
- assertEquals(Status.PAUSED, statusAfterPause);
- assertEquals(Status.PAUSED, statusAfterSeeking); // Still paused (or paused again)
- assertEquals(Status.STOPPED, statusAfterSecondStop);
- }
-
- @Test
- void gain() throws StreamPlayerException, InterruptedException {
- // Setup
- final double gain1_dB = 0.5;
- final double gain2 = 0.2;
- final double delta = 0.05;
-
- // By setting listen to true, you an listen to the musig being played,
- // and hear that the gain changes.
- // This is totally against the rules for unit testing, but can be useful.
- final boolean listen = false;
-
- // Exercise
- final float initialGain = player.getGainValue();
- player.open(audioFile);
- player.seekTo(30);
- player.play();
- player.setGain(gain1_dB);
- final float actualGain0 = player.getGainValue();
- if (listen) Thread.sleep(2000);
- final float actualGain1 = player.getGainValue();
-
- player.setGain(gain2);
- if (listen) Thread.sleep(2000);
- final float actualGain2 = player.getGainValue();
-
- player.setGain(gain1_dB);
- if (listen) Thread.sleep(2000);
-
- player.stop();
-
- // Verify
- assertEquals(0, initialGain);
- assertEquals(actualGain0, actualGain1);
- assertEquals(20.0 * Math.log10(gain1_dB), actualGain1, delta);
-
- // TODO: Consider changing the API. setGain() and getGainValue() have different scales.
- // setGain(linear scale),
- // whereas getGainValue() returns a logarithmic dB scale value. This is inconsistent.
- }
-
- /**
- * Plays music if "listen" is true.
- * Varies the gain, and checks that it can be read back.
- * If listen is true, it plays for 2 seconds per gain level.
- *
- * @throws StreamPlayerException
- * @throws InterruptedException
- */
- @Test
- void logScaleGain() throws StreamPlayerException, InterruptedException {
- // Setup
- final boolean listen = false; // Set to true to listen to the test.
-
- // Exercise
-
- player.open(audioFile);
- player.seekTo(30);
- player.play();
-
- assertGainCanBeSetTo(-10, listen);
- assertGainCanBeSetTo(-75, listen);
- assertGainCanBeSetTo(0, listen);
- assertGainCanBeSetTo(6, listen);
-
- player.stop();
- }
-
- private void assertGainCanBeSetTo(double gain, boolean listen) throws InterruptedException {
- final float atGain = playAtGain(listen, gain);
- assertEquals(gain, atGain, 0.01);
- }
-
- private float playAtGain(boolean listen, double gain) throws InterruptedException {
- player.setLogScaleGain(gain);
- if (listen) {
- Thread.sleep(2000);
- }
- return player.getGainValue();
- }
-
- /**
- * Test that the maximum gain is greater than the minimum gain. That is about all we can expect.
- * The actual values depend on the available {@link SourceDataLine}.
- * We don't know anything about its scale beforehand.
- *
- * The player must be started before maximum and minimum gains can be queried.
- *
- * // TODO: Is it really acceptable that we cannot check gain before the player is started?
- *
- * @throws StreamPlayerException
- */
- @Test
- void maximumGain() throws StreamPlayerException {
-
- player.open(audioFile);
- player.play();
- final float maximumGain = player.getMaximumGain();
- final float minimumGain = player.getMinimumGain();
- player.stop();
-
- assertTrue(minimumGain < maximumGain,
- String.format("Maximum gain (%.2f) should be greater than minimum gain (%.2f).",
- maximumGain, minimumGain)
- );
- }
-
- @Test
- void totalBytes() throws StreamPlayerException, InterruptedException {
- int expectedLengthOfExampleAudioFile = 5877062;
-
-
- assertEquals(-1, player.getTotalBytes());
-
- player.open(audioFile);
- assertEquals(expectedLengthOfExampleAudioFile, player.getTotalBytes());
-
- player.play();
- assertEquals(expectedLengthOfExampleAudioFile, player.getTotalBytes());
- }
-
- @Test
- void stopped() {
-
- assertFalse(player.isStopped());
-
- player.stop();
- assertTrue(player.isStopped());
- }
-
- @Test
- void sourceDataLine() throws StreamPlayerException {
- assertNull(player.getSourceDataLine());
-
- player.open(audioFile);
- assertNotNull(player.getSourceDataLine());
-
- player.play();
-
- assertNotNull(player.getSourceDataLine());
- }
-
- @Test
- void playing() throws StreamPlayerException {
-
- assertFalse(player.isPlaying());
-
- player.open(audioFile);
- assertFalse(player.isPlaying());
-
- player.play();
- assertTrue(player.isPlaying());
-
- player.pause();
- assertFalse(player.isPlaying());
- }
-
- @Test
- void pausedOrPlaying() throws StreamPlayerException {
-
- assertFalse(player.isPausedOrPlaying());
-
- player.open(audioFile);
- assertFalse(player.isPausedOrPlaying());
-
- player.play();
- assertTrue(player.isPausedOrPlaying());
-
- player.pause();
- assertTrue(player.isPausedOrPlaying());
-
- player.stop();
- assertFalse(player.isPausedOrPlaying());
- }
-
- @Test
- void paused() throws StreamPlayerException {
- assertFalse(player.isPaused());
-
- player.open(audioFile);
- assertFalse(player.isPaused());
-
- player.play();
- assertFalse(player.isPaused());
-
- player.pause();
- assertTrue(player.isPaused());
- }
-
- @Test
- void addStreamPlayerListener() throws StreamPlayerException, InterruptedException {
- // Setup
- final StreamPlayerListener listener = mock(StreamPlayerListener.class);
-
- ArgumentCaptor