[BAEL-3445] Added Background examples to Cucumber examples (#8319)
This commit is contained in:
+25
-7
@@ -1,7 +1,5 @@
|
||||
package com.baeldung.cucumber.books;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -12,10 +10,12 @@ import io.cucumber.java.en.Then;
|
||||
import io.cucumber.java.en.When;
|
||||
import io.cucumber.datatable.DataTable;
|
||||
|
||||
public class BookStoreRunSteps {
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class BookStoreRunSteps {
|
||||
private BookStore store;
|
||||
private List<Book> foundBooks;
|
||||
private Book foundBook;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -23,19 +23,22 @@ public class BookStoreRunSteps {
|
||||
foundBooks = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Given("^I have the following books in the store$")
|
||||
public void haveBooksInTheStore(DataTable table) {
|
||||
haveBooksInTheStoreByList(table);
|
||||
}
|
||||
|
||||
@Given("^I have the following books in the store by list$")
|
||||
public void haveBooksInTheStoreByList(DataTable table) {
|
||||
|
||||
List<List<String>> rows = table.asLists(String.class);
|
||||
|
||||
|
||||
for (List<String> columns: rows) {
|
||||
store.addBook(new Book(columns.get(0), columns.get(1)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Given("^I have the following books in the store by map$")
|
||||
public void haveBooksInTheStoreByMap(DataTable table) {
|
||||
|
||||
List<Map<String, String>> rows = table.asMaps(String.class, String.class);
|
||||
|
||||
for (Map<String, String> columns: rows) {
|
||||
@@ -52,9 +55,24 @@ public class BookStoreRunSteps {
|
||||
public void searchForBooksByAuthor(String author) {
|
||||
foundBooks = store.booksByAuthor(author);
|
||||
}
|
||||
|
||||
@When("^I search for a book titled (.+)$")
|
||||
public void searchForBookByTitle(String title) {
|
||||
foundBook = store.bookByTitle(title).orElse(null);
|
||||
}
|
||||
|
||||
@Then("^I find (\\d+) books$")
|
||||
public void findBooks(int count) {
|
||||
assertEquals(count, foundBooks.size());
|
||||
}
|
||||
|
||||
@Then("^I find a book$")
|
||||
public void findABook() {
|
||||
assertNotNull(foundBook);
|
||||
}
|
||||
|
||||
@Then("^I find no book$")
|
||||
public void findNoBook() {
|
||||
assertNull(foundBook);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user