Added tests for JTreeLibrary display mode functions.
This commit is contained in:
parent
bbd4274353
commit
6d33c0a6a2
@ -30,10 +30,10 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
|
|||||||
|
|
||||||
private IDatabase database;
|
private IDatabase database;
|
||||||
private IPlaylist playlist;
|
private IPlaylist playlist;
|
||||||
private static final DefaultMutableTreeNode updatingNode = new DefaultMutableTreeNode();
|
static final DefaultMutableTreeNode updatingNode = new DefaultMutableTreeNode();
|
||||||
private final AtomicBoolean libraryUpdating = new AtomicBoolean(false);
|
private final AtomicBoolean libraryUpdating = new AtomicBoolean(false);
|
||||||
private final JComboBox<String> libraryDisplayType = new JComboBox<>();
|
private final JComboBox<String> libraryDisplayType = new JComboBox<>();
|
||||||
private final JTree libraryTree = new JTree();
|
final JTree libraryTree = new JTree();
|
||||||
private final Map<String, Runnable> libraryDisplayVariants = createDisplayVariantMap();
|
private final Map<String, Runnable> libraryDisplayVariants = createDisplayVariantMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
90
src/test/java/musicplayer/library/JTreeLibraryTest.java
Normal file
90
src/test/java/musicplayer/library/JTreeLibraryTest.java
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
package musicplayer.library;
|
||||||
|
|
||||||
|
import musicplayer.db.HibernateDatabase;
|
||||||
|
import musicplayer.db.IDatabase;
|
||||||
|
import musicplayer.model.Album;
|
||||||
|
import musicplayer.model.Artist;
|
||||||
|
import musicplayer.model.Song;
|
||||||
|
import musicplayer.playlist.IPlaylist;
|
||||||
|
import musicplayer.playlist.JTablePlaylist;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class JTreeLibraryTest {
|
||||||
|
|
||||||
|
JTreeLibrary library;
|
||||||
|
Song sampleSong = new Song(ILibrary.autoParse(
|
||||||
|
new File(JTreeLibraryTest.class.getResource("/sample.mp3").getFile()).toPath()).get());
|
||||||
|
IDatabase database;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
database = new HibernateDatabase(true);
|
||||||
|
IPlaylist playlist = new JTablePlaylist();
|
||||||
|
library = new JTreeLibrary(database, playlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowSongsEmpty() throws Exception {
|
||||||
|
library.showSongs();
|
||||||
|
DefaultMutableTreeNode root = (DefaultMutableTreeNode)library.libraryTree.getModel().getRoot();
|
||||||
|
assertEquals(1, root.getChildCount());
|
||||||
|
// If empty, tree will only have a string with an error message in
|
||||||
|
assertEquals(String.class, ((DefaultMutableTreeNode)root.getFirstChild()).getUserObject().getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowSongs() throws Exception {
|
||||||
|
database.addSong(sampleSong);
|
||||||
|
library.showSongs();
|
||||||
|
DefaultMutableTreeNode root = (DefaultMutableTreeNode)library.libraryTree.getModel().getRoot();
|
||||||
|
assertEquals(1, root.getChildCount());
|
||||||
|
assertEquals(sampleSong, ((DefaultMutableTreeNode)root.getFirstChild()).getUserObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowGroupedSongsEmpty() throws Exception {
|
||||||
|
library.showGroupedSongs(Artist.class);
|
||||||
|
DefaultMutableTreeNode root = (DefaultMutableTreeNode)library.libraryTree.getModel().getRoot();
|
||||||
|
assertEquals(1, root.getChildCount());
|
||||||
|
// If empty, tree will only have a string with an error message in
|
||||||
|
assertEquals(String.class, ((DefaultMutableTreeNode)root.getFirstChild()).getUserObject().getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowGroupedSongsArtist() throws Exception {
|
||||||
|
database.addSong(sampleSong);
|
||||||
|
library.showGroupedSongs(Artist.class);
|
||||||
|
DefaultMutableTreeNode root = (DefaultMutableTreeNode)library.libraryTree.getModel().getRoot();
|
||||||
|
assertEquals(1, root.getChildCount());
|
||||||
|
DefaultMutableTreeNode artistNode = (DefaultMutableTreeNode)root.getFirstChild();
|
||||||
|
assertEquals(1, artistNode.getChildCount());
|
||||||
|
assertEquals(sampleSong.getArtist(), artistNode.getUserObject());
|
||||||
|
assertEquals(sampleSong, ((DefaultMutableTreeNode)artistNode.getFirstChild()).getUserObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowGroupedSongsAlbum() throws Exception {
|
||||||
|
database.addSong(sampleSong);
|
||||||
|
library.showGroupedSongs(Album.class);
|
||||||
|
DefaultMutableTreeNode root = (DefaultMutableTreeNode)library.libraryTree.getModel().getRoot();
|
||||||
|
assertEquals(1, root.getChildCount());
|
||||||
|
DefaultMutableTreeNode albumNode = (DefaultMutableTreeNode)root.getFirstChild();
|
||||||
|
assertEquals(1, albumNode.getChildCount());
|
||||||
|
assertEquals(sampleSong.getAlbum(), albumNode.getUserObject());
|
||||||
|
assertEquals(sampleSong, ((DefaultMutableTreeNode)albumNode.getFirstChild()).getUserObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCurrentlyUpdating() throws Exception {
|
||||||
|
String updateText = "Test String";
|
||||||
|
library.currentlyUpdating("Test String");
|
||||||
|
assertEquals(updateText, library.updatingNode.getUserObject());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user