Commit 08c7ef46 authored by dbhuller's avatar dbhuller

adding bookstore feature file and step definitions

parent f4df99fc
package hellocucumber;
public class Book {
private String title;
private String author;
public Book(String title, String author) {
this.title = title;
this.author = author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}
package hellocucumber;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class BookStore {
private List<Book> bookList = new ArrayList<>();
public void addBook(Book book) {
bookList.add(book);
}
public List<Book> getBooksByAuthor(String author) {
return bookList.stream().filter(book -> Objects.equals(author, book.getAuthor())).collect(Collectors.toList());
}
}
package hellocucumber;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
public class BookStoreStepDefinitions {
private BookStore bookStore = new BookStore();
private List<Book> bookList;
@Given("I have the following books in the store")
public void i_have_the_following_books_in_the_store(DataTable data) {
// Write code here that turns the phrase above into concrete actions
// For automatic transformation, change DataTable to one of
// E, List<E>, List<List<E>>, List<Map<K,V>>, Map<K,V> or
// Map<K, List<V>>. E,K,V must be a String, Integer, Float,
// Double, Byte, Short, Long, BigInteger or BigDecimal.
//
// For other transformations you can register a DataTableType.
List<Map<String, String>> dataTableRows = data.asMaps(String.class, String.class);
for(Map<String, String> cols : dataTableRows) {
bookStore.addBook(new Book(cols.get("title"), cols.get("author")));
}
}
@When("I search for books by author JK Rowling")
public void i_search_for_books_by_author_jk_rowling() {
// Write code here that turns the phrase above into concrete actions
bookList = bookStore.getBooksByAuthor("JK Rowling");
}
@Then("I find {int} books")
public void i_find_books(int int1) {
// Write code here that turns the phrase above into concrete actions
assertEquals(int1, bookList.size());
}
}
@wip
Feature: Book Store
Scenario: Correct number of books found by author
Given I have the following books in the store
| title | author |
| Harry Potter 1 | JK Rowling |
| Harry Potter 2 | JK Rowling |
| The Lord of the Rings 1 | JRR Tolkien |
| The Lord of the Rings 2 | JRR Tolkien |
| Harry Potter 3 | JK Rowling |
When I search for books by author JK Rowling
Then I find 3 books
\ No newline at end of file
hellocucumber/Calculator.class
hellocucumber/BookStore.class
hellocucumber/BookStoreStepDefinitions.class
hellocucumber/AmazonSearchStepDefinitions.class
hellocucumber/Book.class
hellocucumber/CalculatorStepDefinitions.class
/Users/dbhuller/Documents/CucumberDemo/cucumber-demo/hellocucumber/hellocucumber/src/test/java/hellocucumber/Book.java
/Users/dbhuller/Documents/CucumberDemo/cucumber-demo/hellocucumber/hellocucumber/src/test/java/hellocucumber/Calculator.java
/Users/dbhuller/Documents/CucumberDemo/cucumber-demo/hellocucumber/hellocucumber/src/test/java/hellocucumber/AmazonSearchStepDefinitions.java
/Users/dbhuller/Documents/CucumberDemo/cucumber-demo/hellocucumber/hellocucumber/src/test/java/hellocucumber/StepDefinitions.java
/Users/dbhuller/Documents/CucumberDemo/cucumber-demo/hellocucumber/hellocucumber/src/test/java/hellocucumber/CalculatorStepDefinitions.java
/Users/dbhuller/Documents/CucumberDemo/cucumber-demo/hellocucumber/hellocucumber/src/test/java/hellocucumber/RunCucumberTest.java
/Users/dbhuller/Documents/CucumberDemo/cucumber-demo/hellocucumber/hellocucumber/src/test/java/hellocucumber/BookStoreStepDefinitions.java
/Users/dbhuller/Documents/CucumberDemo/cucumber-demo/hellocucumber/hellocucumber/src/test/java/hellocucumber/BookStore.java
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="8" failures="0" name="hellocucumber.RunCucumberTest" time="0.286" errors="0" skipped="0">
<testsuite tests="9" failures="0" name="hellocucumber.RunCucumberTest" time="0.235" errors="0" skipped="0">
<properties>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="java.vm.version" value="15.0.2+7"/>
......@@ -57,12 +57,13 @@
<property name="socksNonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
<property name="ftp.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
</properties>
<testcase classname="Calculator" name="Add two numbers -2 and 3" time="0.161"/>
<testcase classname="Calculator" name="Add two numbers 10 and 15" time="0.014"/>
<testcase classname="Calculator" name="Add two numbers 99 and -99" time="0.027"/>
<testcase classname="Calculator" name="Add two numbers -1 and -10" time="0.017"/>
<testcase classname="Calculator" name="Subtract two numbers -2 and 3" time="0.015"/>
<testcase classname="Calculator" name="Subtract two numbers 10 and 15" time="0.017"/>
<testcase classname="Calculator" name="Subtract two numbers 99 and -99" time="0.019"/>
<testcase classname="Calculator" name="Subtract two numbers -1 and -10" time="0.016"/>
<testcase classname="Book Store" name="Correct number of books found by author" time="0.161"/>
<testcase classname="Calculator" name="Add two numbers -2 and 3" time="0.014"/>
<testcase classname="Calculator" name="Add two numbers 10 and 15" time="0.011"/>
<testcase classname="Calculator" name="Add two numbers 99 and -99" time="0.008"/>
<testcase classname="Calculator" name="Add two numbers -1 and -10" time="0.01"/>
<testcase classname="Calculator" name="Subtract two numbers -2 and 3" time="0.01"/>
<testcase classname="Calculator" name="Subtract two numbers 10 and 15" time="0.007"/>
<testcase classname="Calculator" name="Subtract two numbers 99 and -99" time="0.007"/>
<testcase classname="Calculator" name="Subtract two numbers -1 and -10" time="0.007"/>
</testsuite>
\ No newline at end of file
-------------------------------------------------------------------------------
Test set: hellocucumber.RunCucumberTest
-------------------------------------------------------------------------------
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.943 sec
Tests run: 9, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.831 sec
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<testsuite errors="0" failures="0" name="io.cucumber.core.plugin.JUnitFormatter" skipped="0" tests="8" time="0.321">
<testcase classname="Calculator" name="Add two numbers -2 and 3" time="0.058">
<testsuite errors="0" failures="0" name="io.cucumber.core.plugin.JUnitFormatter" skipped="0" tests="9" time="0.27">
<testcase classname="Book Store" name="Correct number of books found by author" time="0.051">
<system-out><![CDATA[Given I have the following books in the store...............................passed
When I search for books by author JK Rowling................................passed
Then I find 3 books.........................................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Add two numbers -2 and 3" time="0.007">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I add -2 and 3.........................................................passed
Then The result should be 1.................................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Add two numbers 10 and 15" time="0.003">
<testcase classname="Calculator" name="Add two numbers 10 and 15" time="0.005">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I add 10 and 15........................................................passed
Then The result should be 25................................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Add two numbers 99 and -99" time="0.009">
<testcase classname="Calculator" name="Add two numbers 99 and -99" time="0.002">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I add 99 and -99.......................................................passed
Then The result should be 0.................................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Add two numbers -1 and -10" time="0.006">
<testcase classname="Calculator" name="Add two numbers -1 and -10" time="0.002">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I add -1 and -10.......................................................passed
Then The result should be -11...............................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Subtract two numbers -2 and 3" time="0.006">
<testcase classname="Calculator" name="Subtract two numbers -2 and 3" time="0.004">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I subtract -2 and 3....................................................passed
Then The result should be -5................................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Subtract two numbers 10 and 15" time="0.008">
<testcase classname="Calculator" name="Subtract two numbers 10 and 15" time="0.002">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I subtract 10 and 15...................................................passed
Then The result should be -5................................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Subtract two numbers 99 and -99" time="0.009">
<testcase classname="Calculator" name="Subtract two numbers 99 and -99" time="0.002">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I subtract 99 and -99..................................................passed
Then The result should be 198...............................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Subtract two numbers -1 and -10" time="0.004">
<testcase classname="Calculator" name="Subtract two numbers -1 and -10" time="0.002">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I subtract -1 and -10..................................................passed
Then The result should be 9.................................................passed
......
@wip
Feature: Book Store
Scenario: Correct number of books found by author
Given I have the following books in the store
| title | author |
| Harry Potter 1 | JK Rowling |
| Harry Potter 2 | JK Rowling |
| The Lord of the Rings 1 | JRR Tolkien |
| The Lord of the Rings 2 | JRR Tolkien |
| Harry Potter 3 | JK Rowling |
When I search for books by author JK Rowling
Then I find 3 books
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment