### Question:
RecordingsService { public Optional<RecordingData> getLastRecording() { return recordingsRepository.findTopByOrderByTimestampDesc() .map(RecordingData::fromEntity); } RecordingsService(final RecordingsRepository recordingsRepository); Optional<RecordingData> getLastRecording(); List<RecordingData> listRecordings(final int pageNumber, final int size);  }### Answer:
@Test public void getLastRecordingQueriesTheRepositoryForTheLastRecording() { final RecordingEntity givenRecordingEntity = givenRecordingEntity(); given(recordingsRepository.findTopByOrderByTimestampDesc()) .willReturn(Optional.of(givenRecordingEntity)); final Optional<RecordingData> optionalLastRecording = victim.getLastRecording(); assertThat(optionalLastRecording) .hasValueSatisfying(lastRecording -> assertThat(lastRecording) .extracting( RecordingData::getTimestamp, RecordingData::getRequest, RecordingData::getReply) .contains( givenRecordingEntity.getTimestamp(), base16().encode(givenRecordingEntity.getRequest()), base16().encode(givenRecordingEntity.getReply()))); }
@Test public void getLastRecordingsReturnsEmptyIfRepositoryIsEmpty() { given(recordingsRepository.findTopByOrderByTimestampDesc()) .willReturn(Optional.empty()); final Optional<RecordingData> recordingData = victim.getLastRecording(); assertThat(recordingData).isEmpty(); }