package day13;

import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.*;

public class LibraryTest
{
	private static Library library;
	
	@BeforeClass
	public static void buildUp()
	{
		library = new LibraryImpl("World Union Library");
	}
	
	@Test
	public void testGetLibraryName()
	{
		String expected = "World Union Library";
		String actual = library.getLibraryName();
		assertEquals(expected, actual);
	}
	
	@Test
	public void testGetMaxBooksNumber()
	{
		int expected = 3;
		int actual = library.getMaxBooksPerUser();
		assertEquals(expected, actual);
	}
	
	@Test
	public void testGetId()
	{
		int expected = 2;
		int actual = library.getId("Dois Tois");
		assertEquals(expected, actual);
	}
	
	@Test
	public void testAddAndGetBookAuthor()
	{
		String expected = "Mario Cenas";
		library.addBook("Coiso", "Mario Cenas");
		String actual = library.takeBook("Coiso").getAuthorName();
		assertEquals(expected, actual);
	}

	@Test
	public void testAlreadyTakenBook()
	{
		library.addBook("Coiso", "Mario Cenas");
		library.takeBook("Coiso");
		// Book is already taken at this stage
		Book book = library.takeBook("Coiso");
		assertNull(book);
	}

	@Test
	public void testReturnBook()
	{
		library.addBook("Coiso", "Mario Cenas");
		Book book = library.takeBook("Coiso");
		// Book is already taken at this stage
		library.returnBook(book);
		assertFalse(book.isTaken());
	}
}
