BookController { @GetMapping("/findByTitle/{title}") public Book findBookByTitle(@NotNull @PathVariable String title) throws BookNotFoundException { return this.bookService.findBookByTitle(title); }  @GetMapping("/findByTitle/{title}") Book findBookByTitle(@NotNull @PathVariable String title); @PostMapping("/saveBook") Book saveBook(@Valid @RequestBody Book book); @PutMapping("/updateByTitle/{title}/{author}") Book updateAuthorByTitle(@PathVariable("title") String title, @PathVariable("author") String author); @DeleteMapping("/deleteByTitle/{title}") ResponseEntity<String> deleteBookByTitle(@PathVariable("title") String title); @GetMapping("/deleteCache") String deleteCache(); void deleteAll();  }
@Test void getBookShouldReturnBook() throws Exception { given(this.bookService.findBookByTitle(anyString())).willReturn(Book.builder().title("JUNIT_TITLE") .author("JUNIT_AUTHOR").bookId("JUNIT").text("JUNIT_TEXT").version(1L).build()); this.mockMvc.perform(MockMvcRequestBuilders.get("/book/findByTitle/JUNIT_TITLE")).andExpect(status().isOk()) .andExpect(jsonPath("title").value("JUNIT_TITLE")).andExpect(jsonPath("author").value("JUNIT_AUTHOR")); }
@Test void getBookNotFound() throws Exception { given(this.bookService.findBookByTitle(anyString())) .willThrow(new BookNotFoundException("Book with Title Not Found")); this.mockMvc.perform(MockMvcRequestBuilders.get("/book/findByTitle/MongodbBook")) .andExpect(status().isNotFound()); }