### Question:
SongPublicationService { public Optional<Song> getSong(final String songIdentifier) { return songsRepository.getSong(songIdentifier); }  Optional<Song> getSong(final String songIdentifier); void publishSong(final Song song);  }### Answer:
@Test public void testGetSongReturnsSongReturnedByRepository() { when(songsRepository.getSong("id")) .thenReturn(Optional.of(SONG)); final Optional<Song> optionalSong = songPublicationService.getSong("id"); assertTrue(optionalSong.isPresent()); assertEquals(SONG, optionalSong.get()); }
@Test public void testGetSongReturnsEmptyOptional_WhenRepositoryReturnsNoSong() { when(songsRepository.getSong(any())) .thenReturn(Optional.empty()); final Optional<Song> optionalSong = songPublicationService.getSong("random-id"); assertFalse(optionalSong.isPresent()); }