package com.twu.biblioteca.service;

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

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

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class LibraryServiceTest {

    private LibraryService libraryService;

    @Before
    public void initLibraryService() {

        libraryService = new LibraryService();
    }

    @Test
    public void canInitLibraryTest() {

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

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

    @Test
    public void canShowWelcomeMessageTest() {

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

    @Test
    public void canShowMainMenuForCustomer() {

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

        List<Book> books = new ArrayList<Book>();
        libraryService.showBooksOfLibrary(books);
    }
}

@@ -112,60 +112,8 @@
 er;%0A
-import com.twu.biblioteca.helper.InputReaderHelper;%0A
 impo
@@ -257,51 +257,8 @@
 als;
-%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Apu
@@ -473,23 +473,21 @@
  canInit
-Library
+Users
 Test() %7B
@@ -601,37 +601,24 @@
 Service.init
-Library().get
 Users().get(
@@ -692,29 +692,16 @@
 ice.init
-Library().get
 Users().
@@ -722,16 +722,70 @@
 word());
+%0A    %7D%0A%0A    @Test%0A    public void canInitBooksTest() %7B
 %0A%0A      
@@ -947,37 +947,24 @@
 Service.init
-Library().get
 Books().get(
@@ -1040,21 +1040,8 @@
 init
-Library().get
 Book
@@ -1334,16 +1334,20 @@
 Customer
+Test
 () %7B%0A%0A  
@@ -1848,16 +1848,20 @@
 fLibrary
+Test
 () %7B%0A%0A  
@@ -1963,11 +1963,118 @@
 );%0A    %7D
+%0A%0A//    @Test%0A//    public void canCheckOutBookTest() %7B%0A//%0A//        libraryService.checkOutBook();%0A//    %7D
 %0A%7D%0A

delete useless codes