Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.kodilla.testing.library;
- import org.junit.Assert;
- import org.junit.Before;
- import org.junit.Test;
- import java.util.ArrayList;
- import java.util.List;
- import static org.mockito.Mockito.mock;
- import static org.mockito.Mockito.when;
- public class UserBooksListTestSuite {
- //gdy użytkownik nie ma wypożyczonych żadnych książek,
- @Test
- public void testUserWithNoBooks() {
- // Given
- LibraryDatabase libraryDatabaseMock = mock(LibraryDatabase.class);
- BookLibrary bookLibrary = new BookLibrary(libraryDatabaseMock);
- LibraryUser libraryUser = new LibraryUser("Gorge","Sand","23432645342");
- List<Book> resultListOfBooks = new ArrayList<Book>();
- when(libraryDatabaseMock.listBooksInHandsOf(libraryUser)).thenReturn(resultListOfBooks);
- // When
- List<Book> theListOfBooks = bookLibrary.listBooksInHandsOf(libraryUser);
- // Then
- Assert.assertEquals(resultListOfBooks.size(),theListOfBooks.size());
- }
- //gdy ma wypożyczoną jedną książkę,
- @Test
- public void testUserWithOneBook() {
- // Given
- LibraryDatabase libraryDatabaseMock = mock(LibraryDatabase.class);
- BookLibrary bookLibrary = new BookLibrary(libraryDatabaseMock);
- LibraryUser libraryUser = new LibraryUser("Gorge","Sand","23432645342");
- List<Book> resultListOfBooks = new ArrayList<Book>();
- Book book1 = new Book("Secrets of Alamo", "John Smith", 2008);
- resultListOfBooks.add(book1);
- when(libraryDatabaseMock.listBooksInHandsOf(libraryUser)).thenReturn(resultListOfBooks);
- // When
- List<Book> theListOfBooks = bookLibrary.listBooksInHandsOf(libraryUser);
- // Then
- Assert.assertEquals(resultListOfBooks.size(),theListOfBooks.size());
- }
- //gdy ma wypożyczonych 5 książek.
- @Test
- public void testUserWithFiveBooks() {
- // Given
- LibraryDatabase libraryDatabaseMock = mock(LibraryDatabase.class);
- BookLibrary bookLibrary = new BookLibrary(libraryDatabaseMock);
- LibraryUser libraryUser = new LibraryUser("Gorge","Sand","23432645342");
- List<Book> resultListOfBooks = new ArrayList<Book>();
- Book book1 = new Book("Secrets of Alamo", "John Smith", 2008);
- Book book2 = new Book("Secretaries and Directors", "Dilbert Michigan", 2012);
- Book book3 = new Book("Secret life of programmers", "Steve Wolkowitz", 2016);
- Book book4 = new Book("Secrets of Java", "Ian Tenewitch", 2010);
- Book book5 = new Book("Secrets of Java", "Ian Tenewitch", 2010);
- resultListOfBooks.add(book1);
- resultListOfBooks.add(book2);
- resultListOfBooks.add(book3);
- resultListOfBooks.add(book4);
- resultListOfBooks.add(book5);
- when(libraryDatabaseMock.listBooksInHandsOf(libraryUser)).thenReturn(resultListOfBooks);
- // When
- List<Book> theListOfBooks = bookLibrary.listBooksInHandsOf(libraryUser);
- // Then
- Assert.assertEquals(resultListOfBooks.size(),theListOfBooks.size());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement