Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
awa-w5d4-cucumber-tenminutetutorial
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Eric Arndt
awa-w5d4-cucumber-tenminutetutorial
Commits
72f30e7b
Commit
72f30e7b
authored
Apr 06, 2021
by
earndt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[W6D2] (ArndtED) Adds working BookStore test
parent
dcecf319
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
1 deletion
+111
-1
Book.java
hellocucumber/src/test/java/hellocucumber/Book.java
+27
-0
BookStore.java
hellocucumber/src/test/java/hellocucumber/BookStore.java
+21
-0
BookStoreSteps.java
...ocucumber/src/test/java/hellocucumber/BookStoreSteps.java
+48
-0
RunCucumberTest.java
...cucumber/src/test/java/hellocucumber/RunCucumberTest.java
+5
-1
bookstore.feature
...cumber/src/test/resources/hellocucumber/bookstore.feature
+10
-0
No files found.
hellocucumber/src/test/java/hellocucumber/Book.java
0 → 100644
View file @
72f30e7b
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
String
getAuthor
()
{
return
author
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
void
setAuthor
(
String
author
)
{
this
.
author
=
author
;
}
}
hellocucumber/src/test/java/hellocucumber/BookStore.java
0 → 100644
View file @
72f30e7b
package
hellocucumber
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
public
class
BookStore
{
private
List
<
Book
>
books
=
new
ArrayList
<>();
public
void
addBook
(
Book
book
)
{
books
.
add
(
book
);}
public
void
addAllBooks
(
Collection
<
Book
>
books
)
{
this
.
books
.
addAll
(
books
);}
public
List
<
Book
>
booksByAuthor
(
String
author
){
return
books
.
stream
()
.
filter
(
book
->
Objects
.
equals
(
author
,
book
.
getAuthor
()))
.
collect
(
Collectors
.
toList
());
}
}
hellocucumber/src/test/java/hellocucumber/BookStoreSteps.java
0 → 100644
View file @
72f30e7b
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
org.junit.Assert
;
import
org.junit.Before
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
class
BookStoreTest
{
static
String
bookStore
(
String
bookStore
){
return
null
;
}
}
public
class
BookStoreSteps
{
private
BookStore
store
=
new
BookStore
();
private
List
<
Book
>
foundBooks
;
@Before
public
void
setUp
(){
foundBooks
=
new
ArrayList
<>();
}
@Given
(
"^The following books are in the bookstore$"
)
public
void
the_following_books_are_in_the_bookstore
(
DataTable
data
){
List
<
Map
<
String
,
String
>>
rows
=
data
.
asMaps
(
String
.
class
,
String
.
class
);
for
(
Map
<
String
,
String
>
columns
:
rows
)
{
store
.
addBook
(
new
Book
(
columns
.
get
(
"title"
),
columns
.
get
(
"author"
)));
}
}
@When
(
"^I search for books by author Neal Stephenson$"
)
public
void
i_search_for_books_by_author_neal_stephenson
()
throws
Throwable
{
foundBooks
=
store
.
booksByAuthor
(
"Neal Stephenson"
);
}
@Then
(
"^I find (\\d+) books$"
)
public
void
i_find_books
(
int
arg1
)
throws
Throwable
{
Assert
.
assertEquals
(
arg1
,
foundBooks
.
size
());
}
}
hellocucumber/src/test/java/hellocucumber/RunCucumberTest.java
View file @
72f30e7b
...
...
@@ -5,7 +5,11 @@ import io.cucumber.junit.CucumberOptions;
import
org.junit.runner.RunWith
;
@RunWith
(
Cucumber
.
class
)
@CucumberOptions
(
plugin
=
{
"pretty"
})
@CucumberOptions
(
plugin
=
{
"pretty"
,
"html:target/surefire-reports/html"
,
"json:target/surefire-reports/json/report.json"
,
"junit:target/surefire-reports/junit/report.xml"
},
monochrome
=
true
)
public
class
RunCucumberTest
{
}
hellocucumber/src/test/resources/hellocucumber/bookstore.feature
0 → 100644
View file @
72f30e7b
Feature
:
Book Store
Scenario
:
Find correct nonzero number of books by author
Given
The following books are in the bookstore
|
title
|
author
|
|
Anathem
|
Neal
Stephenson
|
|
The
Beach
|
Alex
Garland
|
|
Snow
Crash
|
Neal
Stephenson
|
When
I search for books by author Neal Stephenson
Then
I find 2 books
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment