package com.gabrielavara.choiceplayer.util;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import com.gabrielavara.choiceplayer.api.service.Mp3;
import com.gabrielavara.choiceplayer.api.service.PlaylistLoader;
import com.gabrielavara.choiceplayer.api.service.PlaylistTestInitializer;
import com.gabrielavara.choiceplayer.views.TableItem;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.junit.Before;
import org.junit.Test;

public class PlaylistUtilTest extends PlaylistTestInitializer {
    private ObservableList<Mp3> mp3List;
    private PlaylistUtil playlistUtil;
    private ObservableList<TableItem> tableItems = FXCollections.observableArrayList();

    @Override
    @Before
    public void setup() throws IOException {
        super.setup();
        List<Mp3> files = new PlaylistLoader().load(Paths.get("src/test/resources/mp3"));
        mp3List = FXCollections.observableList(files);
        List<TableItem> items = IntStream.range(0, files.size()).mapToObj(index -> new TableItem(index + 1, files.get(index)))
                .collect(Collectors.toList());
        tableItems.addAll(items);
        playlistUtil = new PlaylistUtil(tableItems);
    }

    @Test
    public void testGetNextTrackOnStartup() {
        // when
        Optional<Mp3> nextTrack = playlistUtil.getNextTrack();

        // then
        assertEquals(true, nextTrack.isPresent());
        nextTrack.ifPresent(t -> assertEquals(mp3List.get(0), t));
    }

    @Test
    public void testGetNextTrack() {
        // given
        tableItems.get(0).getMp3().setCurrentlyPlaying(true);

        // when
        Optional<Mp3> nextTrack = playlistUtil.getNextTrack();

        // then
        assertEquals(true, nextTrack.isPresent());
        nextTrack.ifPresent(t -> assertEquals(mp3List.get(1), t));
    }

    @Test
    public void testGetNextTrackOnEndOfPlaylist() {
        // given
        tableItems.get(3).getMp3().setCurrentlyPlaying(true);

        // when
        Optional<Mp3> nextTrack = playlistUtil.getNextTrack();

        // then
        assertEquals(false, nextTrack.isPresent());
    }

    @Test
    public void testGetPreviousTrackOnStartup() {
        // when
        Optional<Mp3> previousTrack = playlistUtil.getPreviousTrack();

        // then
        assertEquals(true, previousTrack.isPresent());
        previousTrack.ifPresent(t -> assertEquals(mp3List.get(0), t));
    }

    @Test
    public void testGetPreviousTrack() {
        // given
        tableItems.get(1).getMp3().setCurrentlyPlaying(true);

        // when
        Optional<Mp3> previousTrack = playlistUtil.getPreviousTrack();

        // then
        assertEquals(true, previousTrack.isPresent());
        previousTrack.ifPresent(t -> assertEquals(mp3List.get(0), t));
    }

    @Test
    public void testGetPreviousTrackOnStartOfPlaylist() {
        // given
        tableItems.get(0).getMp3().setCurrentlyPlaying(true);

        // when
        Optional<Mp3> previousTrack = playlistUtil.getPreviousTrack();

        // then
        assertEquals(false, previousTrack.isPresent());
    }

    @Test
    public void testGetCurrentlyPlayingAlbumArtNotExisting() {
        // given
        tableItems.get(0).getMp3().setCurrentlyPlaying(true);

        // when
        Optional<byte[]> currentlyPlayingAlbumArt = playlistUtil.getCurrentlyPlayingAlbumArt();

        // then
        assertEquals(false, currentlyPlayingAlbumArt.isPresent());
    }

    @Test
    public void testGetCurrentlyPlayingAlbumArtExisting() {
        // given
        tableItems.get(3).getMp3().setCurrentlyPlaying(true);

        // when
        Optional<byte[]> currentlyPlayingAlbumArt = playlistUtil.getCurrentlyPlayingAlbumArt();

        // then
        assertEquals(true, currentlyPlayingAlbumArt.isPresent());
    }
}
@@ -82,16 +82,103 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Aimport
@@ -1630,37 +1630,29 @@
       assert
-Equals(true, 
+True(
 nextTrack.is
@@ -1974,29 +1974,21 @@
   assert
-Equals(true, 
+True(
 nextTrac
@@ -2329,30 +2329,22 @@
   assert
-Equals(f
+F
 alse
-, 
+(
 nextTrac
@@ -2540,37 +2540,29 @@
       assert
-Equals(true, 
+True(
 previousTrac
@@ -2904,29 +2904,21 @@
   assert
-Equals(true, 
+True(
 previous
@@ -3281,30 +3281,22 @@
   assert
-Equals(f
+F
 alse
-, 
+(
 previous
@@ -3622,22 +3622,14 @@
 sert
-Equals(f
+F
 alse
-, 
+(
 curr
@@ -3967,21 +3967,13 @@
 sert
-Equals(true, 
+True(
 curr

Use assertTrue, assertFalse