additional answers mockito change repository method (#9082)

This commit is contained in:
Belma Jakupovic
2020-04-15 21:15:59 +02:00
committed by GitHub
parent 7178f731f1
commit 86c4eea3dd
3 changed files with 19 additions and 12 deletions
@@ -1,5 +1,9 @@
package com.baeldung.mockito.additionalanswers;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class BookRepository {
public Book getByBookId(Long bookId) {
return new Book(bookId, "To Kill a Mocking Bird", "Harper Lee", 256);
@@ -9,9 +13,12 @@ public class BookRepository {
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;
public Book selectRandomBook(Book bookOne, Book bookTwo, Book bookThree) {
List<Book> selection = new ArrayList<>();
selection.add(bookOne);
selection.add(bookTwo);
selection.add(bookThree);
Random random = new Random();
return selection.get(random.nextInt(selection.size()));
}
}
@@ -15,8 +15,8 @@ public class BookService {
return bookRepository.save(book);
}
public Book checkifEquals(Book book1, Book book2, Book book3) {
return bookRepository.checkIfEquals(book1, book2, book3);
public Book selectRandomBook(Book book1, Book book2, Book book3) {
return bookRepository.selectRandomBook(book1, book2, book3);
}
}