### Question:
NavigationViewEventDispatcher { SpeechAnnouncement onAnnouncement(SpeechAnnouncement announcement) { if (speechAnnouncementListener != null) { String textAnnouncement = speechAnnouncementListener.willVoice(announcement); SpeechAnnouncement announcementToBeVoiced = SpeechAnnouncement.builder().announcement(textAnnouncement).build(); return announcementToBeVoiced; } return announcement; }    }### Answer:
@Test public void onNewVoiceAnnouncement_instructionListenerIsCalled() { SpeechAnnouncement originalAnnouncement = mock(SpeechAnnouncement.class); SpeechAnnouncementListener speechAnnouncementListener = mock(SpeechAnnouncementListener.class); String textAnnouncement = "announcement to be voiced"; when(speechAnnouncementListener.willVoice(originalAnnouncement)).thenReturn(textAnnouncement); NavigationViewEventDispatcher eventDispatcher = buildViewEventDispatcher(speechAnnouncementListener); eventDispatcher.onAnnouncement(originalAnnouncement); verify(speechAnnouncementListener).willVoice(originalAnnouncement); }
@Test public void onNewVoiceAnnouncement_announcementToBeVoicedIsReturned() { SpeechAnnouncement originalAnnouncement = SpeechAnnouncement.builder().announcement("announcement").build(); SpeechAnnouncementListener speechAnnouncementListener = mock(SpeechAnnouncementListener.class); String textAnnouncement = "announcement to be voiced"; when(speechAnnouncementListener.willVoice(originalAnnouncement)).thenReturn(textAnnouncement); NavigationViewEventDispatcher eventDispatcher = buildViewEventDispatcher(speechAnnouncementListener); SpeechAnnouncement modifiedAnnouncement = eventDispatcher.onAnnouncement(originalAnnouncement); assertEquals("announcement to be voiced", modifiedAnnouncement.announcement()); }