package com.twu.biblioteca;

import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Scanner;

import static org.junit.Assert.assertEquals;

public class BibliotecaAppTest {

    OutputStream outputStream;

    @Before
    public void setUp() {
        outputStream = new ByteArrayOutputStream();
    }

    @Test
    public void getInput_should_print_hint_and_give_the_input_to_callback() {
        InputHandler inputHandler = new InputHandler("test", input -> "this is a input " + input);

        String output = BibliotecaApp.getInput(new Scanner("test"),
                new PrintStream(outputStream),
                inputHandler);

        assertEquals("\ntest\n", outputStream.toString());
        assertEquals("this is a input test", output);
    }

    @Test
    public void biblioteca_should_output_correctly() {
        BibliotecaApp.biblioteca(new Scanner("0\n1\n2\n"), new PrintStream(outputStream));

        String expectedOutput = String.join("\n",
                "",
                "Welcome to Biblioteca!",
                "",
                "====================",
                "        Menu        ",
                "--------------------",
                "(1) List Books",
                "(2) Quit",
                "--------------------",
                "",
                "Please choose (item number):",
                "",
                "Select a valid option!",
                "",
                "====================",
                "        Menu        ",
                "--------------------",
                "(1) List Books",
                "(2) Quit",
                "--------------------",
                "",
                "Please choose (item number):",
                "",
                "Book1\tAuthor1\t2003",
                "Book2\tAuthor2\t2005",
                "Book3\tAuthor3\t2013",
                "",
                "====================",
                "        Menu        ",
                "--------------------",
                "(1) List Books",
                "(2) Quit",
                "--------------------",
                "",
                "Please choose (item number):"
                ) + "\n";

        assertEquals(expectedOutput, outputStream.toString());
    }
}

@@ -1037,22 +1037,20 @@
 expected
-Output
+Menu
  = Strin
@@ -1086,70 +1086,8 @@
 %22%22,%0A
-                %22Welcome to Biblioteca!%22,%0A                %22%22,%0A
     
@@ -1294,33 +1294,34 @@
 ---------------%22
-,
+);
 %0A               
@@ -1317,65 +1317,47 @@
     
-        %22%22,%0A                %22Please choose (item number):
+String expectedOutput = String.join(%22%5Cn
 %22,%0A 
@@ -1396,29 +1396,29 @@
    %22
-Select a valid option
+Welcome to Biblioteca
 !%22,%0A
@@ -1425,34 +1425,44 @@
                 
-%22%22
+expectedMenu
 ,%0A              
@@ -1468,211 +1468,149 @@
    %22
-====================%22,%0A                %22        Menu        %22,%0A                %22--------------------%22,%0A                %22(1) List Books%22,%0A                %22(2) Quit%22,%0A                %22--------------------%22
+%22,%0A                %22Please choose (item number):%22,%0A                %22%22,%0A                %22Select a valid option!%22,%0A                expectedMenu
 ,%0A  
@@ -1835,232 +1835,20 @@
     
-%22%22,%0A                %22====================%22,%0A                %22        Menu        %22,%0A                %22--------------------%22,%0A                %22(1) List Books%22,%0A                %22(2) Quit%22,%0A                %22--------------------%22
+expectedMenu
 ,%0A  
@@ -1912,24 +1912,16 @@
 mber):%22%0A
-        
         

refactor the test