Commit 7262095d authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch10c] test for sorting by least played. We were right, this is a horrible example for streams.

parent 445dad3f
Loading
Loading
Loading
Loading
+26 −6
Changes for src/test/java/ch10c/JukeboxV3Test.java: 26 added lines, 6 removed lines.
Original line number Diff line number Diff line
package ch10c;

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

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

class JukeboxV3Test {
  @Test
  void shouldOutputAllSongsPlayed() {
    JukeboxData.Songs songs = new JukeboxData.Songs();
    List<Log> log = new Log().getLog();
  private JukeboxData.Songs songs;
  private List<Log> log;

    System.out.println(log);
  @BeforeEach
  void setUp() {
    songs = new JukeboxData.Songs();
    log = new Log().getLog();
  }

    List<Song> allSongs = log.stream().map(log1 -> songs.getSongById(log1.id))
  @Test
  void shouldOutputAllSongsPlayed() {
    List<Song> allSongs = log.stream()
                             .map(logEntry -> songs.getSongById(logEntry.id))
                             .collect(Collectors.toList());

    System.out.println(allSongs);
  }

  @Test
  void shouldOrderByLeastPlayed() {
    // this is impossible!!!!
    // back to square one
//    List<Song> result = log.stream()
//                           .map(logEntry -> songs.getSongById(logEntry.id))
//            .sorted(Comparator.comparingInt())
//                           .collect(Collectors.toList());
//
//    System.out.println(result);
//
  }
}
 No newline at end of file