|
| 1 | +package listfix.io.playlists.wpl; |
| 2 | + |
| 3 | +import listfix.io.IPlaylistOptions; |
| 4 | +import listfix.json.JsonAppOptions; |
| 5 | +import listfix.model.playlists.PlaylistEntry; |
| 6 | +import listfix.util.TestUtil; |
| 7 | +import org.junit.Before; |
| 8 | +import org.junit.Test; |
| 9 | +import org.junit.jupiter.api.DisplayName; |
| 10 | + |
| 11 | +import java.io.File; |
| 12 | +import java.io.IOException; |
| 13 | +import java.nio.charset.StandardCharsets; |
| 14 | +import java.util.List; |
| 15 | + |
| 16 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 17 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 18 | + |
| 19 | +public class WPLReaderTests |
| 20 | +{ |
| 21 | + private IPlaylistOptions playlistOptions; |
| 22 | + |
| 23 | + @Before |
| 24 | + public void initOptions() { |
| 25 | + this.playlistOptions = new JsonAppOptions(); |
| 26 | + } |
| 27 | + |
| 28 | + private WPLReader buildWplReader(String playlist) throws IOException |
| 29 | + { |
| 30 | + File m3uPlaylistFile = TestUtil.createFileFromResource(this, "/playlists/wpl/" + playlist); |
| 31 | + return new WPLReader(this.playlistOptions, m3uPlaylistFile.toPath()); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + @DisplayName("Read WPL Playlist: 2seq.wpl") |
| 36 | + public void read_2seq() throws IOException |
| 37 | + { |
| 38 | + WPLReader wplReader = buildWplReader("2seq.wpl"); |
| 39 | + List<PlaylistEntry> wplPlaylist = wplReader.readPlaylist(); |
| 40 | + assertNotNull(wplPlaylist, "PlaylistFactory should read and construct M3U playlist"); |
| 41 | + assertEquals(4, wplPlaylist.size(), "M3U playlist contains 2 tracks"); |
| 42 | + assertEquals(StandardCharsets.UTF_8, wplReader.getEncoding()); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + @DisplayName("Read WPL Playlist: playlist.wpl") |
| 47 | + public void read_playlist() throws IOException |
| 48 | + { |
| 49 | + WPLReader wplReader = buildWplReader("playlist.wpl"); |
| 50 | + List<PlaylistEntry> wplPlaylist = wplReader.readPlaylist(); |
| 51 | + assertNotNull(wplPlaylist, "PlaylistFactory should read and construct M3U playlist"); |
| 52 | + assertEquals(2, wplPlaylist.size(), "M3U playlist contains 2 tracks"); |
| 53 | + assertEquals(StandardCharsets.UTF_8, wplReader.getEncoding()); |
| 54 | + } |
| 55 | +} |
0 commit comments