### Question:
SongPublicationService { public void publishSong(final Song song) { songsRepository.storeSong(song); publicationNotifier.onSongPublished(song); }  Optional<Song> getSong(final String songIdentifier); void publishSong(final Song song);  }### Answer:
@Test(expected = SongIdentifierExistsException.class) public void whenAnotherSongExistsWithSameId_ExceptionIsThrownAndNoEventPublished() { doThrow(new SongIdentifierExistsException("id")) .when(songsRepository).storeSong(SONG); songPublicationService.publishSong(SONG); verifyZeroInteractions(publicationNotifier); }
@Test public void testPublishSongStoresSongInRepositoryAndPublishesEvent() { songPublicationService.publishSong(SONG); verify(songsRepository).storeSong(SONG); verify(publicationNotifier).onSongPublished(SONG); }