Example #1
0
 @Test
 public void shouldPromptUserWhenFailedReturnBook() throws IOException {
   when(bufferedReader.readLine()).thenReturn("3", "1");
   when(library.returnBook(anyString())).thenReturn(false, true);
   menu.respondToUserInput(library);
   verify(printStream).println("That is not a valid book to return.");
 }
Example #2
0
 @Test
 public void shouldCallReturnToLibraryWithCorrectBook() throws IOException {
   when(bufferedReader.readLine()).thenReturn("3", "SOME BOOK TITLE!", "0");
   when(library.returnBook(anyString())).thenReturn(true);
   menu.respondToUserInput(library);
   verify(library).returnBook("SOME BOOK TITLE!");
 }
Example #3
0
 @Test
 public void shouldThankUserWhenSuccessfulReturnOfBook() throws IOException {
   when(bufferedReader.readLine()).thenReturn("3", "1");
   when(library.returnBook(anyString())).thenReturn(true);
   menu.respondToUserInput(library);
   verify(printStream).println("Thank you for returning the book.");
 }
Example #4
0
 @Test
 public void shouldPromptUserForBookTitleTheyWantToReturn() throws IOException {
   when(bufferedReader.readLine()).thenReturn("3", "SOME TITLE!", "0");
   when(library.returnBook(anyString())).thenReturn(true);
   menu.respondToUserInput(library);
   verify(printStream).println("Which book would you like to return?");
 }
Example #5
0
 @Test
 public void shouldAllowUserToReenterReturningBookTitle() throws IOException {
   when(bufferedReader.readLine()).thenReturn("3", "1");
   when(library.returnBook(anyString())).thenReturn(false, true);
   menu.respondToUserInput(library);
   verify(printStream).println("That is not a valid book to return.");
   verify(printStream).println("Thank you for returning the book.");
 }
Example #6
0
 @Test
 public void shouldReportErrorMessageWhenUserSelectsABookThatDoesNotExist() throws IOException {
   when(bufferedReader.readLine()).thenReturn("2", "100", "1", "0");
   when(library.checkOutBook(99)).thenReturn(false);
   when(library.checkOutBook(0)).thenReturn(true);
   bookList.add(harryPotter);
   menu.respondToUserInput(library);
   verify(printStream).println(contains("That book is not available."));
 }
Example #7
0
  @Test
  public void shouldShowMenuOptionsWhenMenuIsDisplayed() {
    menu.showOptions();
    verify(printStream).println(contains("[1] Show all books"));
    verify(printStream).println(contains("[2] Check out book"));
    verify(printStream).println(contains("[3] Return Book"));
    verify(printStream).println(contains("[4] Show all movies"));
    verify(printStream).println(contains("[5] Check out movies"));

    verify(printStream).println(contains("[0] Quit"));
  }
Example #8
0
 @Test
 public void shouldBePromptedOnceWhenQuitIsFirstChoice() throws IOException {
   when(bufferedReader.readLine()).thenReturn("0", "1");
   menu.respondToUserInput(library);
   verify(bufferedReader).readLine();
 }
Example #9
0
 @Test
 public void shouldReportErrorMessageWhenInputIsNotInteger() throws IOException {
   when(bufferedReader.readLine()).thenReturn("not an integer", "1", "0");
   menu.respondToUserInput(library);
   verify(printStream).println(contains("Select a valid option!"));
 }
Example #10
0
 @Test
 public void shouldReportErrorWhenInvalidIntegerSelected() throws IOException {
   when(bufferedReader.readLine()).thenReturn("-1", "1", "0");
   menu.respondToUserInput(library);
   verify(printStream).println("Select a valid option!");
 }
Example #11
0
 @Test
 public void shouldListBooksWhenMenuOptionOneIsSelected() throws IOException {
   when(bufferedReader.readLine()).thenReturn("1", "0");
   menu.respondToUserInput(library);
   verify(library).listBooks();
 }
Example #12
0
 @Test
 public void shouldCallCheckOutFromLibraryWithCorrectMovie() throws IOException {
   when(bufferedReader.readLine()).thenReturn("5", "1", "0");
   menu.respondToUserInput(library);
   verify(library).checkOutMovie(0);
 }
Example #13
0
 @Test
 public void shouldListBooksWhenCustomerWantsToCheckOutABook() throws IOException {
   successfullyReturnBook();
   menu.respondToUserInput(library);
   verify(library).listBooks();
 }
Example #14
0
 @Test
 public void shouldTellUserWhenTheyHaveSuccessfullyCheckedOutABook() throws IOException {
   successfullyReturnBook();
   menu.respondToUserInput(library);
   verify(printStream).println(contains("Thank you! Enjoy the book"));
 }
Example #15
0
 @Test
 public void shouldPromptUserToPickBookWhenUserWantsToCheckOutBook() throws IOException {
   successfullyReturnBook();
   menu.respondToUserInput(library);
   verify(printStream).println("Which book would you like to check out?");
 }
Example #16
0
 @Test
 public void shouldListMoviesWhenFourIsChosen() throws IOException {
   when(bufferedReader.readLine()).thenReturn("4", "0");
   menu.respondToUserInput(library);
   verify(library).listMovies();
 }
Example #17
0
 @Test
 public void shouldPromptUserToPickMovieWhenUserWantsToCheckOutMovie() throws IOException {
   when(bufferedReader.readLine()).thenReturn("5", "0");
   menu.respondToUserInput(library);
   verify(printStream).println("Which movie would you like to check out?");
 }
Example #18
0
 @Test
 public void shouldLogInUserWhenCustomerSelectsOption6() throws IOException {
   when(bufferedReader.readLine()).thenReturn("6", "0");
   menu.respondToUserInput(library);
   verify(library).logInUser();
 }
Example #19
0
 @Test
 public void shouldListMoviesWhenCustomerWantsToCheckOutAMovie() throws IOException {
   when(bufferedReader.readLine()).thenReturn("5", "0");
   menu.respondToUserInput(library);
   verify(library).listMovies();
 }
Example #20
0
 @Test
 public void shouldCallCheckOutFromLibraryWithCorrectBook() throws IOException {
   successfullyReturnBook();
   menu.respondToUserInput(library);
   verify(library).checkOutBook(0);
 }