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 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 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 canShowBooksOfLibraryTest() {

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

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

@@ -764,32 +764,374 @@
 word());%0A    %7D%0A%0A
+    @Test%0A    public void canInitBooksTest() %7B%0A%0A        Book book = new Book(%22Refactoring: Improving the Design of Existing Code%22, %22Martin Fowler%22, %22July 8, 1999%22);%0A        assertEquals(book.getName(), libraryService.initBooks().get(0).getName());%0A        assertEquals(book.getAuthor(), libraryService.initBooks().get(0).getAuthor());%0A    %7D%0A%0A
     @Test%0A    pu
@@ -2241,33 +2241,129 @@
 void can
-Init
+Show
 Books
-Test() %7B
+OfLibraryTest() %7B%0A        String booksOfLibrary = %22----------   BOOK LIST OF BIBLIOTECA   ----------%5Cn%22;
 %0A%0A      
@@ -2364,32 +2364,80 @@
         
+List%3C
 Book
+%3E
  book
+s
  = new 
+ArrayList%3CBook%3E();%0A        books.add(new 
 Book(%22Re
@@ -2511,32 +2511,33 @@
  %22July 8, 1999%22)
+)
 ;%0A        assert
@@ -2534,36 +2534,233 @@
     
-assertEquals(book.getName(),
+books.add(new Book(%22Programming in Scala%22, %22Martin Odersky%22, %22January 4, 2011%22));%0A%0A            for(int i = 0; i %3C libraryService.getAvailableBooks(books).size(); i++) %7B%0A                booksOfLibrary += %22%5B%22 + (i + 1) + %22%5D %22 +
  lib
@@ -2775,39 +2775,73 @@
 ice.
-init
+getAvailable
 Books(
+books
 ).get(
-0
+i
 ).get
-Name()
+BookInfo(
 );%0A
+            %7D%0A    
     
@@ -2857,36 +2857,34 @@
 tEquals(book
-.getAuthor()
+sOfLibrary
 , librarySer
@@ -2892,45 +2892,74 @@
 ice.
-init
+show
 Books
-().get(0).getAuthor(
+OfLibrary(libraryService.getAvailableBooks(books)
 ));%0A    
 %7D%0A%0A%0A
@@ -2958,13 +2958,28 @@
     
+ 
-%7D%0A%0A%0A%0A
+   %7D%0A%0A    %7D%0A%0A%0A%0A%0A%0A//
     
@@ -2976,32 +2976,34 @@
 %0A%0A%0A%0A//    @Test%0A
+//
     public void 
@@ -3024,33 +3024,37 @@
 LibraryTest() %7B%0A
-%0A
+//%0A//
         Library 
@@ -3092,16 +3092,18 @@
 rvice);%0A
+//
 //      
@@ -3148,16 +3148,18 @@
 brary);%0A
+//
     %7D%0A%0A/
@@ -3263,10 +3263,12 @@
 //    %7D%0A
+//
 %7D%0A

complete canShowBooksOfLibraryTest codes but test failed