package com.twu.biblioteca.service;

import com.twu.biblioteca.entity.Book;
import com.twu.biblioteca.entity.Library;
import com.twu.biblioteca.entity.User;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class LibraryServiceTest {

    private LibraryService libraryService;

    @Before
    public void initLibraryService() {

        libraryService = new LibraryService();
    }

    @Test
    public void canInitUsersTest() {

        User user = new User("zhzhang", "1111", "customer");
        assertEquals(user.getName(), libraryService.initUsers().get(0).getName());
        assertEquals(user.getPassword(), libraryService.initUsers().get(0).getPassword());
    }

    @Test
    public void canGetAvailableBooks() {

        Book book = new Book("Refactoring: Improving the Design of Existing Code", "Martin Fowler", "July 8, 1999");
        List<Book> books = new ArrayList<Book>();
        books.add(book);
        
        assertEquals(1, libraryService.getAvailableBooks(books).size());

        book.setIsBorrowed(true);
        assertEquals(0, libraryService.getAvailableBooks(books).size());
    }

    @Test
    public void canInitBooksTest() {

        Book book = new Book("Refactoring: Improving the Design of Existing Code", "Martin Fowler", "July 8, 1999");
        assertEquals(book.getName(), libraryService.initBooks().get(0).getName());
        assertEquals(book.getAuthor(), libraryService.initBooks().get(0).getAuthor());
    }

    @Test
    public void canShowWelcomeMessageTest() {

        String welcomeMessage = "----------   WELCOME TO BIBLIOTECA   ----------";
        assertEquals(welcomeMessage, libraryService.showWelcomeMessage());
    }

    @Test
    public void canShowMainMenuForCustomerTest() {

        String welcomeMessage = "----------   Main  Menu   ----------\n" +
                                "\n[0] Exit BIBLIOTECA\n" +
                                "[1] List Books of Library\n" +
                                "[2] Check Out Book\n" +
                                "[3] Return Book\n" +
                                "\nPlease Enter Your Choice :";
        assertEquals(welcomeMessage, libraryService.showMainMenuForCustomer());
    }

    @Test
    public void canShowBooksOfLibraryTest() {

        Library library = new Library(libraryService);
//        libraryService.showBooksOfLibrary(library);
    }

//    @Test
//    public void canCheckOutBookTest() {
//
//        libraryService.checkOutBook();
//    }
}

@@ -764,32 +764,697 @@
 word());%0A    %7D%0A%0A
+    @Test%0A    public void canShowWelcomeMessageTest() %7B%0A%0A        String welcomeMessage = %22----------   WELCOME TO BIBLIOTECA   ----------%22;%0A        assertEquals(welcomeMessage, libraryService.showWelcomeMessage());%0A    %7D%0A%0A    @Test%0A    public void canShowMainMenuForCustomerTest() %7B%0A%0A        String welcomeMessage = %22----------   Main  Menu   ----------%5Cn%22 +%0A                %22%5Cn%5B0%5D Exit BIBLIOTECA%5Cn%22 +%0A                %22%5B1%5D List Books of Library%5Cn%22 +%0A                %22%5B2%5D Check Out Book%5Cn%22 +%0A                %22%5B3%5D Return Book%5Cn%22 +%0A                %22%5CnPlease Enter Your Choice :%22;%0A        assertEquals(welcomeMessage, libraryService.showMainMenuForCustomer());%0A    %7D%0A%0A
     @Test%0A    pu
@@ -1484,24 +1484,24 @@
 leBooks() %7B%0A
-
 %0A        Boo
@@ -1685,17 +1685,9 @@
 k);%0A
-        
 %0A
+
     
@@ -2216,751 +2216,8 @@
  %7D%0A%0A
-    @Test%0A    public void canShowWelcomeMessageTest() %7B%0A%0A        String welcomeMessage = %22----------   WELCOME TO BIBLIOTECA   ----------%22;%0A        assertEquals(welcomeMessage, libraryService.showWelcomeMessage());%0A    %7D%0A%0A    @Test%0A    public void canShowMainMenuForCustomerTest() %7B%0A%0A        String welcomeMessage = %22----------   Main  Menu   ----------%5Cn%22 +%0A                                %22%5Cn%5B0%5D Exit BIBLIOTECA%5Cn%22 +%0A                                %22%5B1%5D List Books of Library%5Cn%22 +%0A                                %22%5B2%5D Check Out Book%5Cn%22 +%0A                                %22%5B3%5D Return Book%5Cn%22 +%0A                                %22%5CnPlease Enter Your Choice :%22;%0A        assertEquals(welcomeMessage, libraryService.showMainMenuForCustomer());%0A    %7D
 %0A%0A  

complete canShowMainMenuForCustomerTest codes