コード例 #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.");
 }
コード例 #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!");
 }
コード例 #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.");
 }
コード例 #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?");
 }
コード例 #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.");
 }
コード例 #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."));
 }
コード例 #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"));
  }
コード例 #8
0
 @Test
 public void shouldBePromptedOnceWhenQuitIsFirstChoice() throws IOException {
   when(bufferedReader.readLine()).thenReturn("0", "1");
   menu.respondToUserInput(library);
   verify(bufferedReader).readLine();
 }
コード例 #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!"));
 }
コード例 #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!");
 }
コード例 #11
0
 @Test
 public void shouldListBooksWhenMenuOptionOneIsSelected() throws IOException {
   when(bufferedReader.readLine()).thenReturn("1", "0");
   menu.respondToUserInput(library);
   verify(library).listBooks();
 }
コード例 #12
0
 @Test
 public void shouldCallCheckOutFromLibraryWithCorrectMovie() throws IOException {
   when(bufferedReader.readLine()).thenReturn("5", "1", "0");
   menu.respondToUserInput(library);
   verify(library).checkOutMovie(0);
 }
コード例 #13
0
 @Test
 public void shouldListBooksWhenCustomerWantsToCheckOutABook() throws IOException {
   successfullyReturnBook();
   menu.respondToUserInput(library);
   verify(library).listBooks();
 }
コード例 #14
0
 @Test
 public void shouldTellUserWhenTheyHaveSuccessfullyCheckedOutABook() throws IOException {
   successfullyReturnBook();
   menu.respondToUserInput(library);
   verify(printStream).println(contains("Thank you! Enjoy the book"));
 }
コード例 #15
0
 @Test
 public void shouldPromptUserToPickBookWhenUserWantsToCheckOutBook() throws IOException {
   successfullyReturnBook();
   menu.respondToUserInput(library);
   verify(printStream).println("Which book would you like to check out?");
 }
コード例 #16
0
 @Test
 public void shouldListMoviesWhenFourIsChosen() throws IOException {
   when(bufferedReader.readLine()).thenReturn("4", "0");
   menu.respondToUserInput(library);
   verify(library).listMovies();
 }
コード例 #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?");
 }
コード例 #18
0
 @Test
 public void shouldLogInUserWhenCustomerSelectsOption6() throws IOException {
   when(bufferedReader.readLine()).thenReturn("6", "0");
   menu.respondToUserInput(library);
   verify(library).logInUser();
 }
コード例 #19
0
 @Test
 public void shouldListMoviesWhenCustomerWantsToCheckOutAMovie() throws IOException {
   when(bufferedReader.readLine()).thenReturn("5", "0");
   menu.respondToUserInput(library);
   verify(library).listMovies();
 }
コード例 #20
0
 @Test
 public void shouldCallCheckOutFromLibraryWithCorrectBook() throws IOException {
   successfullyReturnBook();
   menu.respondToUserInput(library);
   verify(library).checkOutBook(0);
 }