package com.librarian.controller;

import com.librarian.dao.impl.BooksDAOImpl;
import com.librarian.entity.Book;
import com.librarian.util.ScannerLibrayMock;
import org.junit.Before;
import org.junit.Test;

import java.time.LocalDate;
import java.time.Month;

import static org.junit.Assert.*;

public class MenuTest {

    private Menu menu;

    @Before
    public void setUp() {
        menu = new Menu();
    }

    @Test
    public void shouldReturnMenuOptions() {
        String options = menu.getOptions();
        String expected = Menu.LIST_ALL_BOOKS_OPTION + Menu.LIST_ALL_BOOKS_DESCRIPTION + "\n"
                + Menu.CHECKOUT_BOOK_OPTION + Menu.CHECKOUT_BOOK_MESSAGE + "\n"
                + Menu.RETURN_BOOK_OPTION + Menu.RETURN_BOOK_MESSAGE + "\n"
                + Menu.LIST_ALL_MOVIES_OPTION + Menu.LIST_ALL_MOVIES_MESSAGE + "\n"
                + Menu.CHECKOUT_MOVIE_OPTION + Menu.CHECKOUT_MOVIE_MESSAGE + "\n"
                + Menu.CHECKIN_MOVIE_OPTION + Menu.CHECKIN_MOVIE_MESSAGE + "\n"
                + Menu.QUIT_SYSTEM_OPTION + Menu.QUIT_SYSTEM_DESCRIPTION + "\n";
        assertEquals(expected, options);
    }

    @Test
    public void shouldReturnAllBooks() {
        String allbooks = menu.processInput(Menu.LIST_ALL_BOOKS_OPTION);
        assertFalse(allbooks.isEmpty());
    }

    @Test
    public void shouldReturnEmpty() {
        String empty = menu.processInput(Menu.QUIT_SYSTEM_OPTION);
        assertTrue(empty.isEmpty());
    }

    @Test
    public void shouldCheckoutBook() {

        String title = "Funcacao";
        ScannerLibrayMock scannerMock = new ScannerLibrayMock();
        scannerMock.setResponseFromScanner(title);
        menu.setScannerLibrary(scannerMock);

        Book book = new Book(title, "", LocalDate.of(1991, Month.APRIL, 13));
        menu.getDao().insertBook(book);

        String checkoutStatusMessage = menu.processInput(Menu.CHECKOUT_BOOK_OPTION);
        assertEquals(BooksDAOImpl.BOOK_IS_AVAILABLE_MESSAGE, checkoutStatusMessage);
    }

    @Test
    public void shouldThrowInvalidOptionArg() {
        try {
            menu.processInput("100");
            fail("Must send");
        } catch (RuntimeException exception) {
            assertEquals(Menu.INVALID_OPTION_MESSAGE, exception.getMessage());
        }
    }

}

@@ -28,16 +28,52 @@
 oller;%0A%0A
+import com.librarian.dao.MoviesDAO;%0A
 import c
@@ -2326,10 +2326,2057 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void shouldListAllMovies()%7B%0A        String allMovies = menu.processInput(Menu.LIST_ALL_MOVIES_OPTION);%0A        assertNotNull(allMovies);%0A    %7D%0A%0A    @Test%0A    public void shouldCheckoutMovie()%7B%0A        String title = %22Harry Potter%22;%0A        ScannerLibrayMock scannerMock = new ScannerLibrayMock();%0A        scannerMock.setResponseFromScanner(title);%0A        menu.setScannerLibrary(scannerMock);%0A        String checkoutSuccessfulMessage = menu.processInput(Menu.CHECKOUT_MOVIE_OPTION);%0A        assertEquals(MoviesDAO.MOVIE_IS_AVAILABLE_MESSAGE,checkoutSuccessfulMessage);%0A    %7D%0A%0A    @Test%0A    public void shouldNotChkoutMovie()%7B%0A        String title = %22Indiana Jones%22;%0A        ScannerLibrayMock scannerMock = new ScannerLibrayMock();%0A        scannerMock.setResponseFromScanner(title);%0A        menu.setScannerLibrary(scannerMock);%0A        String checkoutunSuccessfulMessage = menu.processInput(Menu.CHECKOUT_MOVIE_OPTION);%0A        assertEquals(MoviesDAO.MOVIE_NOT_AVAILABLE_MESSAGE,checkoutunSuccessfulMessage);%0A    %7D%0A%0A    @Test%0A    public void shouldCheckinMovie()%7B%0A        String title = %22Harry Potter%22;%0A        ScannerLibrayMock scannerMock = new ScannerLibrayMock();%0A        scannerMock.setResponseFromScanner(title);%0A        menu.setScannerLibrary(scannerMock);%0A        String checkoutunSuccessfulMessage = menu.processInput(Menu.CHECKOUT_MOVIE_OPTION);%0A        assertEquals(MoviesDAO.MOVIE_NOT_AVAILABLE_MESSAGE,checkoutunSuccessfulMessage);%0A        String successfulCheckin = menu.processInput(Menu.CHECKIN_MOVIE_OPTION);%0A        assertEquals(MoviesDAO.CHECKIN_SUCCESSFUL_MESSAGE,successfulCheckin);%0A    %7D%0A%0A    @Test%0A    public void shouldNotCheckinMovie()%7B%0A        String title = %22Indiana Jones%22;%0A        ScannerLibrayMock scannerMock = new ScannerLibrayMock();%0A        scannerMock.setResponseFromScanner(title);%0A        menu.setScannerLibrary(scannerMock);%0A        String unsuccessfulCheckin = menu.processInput(Menu.CHECKIN_MOVIE_OPTION);%0A        assertEquals(MoviesDAO.CHECKIN_FAIL_MESSAGE,unsuccessfulCheckin);%0A    %7D%0A%0A
 %7D%0A

add test para movieDAO