GridWidget extends BaseGridWidget { @Override protected void onItemClick(int index) { if (!selectedItems.contains(index)) { if (selectedItems.isEmpty()) { selectItem(index); } else { unselectItem(selectedItems.get(0)); selectItem(index); } } else { getAudioHelper().stop(); } if (quickAdvance && listener != null) { listener.advance(); } if (noButtonsMode) { SelectChoice item = items.get(index); Clip clip = getClip(getFormEntryPrompt(), item, getReferenceManager()); if (clip != null) { getAudioHelper().play(clip); } } widgetValueChanged(); } GridWidget(Context context, QuestionDetails questionDetails, final boolean quickAdvance); @Override IAnswerData getAnswer(); @Override void setChoiceSelected(int choiceIndex, boolean isSelected);  }
@Test public void whenChoicesHaveAudio_andNoButtonsMode_clickingChoice_playsAndStopsAudio() throws Exception { createMockReference(referenceManager, "file: String reference = createMockReference(referenceManager, "file: formEntryPrompt = new MockFormEntryPromptBuilder() .withIndex("i am index") .withAppearance(NO_BUTTONS) .withSelectChoices(asList( new SelectChoice("1", "1"), new SelectChoice("2", "2") )) .withSpecialFormSelectChoiceText(asList( new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, "file: new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, "file: )) .build(); GridWidget widget = getActualWidget(); widget.onItemClick(0); verify(audioHelper).play(new Clip("i am index 0", reference)); widget.onItemClick(0); verify(audioHelper).stop(); }
@Test public void whenChoicesHaveAudio_clickingChoice_doesNotPlayAudio() throws Exception { createMockReference(referenceManager, "file: createMockReference(referenceManager, "file: formEntryPrompt = new MockFormEntryPromptBuilder() .withIndex("i am index") .withSelectChoices(asList( new SelectChoice("1", "1"), new SelectChoice("2", "2") )) .withSpecialFormSelectChoiceText(asList( new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, "file: new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, "file: )) .build(); GridWidget widget = getActualWidget(); widget.onItemClick(0); verify(audioHelper, never()).play(any()); }