### Question:
RecordingsController { @GetMapping(path = "last") public ResponseEntity<RecordingData> getLastRecording() { return recordingsService.getLastRecording() .map(ResponseEntity::ok) .orElseGet(() -> ResponseEntity.notFound().build()); } RecordingsController(final RecordingsService recordingsService); @GetMapping(path = "last") ResponseEntity<RecordingData> getLastRecording(); @GetMapping(params = {"page", "size"}) List<RecordingData> getRecordings(@RequestParam("page") int page,
                                             @RequestParam("size") int size);  }### Answer:
@Test public void getLastRecordingReturnsTheValueProvidedByTheService() throws Exception { final RecordingData givenRecordingData = givenRecordingData(); given(recordingsService.getLastRecording()).willReturn(Optional.of(givenRecordingData)); this.mvc.perform( get("/recordings/last").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.timestamp", is(givenRecordingData.getTimestamp().toString()))) .andExpect(jsonPath("$.request", is(givenRecordingData.getRequest()))) .andExpect(jsonPath("$.reply", is(givenRecordingData.getReply()))); }
@Test public void getLastReturnsNotFoundIfNoRecordingIsAvailable() throws Exception { given(recordingsService.getLastRecording()).willReturn(Optional.empty()); this.mvc.perform( get("/recordings/last").accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isNotFound()); }