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:
François Dupire
2019-12-11 19:25:03 +01:00
committed by maibin
parent dfb9ae68a6
commit c8cafe8cd2
7 changed files with 145 additions and 11 deletions
@@ -19,10 +19,4 @@ public class BookStore {
.filter(book -> Objects.equals(author, book.getAuthor()))
.collect(Collectors.toList());
}
public Optional<Book> bookByTitle(String title) {
return books.stream()
.filter(book -> book.getTitle().equals(title))
.findFirst();
}
}
@@ -0,0 +1,35 @@
package com.baeldung.cucumberbackground.books;
public class Book {
private String title;
private String author;
public Book(String title, String author) {
this.title = title;
this.author = author;
}
public Book() {}
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;
}
@Override
public String toString() {
return "Book [title=" + title + ", author=" + author + "]";
}
}
@@ -0,0 +1,28 @@
package com.baeldung.cucumberbackground.books;
import java.util.*;
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());
}
public Optional<Book> bookByTitle(String title) {
return books.stream()
.filter(book -> book.getTitle().equals(title))
.findFirst();
}
}