import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Scanner;
import org.junit.jupiter.api.Test;

/** Prueba de toda la aplicación: entrada de texto, salida de texto, sin teclado. */
class PlayerAppTest {

    @Test
    void wholeSessionFromText() {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        PrintStream out = new PrintStream(bytes, true, StandardCharsets.UTF_8);
        Player player = new Player(List.of(new Song("A", "x", 10), new Song("B", "y", 10)));
        PlayerApp.build(player, out).run(new Scanner("play\ntick 10\ntick\nstop\n"));
        String nl = System.lineSeparator();
        assertEquals("[PLAYING] suena: A" + nl
                + "[PLAYING] siguiente: B" + nl
                + "error: uso: tick <segundos>" + nl
                + "[STOPPED] detenido: B" + nl, bytes.toString(StandardCharsets.UTF_8));
    }
}
