### Question:
DeleteNoteByIdAPIController { @RequestMapping(value = "/{noteId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public String deleteNoteById( @PathVariable("noteId") Long id, HttpSession session ) throws AcmObjectNotFoundException, AcmUserActionFailedException { log.info("Finding note with ID : [{}]", id); String ipAddress = (String) session.getAttribute("acm_ip_address"); if (id != null) { Note note = getNoteDao().find(id); try { log.info("Deleting note by ID : [{}]", id); JSONObject objectToReturnJSON = new JSONObject(); getNoteDao().deleteNoteById(id); ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", true, ipAddress); getNoteEventPublisher().publishNoteEvent(event); objectToReturnJSON.put("deletedNoteId", id); String objectToReturn; objectToReturn = objectToReturnJSON.toString(); return objectToReturn; } catch (PersistenceException e) { ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", false, ipAddress); getNoteEventPublisher().publishNoteEvent(event); throw new AcmUserActionFailedException("Delete", "note", id, e.getMessage(), e); } } throw new AcmObjectNotFoundException("Note", id, "Could not find note", null); }  @RequestMapping(value = "/{noteId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String deleteNoteById(
            @PathVariable("noteId") Long id,
            HttpSession session

    ); NoteDao getNoteDao(); void setNoteDao(NoteDao noteDao); NoteEventPublisher getNoteEventPublisher(); void setNoteEventPublisher(NoteEventPublisher noteEventPublisher);  }### Answer:
@Test public void deleteNoteById() throws Exception { Long noteId = 700L; Long parentId = 800L; expect(mockNote.getId()).andReturn(noteId); expect(mockNote.getCreated()).andReturn(new Date()); expect(mockNote.getModifier()).andReturn("user"); expect(mockNote.getParentId()).andReturn(parentId); expect(mockNote.getParentType()).andReturn("PARENT_TYPE"); expect(mockNoteDao.find(eq(noteId))).andReturn(mockNote); mockNoteDao.deleteNoteById(eq(noteId)); expectLastCall(); Capture<ApplicationNoteEvent> capturedEvent = newCapture(); mockNoteEventPublisher.publishNoteEvent(capture(capturedEvent)); expectLastCall(); expect(mockAuthentication.getName()).andReturn("user"); replayAll(); MvcResult result = mockMvc.perform( delete("/api/latest/plugin/note/{noteId}", noteId) .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .session(mockHttpSession) .principal(mockAuthentication)) .andReturn(); verifyAll(); log.info("log" + result.getResponse()); log.info("log" + result); log.info("log" + result.getResponse().getStatus()); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); assertEquals(capturedEvent.getValue().getSource(), mockNote); }
@Test public void deleteNoteById_notFound() throws Exception { Long noteId = 234L; Long parentId = 800L; expect(mockNote.getId()).andReturn(noteId); expect(mockNote.getCreated()).andReturn(new Date()); expect(mockNote.getModifier()).andReturn("user"); expect(mockNote.getParentId()).andReturn(parentId); expect(mockNote.getParentType()).andReturn("PARENT_TYPE"); expect(mockNoteDao.find(eq(noteId))).andReturn(mockNote); mockNoteDao.deleteNoteById(eq(noteId)); expectLastCall(); Capture<ApplicationNoteEvent> capturedEvent = newCapture(); mockNoteEventPublisher.publishNoteEvent(capture(capturedEvent)); expectLastCall(); expect(mockAuthentication.getName()).andReturn("user"); replayAll(); mockMvc.perform( delete("/api/latest/plugin/note/{noteId}", noteId) .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .principal(mockAuthentication)); verifyAll(); }