Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.goxr3plus</groupId>
Expand All @@ -13,7 +13,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.5.1</junit.version>
<junit.version>5.1.1</junit.version>
</properties>

<build>
Expand Down Expand Up @@ -165,6 +165,13 @@
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>


</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ else if (previousStatus == Status.PAUSED) {
* @param seconds Seconds to Skip
*/
//todo not finished needs more validations
public long seekSeconds(int seconds) throws Exception {
public long seekSeconds(int seconds) throws StreamPlayerException {
int durationInSeconds = this.getDurationInSeconds();

//Validate
Expand Down Expand Up @@ -774,7 +774,7 @@ public long seekSeconds(int seconds) throws Exception {
*
* @param seconds Seconds to Skip
*/
public long seekTo(int seconds) throws Exception {
public long seekTo(int seconds) throws StreamPlayerException {
int durationInSeconds = this.getDurationInSeconds();

//Validate
Expand All @@ -800,11 +800,11 @@ public long seekTo(int seconds) throws Exception {
// seek(bytes);
// }

private void validateSeconds(int seconds, int durationInSeconds) throws Exception {
private void validateSeconds(int seconds, int durationInSeconds) {
if (seconds < 0) {
throw new Exception("Trying to skip negative seconds ");
throw new UnsupportedOperationException("Trying to skip negative seconds ");
} else if (seconds >= durationInSeconds) {
throw new Exception("Trying to skip with seconds {" + seconds + "} > maximum {" + durationInSeconds + "}");
throw new UnsupportedOperationException("Trying to skip with seconds {" + seconds + "} > maximum {" + durationInSeconds + "}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public StreamPlayerEventLauncher(Object source, Status playerStatus, int encoded
}

@Override
public String call() throws Exception {
public String call() {
// Notify all the listeners that the state has been updated
if (listeners != null) {
listeners.forEach(listener -> listener
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.goxr3plus.streamplayer.stream;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.io.File;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

class StreamPlayerTest {

@Test
@DisplayName("Demonstration of spying")
void demonstrationOfSpyng() throws StreamPlayerException {

final File audioFile = new File("Logic - Ballin [Bass Boosted].mp3");

// Setup the spy
final StreamPlayer streamPlayer = new StreamPlayer();
final StreamPlayer spy = spy(streamPlayer);

// Execute & verify

// Call open, via the spy
spy.open(audioFile);

// verify that getEncodedStreamPosition is called exactly two times
verify(spy, times(2)).getEncodedStreamPosition();

// Call play, via the spy
spy.play();

// Verify that getEncodedStreamPosition is now called 3 times (the 2 previous times + one more time)
verify(spy, times(3)).getEncodedStreamPosition();

spy.stop();
// Verify that there are in total 4 calls of getEncodedStreamPosition after the player is stopped.
verify(spy, times(4)).getEncodedStreamPosition();

// We can only spy on public methods.
// TODO: Look into initAudioInputStream, and check if we really need to call getEncodedStreamPosition() twice.
}
}