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
......@@ -3,7 +3,123 @@
"line": 2,
"elements": [
{
"start_timestamp": "2021-04-06T20:20:59.332Z",
"start_timestamp": "2021-04-06T21:12:23.486Z",
"line": 4,
"name": "Correct number of books found by author",
"description": "",
"id": "book-store;correct-number-of-books-found-by-author",
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"result": {
"duration": 4877000,
"status": "passed"
},
"line": 5,
"name": "I have the following books in the store",
"match": {
"location": "hellocucumber.BookStoreStepDefinitions.i_have_the_following_books_in_the_store(io.cucumber.datatable.DataTable)"
},
"rows": [
{
"cells": [
"title",
"author"
]
},
{
"cells": [
"Harry Potter 1",
"JK Rowling"
]
},
{
"cells": [
"Harry Potter 2",
"JK Rowling"
]
},
{
"cells": [
"The Lord of the Rings 1",
"JRR Tolkien"
]
},
{
"cells": [
"The Lord of the Rings 2",
"JRR Tolkien"
]
},
{
"cells": [
"Harry Potter 3",
"JK Rowling"
]
}
],
"keyword": "Given "
},
{
"result": {
"duration": 413000,
"status": "passed"
},
"line": 12,
"name": "I search for books by author JK Rowling",
"match": {
"location": "hellocucumber.BookStoreStepDefinitions.i_search_for_books_by_author_jk_rowling()"
},
"keyword": "When "
},
{
"result": {
"duration": 1673000,
"status": "passed"
},
"line": 13,
"name": "I find 3 books",
"match": {
"arguments": [
{
"val": "3",
"offset": 7
}
],
"location": "hellocucumber.BookStoreStepDefinitions.i_find_books(int)"
},
"keyword": "Then "
}
],
"tags": [
{
"name": "@wip"
}
]
}
],
"name": "Book Store",
"description": "",
"id": "book-store",
"keyword": "Feature",
"uri": "classpath:hellocucumber/book_store.feature",
"tags": [
{
"name": "@wip",
"type": "Tag",
"location": {
"line": 1,
"column": 1
}
}
]
},
{
"line": 2,
"elements": [
{
"start_timestamp": "2021-04-06T21:12:23.548Z",
"line": 12,
"name": "Add two numbers -2 and 3",
"description": "",
......@@ -13,7 +129,7 @@
"steps": [
{
"result": {
"duration": 2179000,
"duration": 199000,
"status": "passed"
},
"line": 6,
......@@ -25,7 +141,7 @@
},
{
"result": {
"duration": 545000,
"duration": 207000,
"status": "passed"
},
"line": 7,
......@@ -47,7 +163,7 @@
},
{
"result": {
"duration": 1097000,
"duration": 150000,
"status": "passed"
},
"line": 8,
......@@ -71,7 +187,7 @@
]
},
{
"start_timestamp": "2021-04-06T20:20:59.404Z",
"start_timestamp": "2021-04-06T21:12:23.561Z",
"line": 13,
"name": "Add two numbers 10 and 15",
"description": "",
......@@ -81,7 +197,7 @@
"steps": [
{
"result": {
"duration": 345000,
"duration": 334000,
"status": "passed"
},
"line": 6,
......@@ -93,7 +209,7 @@
},
{
"result": {
"duration": 325000,
"duration": 942000,
"status": "passed"
},
"line": 7,
......@@ -115,7 +231,7 @@
},
{
"result": {
"duration": 246000,
"duration": 161000,
"status": "passed"
},
"line": 8,
......@@ -139,7 +255,7 @@
]
},
{
"start_timestamp": "2021-04-06T20:20:59.424Z",
"start_timestamp": "2021-04-06T21:12:23.572Z",
"line": 14,
"name": "Add two numbers 99 and -99",
"description": "",
......@@ -149,7 +265,7 @@
"steps": [
{
"result": {
"duration": 192000,
"duration": 135000,
"status": "passed"
},
"line": 6,
......@@ -161,7 +277,7 @@
},
{
"result": {
"duration": 1015000,
"duration": 181000,
"status": "passed"
},
"line": 7,
......@@ -183,7 +299,7 @@
},
{
"result": {
"duration": 296000,
"duration": 160000,
"status": "passed"
},
"line": 8,
......@@ -207,7 +323,7 @@
]
},
{
"start_timestamp": "2021-04-06T20:20:59.445Z",
"start_timestamp": "2021-04-06T21:12:23.582Z",
"line": 15,
"name": "Add two numbers -1 and -10",
"description": "",
......@@ -217,7 +333,7 @@
"steps": [
{
"result": {
"duration": 387000,
"duration": 122000,
"status": "passed"
},
"line": 6,
......@@ -229,7 +345,7 @@
},
{
"result": {
"duration": 814000,
"duration": 188000,
"status": "passed"
},
"line": 7,
......@@ -251,7 +367,7 @@
},
{
"result": {
"duration": 442000,
"duration": 155000,
"status": "passed"
},
"line": 8,
......@@ -275,7 +391,7 @@
]
},
{
"start_timestamp": "2021-04-06T20:20:59.462Z",
"start_timestamp": "2021-04-06T21:12:23.590Z",
"line": 24,
"name": "Subtract two numbers -2 and 3",
"description": "",
......@@ -285,7 +401,7 @@
"steps": [
{
"result": {
"duration": 898000,
"duration": 538000,
"status": "passed"
},
"line": 18,
......@@ -297,7 +413,7 @@
},
{
"result": {
"duration": 728000,
"duration": 312000,
"status": "passed"
},
"line": 19,
......@@ -319,7 +435,7 @@
},
{
"result": {
"duration": 375000,
"duration": 137000,
"status": "passed"
},
"line": 20,
......@@ -343,7 +459,7 @@
]
},
{
"start_timestamp": "2021-04-06T20:20:59.476Z",
"start_timestamp": "2021-04-06T21:12:23.600Z",
"line": 25,
"name": "Subtract two numbers 10 and 15",
"description": "",
......@@ -353,7 +469,7 @@
"steps": [
{
"result": {
"duration": 1136000,
"duration": 107000,
"status": "passed"
},
"line": 18,
......@@ -365,7 +481,7 @@
},
{
"result": {
"duration": 543000,
"duration": 132000,
"status": "passed"
},
"line": 19,
......@@ -387,7 +503,7 @@
},
{
"result": {
"duration": 261000,
"duration": 275000,
"status": "passed"
},
"line": 20,
......@@ -411,7 +527,7 @@
]
},
{
"start_timestamp": "2021-04-06T20:20:59.493Z",
"start_timestamp": "2021-04-06T21:12:23.606Z",
"line": 26,
"name": "Subtract two numbers 99 and -99",
"description": "",
......@@ -421,7 +537,7 @@
"steps": [
{
"result": {
"duration": 567000,
"duration": 187000,
"status": "passed"
},
"line": 18,
......@@ -433,7 +549,7 @@
},
{
"result": {
"duration": 283000,
"duration": 132000,
"status": "passed"
},
"line": 19,
......@@ -455,7 +571,7 @@
},
{
"result": {
"duration": 522000,
"duration": 115000,
"status": "passed"
},
"line": 20,
......@@ -479,7 +595,7 @@
]
},
{
"start_timestamp": "2021-04-06T20:20:59.516Z",
"start_timestamp": "2021-04-06T21:12:23.613Z",
"line": 27,
"name": "Subtract two numbers -1 and -10",
"description": "",
......@@ -489,7 +605,7 @@
"steps": [
{
"result": {
"duration": 146000,
"duration": 129000,
"status": "passed"
},
"line": 18,
......@@ -501,7 +617,7 @@
},
{
"result": {
"duration": 361000,
"duration": 230000,
"status": "passed"
},
"line": 19,
......@@ -523,7 +639,7 @@
},
{
"result": {
"duration": 151000,
"duration": 118000,
"status": "passed"
},
"line": 20,
......
<?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
......
This source diff could not be displayed because it is too large. You can view the blob instead.
@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