Cucumber hooks - http://jira.baeldung.com/browse/BAEL-3590
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
package com.baeldung.cucumberhooks.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 + "]";
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.cucumberhooks.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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user