Spring Boot, Mockito, Unit Testing, Junit 5, Rest Api.
when(this.booksRepository.save(any())).thenThrow(RuntimeException.class); Books savedBook = null; try { savedBook = this.bookService.saveBook(books); assertThat(savedBook.getId()).isNull(); } catch (Exception e) { assertThat(e).isInstanceOf(RuntimeException.class); } } @Test public void