dupirefr/dupire.francois+pro@gmail.com [BAEL-3445] Cucumber Backgrounds (Moved package) (#8350)
* [BAEL-3445] Added Background examples to Cucumber examples * [BAEL-3445] Copied code to have a package dedicated to the article * [BAEL-3445] Removed code from other package
This commit is contained in:
-5
@@ -56,11 +56,6 @@ public class BookStoreRunSteps {
|
||||
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());
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package com.baeldung.cucumberbackground.books;
|
||||
|
||||
import io.cucumber.datatable.DataTable;
|
||||
import io.cucumber.java.Before;
|
||||
import io.cucumber.java.en.Given;
|
||||
import io.cucumber.java.en.Then;
|
||||
import io.cucumber.java.en.When;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class BookStoreRunSteps {
|
||||
private BookStore store;
|
||||
private List<Book> foundBooks;
|
||||
private Book foundBook;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
store = new BookStore();
|
||||
foundBooks = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Given("^I have the following books in the store$")
|
||||
public void haveBooksInTheStore(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)));
|
||||
}
|
||||
}
|
||||
|
||||
@When("^I search for books by author (.+)$")
|
||||
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);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.cucumberbackground.books;
|
||||
|
||||
import io.cucumber.junit.Cucumber;
|
||||
import io.cucumber.junit.CucumberOptions;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(Cucumber.class)
|
||||
@CucumberOptions(features = "classpath:features/book-store-with-background.feature")
|
||||
public class BookStoreWithBackgroundIntegrationTest {
|
||||
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.cucumberbackground.books;
|
||||
|
||||
import io.cucumber.junit.Cucumber;
|
||||
import io.cucumber.junit.CucumberOptions;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(Cucumber.class)
|
||||
@CucumberOptions(features = "classpath:features/book-store-without-background.feature")
|
||||
public class BookStoreWithoutBackgroundIntegrationTest {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user