I want to write a test for my BookService. This is that test. I don't know why I get the below error all the time:
org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter
[com.mrfisherman.library.service.domain.BookService bookService] in constructor
[public com.mrfisherman.library.service.domain.BookServiceTest(com.mrfisherman.library.service.domain.BookService,
com.mrfisherman.library.persistence.repository.BookRepository)].
As you can see I don't use parametrized tests here. Thank you in advance!
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Server.class)
class BookServiceTest {
private final BookService bookService;
private final BookRepository bookRepository;
public BookServiceTest(BookService bookService, BookRepository bookRepository) {
this.bookService = bookService;
this.bookRepository = bookRepository;
}
@Test
void saveBook() {
//given
Book book = new Book();
book.setTitle("Book 1");
book.setPublishYear(1990);
book.setType(BookFormat.REAL);
book.setIsbn("1234567890");
book.setDescription("Very good book");
book.setNumberOfPages(190);
book.setSummary("Very short summary");
book.setCategories(Set.of(new Category("horror"), new Category("drama")));
//when
bookService.saveBook(book);
//then
Optional<Book> loaded = bookRepository.findById(book.getId());
assertThat(loaded).isPresent();
}
}