@Then("the user <user> has borrowed the book <isbn>")
 public void thenTheUseruserHasBorrowedTheBookisbn(
     @Named("user") String user, @Named("isbn") String isbn) throws SQLException {
   waitForServerResponse();
   String id =
       database.getResult("SELECT id FROM borrowing WHERE borrower_email_address='" + user + "'");
   database.shouldReturnExactlyOne(
       "SELECT * FROM book WHERE current_borrowing_id=" + id + " AND isbn='" + isbn + "'");
 }
 @Then("the library contains a no book with an <attribute> of <value>")
 public void thenTheDatabaseContainsANoEntryForBookisbn(
     @Named("attribute") String attribute, @Named("value") String value) throws SQLException {
   waitForServerResponse();
   database.shouldReturnNothing(
       "SELECT * FROM book WHERE " + getColumnForAttribute(attribute) + " = '" + value + "'");
 }
 @Then("books <isbns> are not borrowed anymore by user <user>")
 public void shouldNotBorrowBooks(@Named("isbns") String isbns, @Named("user") String user)
     throws SQLException {
   waitForServerResponse();
   database.shouldReturnNothing(
       "SELECT * FROM borrowing WHERE borrower_email_address='" + user + "'");
 }
 @Given("a library with only a single unborrowed book with <isbn>")
 public void createSingleBook(@Named("isbn") String isbn) throws SQLException {
   emptyLibrary();
   database.execute(
       "INSERT INTO book(id,title,author,edition,isbn,year_of_publication) VALUES "
           + "(0, 'Title', 'Author', '1', '"
           + isbn
           + "', 2011)");
 }
 @Given("a user <user> has borrowed books <isbns>")
 public void createListOfBorrowedBooks(@Named("user") String user, @Named("isbns") String isbns)
     throws SQLException {
   List<String> isbnList = getListOfItems(isbns);
   for (String isbn : isbnList) {
     database.execute(
         "INSERT INTO book(title,author,edition,isbn,year_of_publication) VALUES "
             + "('Title', 'Author', '1', '"
             + isbn
             + "', 2011)");
     String bookId = database.getResult("SELECT  LAST_INSERT_ID()");
     database.execute(
         "INSERT INTO borrowing(borrow_date, borrower_email_address) VALUES "
             + "(CURDATE(), '"
             + user
             + "')");
     String borrowingId = database.getResult("SELECT  LAST_INSERT_ID()");
     database.execute(
         "UPDATE book SET current_borrowing_id = " + borrowingId + " WHERE id = " + bookId);
   }
 }
 @Then("books <isbns2> are still borrowed by user <user2>")
 public void userShouldBorrowBooks(@Named("isbns") String isbns, @Named("user") String user)
     throws SQLException {
   waitForServerResponse();
   List<String> isbnList = getListOfItems(isbns);
   for (String isbn : isbnList) {
     database.shouldReturnExactlyOne(
         "SELECT count(*) FROM book b LEFT JOIN borrowing g ON b.current_borrowing_id = g.id "
             + "WHERE borrower_email_address = '"
             + user
             + "' and isbn = '"
             + isbn
             + "'");
   }
 }
 @Then("the book <isbn> is not available for borrowing anymore")
 public void shouldNotBeAvailableForBorrowing(@Named("isbn") String isbn) throws SQLException {
   waitForServerResponse();
   database.shouldReturnNothing(
       "SELECT * FROM book WHERE isbn = '" + isbn + "' AND current_borrowing_id is null");
 }
 @Then("the library contains only the book with <isbn>")
 public void shouldContainOnlyOneBook(@Named("isbn") String isbn) throws SQLException {
   waitForServerResponse();
   database.shouldReturnExactlyOne("SELECT * FROM book WHERE isbn = '" + isbn + "'");
 }
 @Given("an empty library")
 public void emptyLibrary() throws SQLException {
   database.emptyTable("book");
   database.emptyTable("borrowing");
 }