Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. package com.kodilla.testing.library;
  2.  
  3. import org.junit.Assert;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. import static org.mockito.Mockito.mock;
  10. import static org.mockito.Mockito.when;
  11.  
  12. public class UserBooksListTestSuite {
  13.  
  14. //gdy użytkownik nie ma wypożyczonych żadnych książek,
  15. @Test
  16. public void testUserWithNoBooks() {
  17. // Given
  18. LibraryDatabase libraryDatabaseMock = mock(LibraryDatabase.class);
  19. BookLibrary bookLibrary = new BookLibrary(libraryDatabaseMock);
  20. LibraryUser libraryUser = new LibraryUser("Gorge","Sand","23432645342");
  21. List<Book> resultListOfBooks = new ArrayList<Book>();
  22. when(libraryDatabaseMock.listBooksInHandsOf(libraryUser)).thenReturn(resultListOfBooks);
  23. // When
  24. List<Book> theListOfBooks = bookLibrary.listBooksInHandsOf(libraryUser);
  25. // Then
  26. Assert.assertEquals(resultListOfBooks.size(),theListOfBooks.size());
  27. }
  28.  
  29. //gdy ma wypożyczoną jedną książkę,
  30. @Test
  31. public void testUserWithOneBook() {
  32. // Given
  33. LibraryDatabase libraryDatabaseMock = mock(LibraryDatabase.class);
  34. BookLibrary bookLibrary = new BookLibrary(libraryDatabaseMock);
  35. LibraryUser libraryUser = new LibraryUser("Gorge","Sand","23432645342");
  36. List<Book> resultListOfBooks = new ArrayList<Book>();
  37. Book book1 = new Book("Secrets of Alamo", "John Smith", 2008);
  38. resultListOfBooks.add(book1);
  39. when(libraryDatabaseMock.listBooksInHandsOf(libraryUser)).thenReturn(resultListOfBooks);
  40. // When
  41. List<Book> theListOfBooks = bookLibrary.listBooksInHandsOf(libraryUser);
  42. // Then
  43. Assert.assertEquals(resultListOfBooks.size(),theListOfBooks.size());
  44. }
  45.  
  46. //gdy ma wypożyczonych 5 książek.
  47. @Test
  48. public void testUserWithFiveBooks() {
  49. // Given
  50. LibraryDatabase libraryDatabaseMock = mock(LibraryDatabase.class);
  51. BookLibrary bookLibrary = new BookLibrary(libraryDatabaseMock);
  52. LibraryUser libraryUser = new LibraryUser("Gorge","Sand","23432645342");
  53. List<Book> resultListOfBooks = new ArrayList<Book>();
  54. Book book1 = new Book("Secrets of Alamo", "John Smith", 2008);
  55. Book book2 = new Book("Secretaries and Directors", "Dilbert Michigan", 2012);
  56. Book book3 = new Book("Secret life of programmers", "Steve Wolkowitz", 2016);
  57. Book book4 = new Book("Secrets of Java", "Ian Tenewitch", 2010);
  58. Book book5 = new Book("Secrets of Java", "Ian Tenewitch", 2010);
  59. resultListOfBooks.add(book1);
  60. resultListOfBooks.add(book2);
  61. resultListOfBooks.add(book3);
  62. resultListOfBooks.add(book4);
  63. resultListOfBooks.add(book5);
  64. when(libraryDatabaseMock.listBooksInHandsOf(libraryUser)).thenReturn(resultListOfBooks);
  65. // When
  66. List<Book> theListOfBooks = bookLibrary.listBooksInHandsOf(libraryUser);
  67. // Then
  68. Assert.assertEquals(resultListOfBooks.size(),theListOfBooks.size());
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement