Belma Jakupovic - Mockito additional answers (#9041)

This commit is contained in:
Belma Jakupovic
2020-04-06 20:22:28 +02:00
committed by GitHub
parent 0b1501aa96
commit b30ee62805
4 changed files with 165 additions and 0 deletions
@@ -0,0 +1,58 @@
package com.baeldung.mockito.additionalanswers;
public class Book {
private Long bookId;
private String title;
private String author;
private int numberOfPages;
public Book(String title, String author, int numberOfPages) {
this.title = title;
this.author = author;
this.numberOfPages = numberOfPages;
}
public Book(Long bookId, String title, String author, int numberOfPages) {
this.bookId = bookId;
this.title = title;
this.author = author;
this.numberOfPages = numberOfPages;
}
public Long getBookId() {
return bookId;
}
public void setBookId(Long bookId) {
this.bookId = bookId;
}
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;
}
public int getNumberOfPages() {
return numberOfPages;
}
public void setNumberOfPages(int numberOfPages) {
this.numberOfPages = numberOfPages;
}
}
@@ -0,0 +1,17 @@
package com.baeldung.mockito.additionalanswers;
public class BookRepository {
public Book getByBookId(Long bookId) {
return new Book(bookId, "To Kill a Mocking Bird", "Harper Lee", 256);
}
public Book save(Book book) {
return new Book(book.getBookId(), book.getTitle(), book.getAuthor(), book.getNumberOfPages());
}
public Book checkIfEquals(Book bookOne, Book bookTwo, Book bookThree) {
if (bookOne.equals(bookTwo) && bookTwo.equals(bookThree) && bookThree.equals(bookOne)) {
return bookOne;
} else return bookTwo;
}
}
@@ -0,0 +1,22 @@
package com.baeldung.mockito.additionalanswers;
public class BookService {
private final BookRepository bookRepository;
public BookService(BookRepository bookRepository) {
this.bookRepository = bookRepository;
}
public Book getByBookId(Long id) {
return bookRepository.getByBookId(id);
}
public Book save(Book book) {
return bookRepository.save(book);
}
public Book checkifEquals(Book book1, Book book2, Book book3) {
return bookRepository.checkIfEquals(book1, book2, book3);
}
}