I am writing unit test case for update method for book.
@Test
void testUpdateBook() {
//initializing the bookId here
givenBookId();
//initializing the book here
givenBook();
givenMock();
//call the updateBook method
whenUpdateBookRequested();
thenVerifyBook();
}
givenMock() {
when(bookRepository.updateBook(bookId,any()).thenReturn(Optional.ofNullable(expectedBook));
}
Every other method is working fine but givenMock() is producing error:
Invalid use of argument matchers. 2 matchers expected, 1 recorded
And if I write the same method like below, then test is running successfully but I am not able to understand the meaning of eq(). Can someone please explain the difference between the previous and the modified method?
givenMock(){
when(bookRepository.updateBook(eq(bookId),any()).thenReturn(Optional.ofNullable(expectedBook));
}