### Question:
BookController { @PatchMapping("/books/{id}") Book patch(@RequestBody Map<String, String> update, @PathVariable Long id) { return repository.findById(id) .map(x -> { String author = update.get("author"); if (!StringUtils.isEmpty(author)) { x.setAuthor(author); return repository.save(x); } else { throw new BookUnSupportedFieldPatchException(update.keySet()); } }) .orElseGet(() -> { throw new BookNotFoundException(id); }); }    }### Answer:
@Test public void patch_bookAuthor_OK() throws Exception { when(mockRepository.save(any(Book.class))).thenReturn(new Book()); String patchInJson = "{\"author\":\"ultraman\"}"; mockMvc.perform(patch("/books/1") .content(patchInJson) .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()); verify(mockRepository, times(1)).findById(1L); verify(mockRepository, times(1)).save(any(Book.class)); }
@Test public void patch_bookPrice_405() throws Exception { String patchInJson = "{\"price\":\"99.99\"}"; mockMvc.perform(patch("/books/1") .content(patchInJson) .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)) .andExpect(status().isMethodNotAllowed()); verify(mockRepository, times(1)).findById(1L); verify(mockRepository, times(0)).save(any(Book.class)); }