Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SpeechAnnouncementListener example and add tests #1166

Merged
merged 1 commit into from Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test that AutoValue works as expected is not worth it IMO. Ultimately, it's like testing a setter. 👀 https://speakerdeck.com/guardiola31337/elegant-unit-testing-droidcon-berlin-2016?slide=68


@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());
}
}