Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.List;

import static junit.framework.TestCase.assertEquals;

@RunWith(AndroidJUnit4.class)
Expand All @@ -59,4 +62,25 @@ public void testSettersAndGetters() {
assertEquals(voiceCommand.getVoiceCommandSelectionListener(), voiceCommandSelectionListener);
}

@Test
public void testDuplicateStrings() {
List<String> voiceCommandsList = new ArrayList<>();
voiceCommandsList.add("Test1");
voiceCommandsList.add("Test1");
voiceCommandsList.add("Test1");
VoiceCommand voiceCommand = new VoiceCommand(voiceCommandsList, voiceCommandSelectionListener);

assertEquals(1, voiceCommand.getVoiceCommands().size());
assertEquals("Test1", voiceCommand.getVoiceCommands().get(0));

voiceCommandsList = new ArrayList<>();
voiceCommandsList.add("Test1");
voiceCommandsList.add("Test2");
voiceCommandsList.add("Test1");
VoiceCommand voiceCommand2 = new VoiceCommand(voiceCommandsList, voiceCommandSelectionListener);

assertEquals(2, voiceCommand2.getVoiceCommands().size());
assertEquals("Test1", voiceCommand2.getVoiceCommands().get(0));
assertEquals("Test2", voiceCommand2.getVoiceCommands().get(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import androidx.annotation.Nullable;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

public class VoiceCommand {
Expand Down Expand Up @@ -77,7 +79,7 @@ public VoiceCommand(@NonNull List<String> voiceCommands, @Nullable VoiceCommandS
* @param voiceCommands - the list of commands to send to the head unit
*/
public void setVoiceCommands(@NonNull List<String> voiceCommands) {
this.voiceCommands = voiceCommands;
this.voiceCommands = new ArrayList<>(removeDuplicateStrings(voiceCommands));
}

/**
Expand Down Expand Up @@ -126,6 +128,10 @@ int getCommandId() {
return commandId;
}

private HashSet<String> removeDuplicateStrings(List<String> voiceCommands) {
return new HashSet<>(voiceCommands);
}

/**
* Used to compile hashcode for VoiceCommand for use to compare in equals method
*
Expand Down