Skip to content

Commit

Permalink
Fix SpeechAnnouncementListener example and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Aug 3, 2018
1 parent d8dbb39 commit ba4e66a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Expand Up @@ -167,7 +167,7 @@ public void onInstructionListVisibilityChanged(boolean shown) {

@Override
public SpeechAnnouncement willVoice(SpeechAnnouncement announcement) {
return announcement.toBuilder().announcement("All announcments will be the same.").build();
return SpeechAnnouncement.builder().announcement("All announcements will be the same.").build();
}

@Override
Expand Down
Expand Up @@ -79,6 +79,9 @@ public abstract static class Builder {
* <p>
* If you pass the milestone into the builder, {@link SpeechAnnouncement} will extract both the SSML
* and normal speech announcements.
* <p>
* Note, the milestone, if passed will override {@link SpeechAnnouncement#announcement()} and
* {@link SpeechAnnouncement#ssmlAnnouncement()}.
*
* @param milestone optional {@link VoiceInstructionMilestone} with SSML / normal announcements
* @return this builder for chaining options together
Expand Down
@@ -0,0 +1,40 @@
package com.mapbox.services.android.navigation.ui.v5.voice;

import com.mapbox.services.android.navigation.v5.milestone.VoiceInstructionMilestone;

import org.junit.Test;

import static junit.framework.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class SpeechAnnouncementTest {

@Test
public void milestoneAnnouncement_isUsedWhenProvided() {
VoiceInstructionMilestone milestone = mock(VoiceInstructionMilestone.class);
String announcement = "Milestone announcement";
when(milestone.getAnnouncement()).thenReturn(announcement);

SpeechAnnouncement speechAnnouncement = SpeechAnnouncement.builder()
.voiceInstructionMilestone(milestone)
.build();

assertEquals(announcement, speechAnnouncement.announcement());
}

@Test
public void milestoneSsmlAnnouncement_isUsedWhenProvided() {
VoiceInstructionMilestone milestone = mock(VoiceInstructionMilestone.class);
String announcement = "Milestone announcement";
when(milestone.getAnnouncement()).thenReturn(announcement);
String ssmlAnnouncement = "Milestone SSML announcement";
when(milestone.getSsmlAnnouncement()).thenReturn(ssmlAnnouncement);

SpeechAnnouncement speechAnnouncement = SpeechAnnouncement.builder()
.voiceInstructionMilestone(milestone)
.build();

assertEquals(ssmlAnnouncement, speechAnnouncement.ssmlAnnouncement());
}
}

0 comments on commit ba4e66a

Please sign in to comment.