Added partial test suite for GStreamerPlayer.
This commit is contained in:
parent
f29be6beee
commit
7993f1481e
@ -40,6 +40,27 @@ public class Song implements Comparable<Song>, IDBType {
|
||||
protected Song() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a song from ExtractedMetadata.
|
||||
* This will always create new model objects (Album, Artist, etc). Use the verbose constructor if you need
|
||||
* proper relationship behaviour between Songs and other model classes.
|
||||
* @param metadata Song metadata.
|
||||
*/
|
||||
public Song(ExtractedMetadata metadata){
|
||||
this(metadata.getTrackNumber(), metadata.getDiscNumber(), metadata.getTitle(), new Artist(metadata.getArtist()),
|
||||
new Album(metadata.getAlbum()), metadata.getGenre(), metadata.getSongFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Representation of a music file.
|
||||
* @param trackNumber Track number.
|
||||
* @param discNumber Disc number.
|
||||
* @param title Song title.
|
||||
* @param artist Song artist.
|
||||
* @param album Song album.
|
||||
* @param genre Song genre.
|
||||
* @param songFile String representation of file path.
|
||||
*/
|
||||
public Song(String trackNumber, String discNumber, String title, Artist artist, Album album, String genre, String songFile) {
|
||||
updateData(trackNumber, discNumber, title, artist, album, genre, songFile);
|
||||
}
|
||||
|
@ -28,15 +28,21 @@ public class GStreamerPlayer implements IPlayer{
|
||||
/**
|
||||
* Manages GStreamer based playback operations.
|
||||
* @param callbackInterface Interface on which UI updates can be called.
|
||||
* @param playlist Playlist containing music to play.
|
||||
*/
|
||||
@Inject
|
||||
public GStreamerPlayer(PlayerCallbackInterface callbackInterface, IPlaylist playlist) {
|
||||
public GStreamerPlayer(PlayerCallbackInterface callbackInterface, IPlaylist playlist){
|
||||
this(callbackInterface, playlist, false);
|
||||
}
|
||||
|
||||
public GStreamerPlayer(PlayerCallbackInterface callbackInterface, IPlaylist playlist, boolean testMode) {
|
||||
this.callbackInterface = callbackInterface;
|
||||
this.playlist = playlist;
|
||||
Gst.init();
|
||||
playBin = new PlayBin2("BusMessages");
|
||||
playBin.setVideoSink(ElementFactory.make("fakesink", "videosink"));
|
||||
|
||||
if(testMode) // Null output for testing
|
||||
playBin.setAudioSink(ElementFactory.make("fakesink", "audiosink"));
|
||||
playBin.connect((PlayBin2.ABOUT_TO_FINISH) playBin2 -> {
|
||||
Thread callbackThing = new Thread(() -> {
|
||||
try {
|
||||
|
83
src/test/java/musicplayer/player/GStreamerPlayerTest.java
Normal file
83
src/test/java/musicplayer/player/GStreamerPlayerTest.java
Normal file
@ -0,0 +1,83 @@
|
||||
package musicplayer.player;
|
||||
|
||||
import musicplayer.model.Song;
|
||||
import musicplayer.playlist.IPlaylist;
|
||||
import musicplayer.playlist.JTablePlaylist;
|
||||
import musicplayer.util.LibraryUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class GStreamerPlayerTest {
|
||||
|
||||
GStreamerPlayer player;
|
||||
IPlaylist playlist;
|
||||
Song sampleSong = new Song(LibraryUtils.autoParse(
|
||||
new File(GStreamerPlayerTest.class.getResource("/sample.mp3").getFile()).toPath()).get());
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
playlist = new JTablePlaylist();
|
||||
player = new GStreamerPlayer(null, playlist, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayEmptyPlaylist() throws Exception {
|
||||
player.play();
|
||||
assertFalse(player.isPlaying());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlay() throws Exception {
|
||||
playlist.addSong(sampleSong);
|
||||
player.play();
|
||||
assertTrue(player.isPlaying());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlaySong() throws Exception {
|
||||
player.playSong(Optional.of(sampleSong));
|
||||
assertTrue(player.isPlaying());
|
||||
assertEquals(sampleSong, player.getCurrentSong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStop() throws Exception {
|
||||
player.playSong(Optional.of(sampleSong));
|
||||
assertTrue(player.isPlaying());
|
||||
player.stop();
|
||||
assertFalse(player.isPlaying());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResume() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPause() throws Exception {
|
||||
player.playSong(Optional.of(sampleSong));
|
||||
assertTrue(player.isPlaying());
|
||||
player.pause();
|
||||
assertFalse(player.isPlaying());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetVolume() throws Exception {
|
||||
assertEquals(100, player.getVolume());
|
||||
int newVolume = 25;
|
||||
player.setVolume(25);
|
||||
assertEquals(newVolume, player.getVolume());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSeek() throws Exception {
|
||||
player.playSong(Optional.of(sampleSong));
|
||||
assertTrue(player.isPlaying());
|
||||
player.seek(100);
|
||||
assertTrue(player.currentSongPosition() >= 100);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user