[voice] Fix try all interpreters (#2980)

* fix try all interpreters
* add test

Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com>
This commit is contained in:
GiviMAD
2022-05-26 07:47:28 +02:00
committed by GitHub
parent dd13da5d32
commit f5da311608
2 changed files with 15 additions and 1 deletions
@@ -302,6 +302,7 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider {
if (!interpreters.isEmpty()) {
Locale locale = localeProvider.getLocale();
InterpretationException exception = null;
for (var interpreter : interpreters) {
try {
String answer = interpreter.interpret(locale, text);
@@ -309,9 +310,10 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider {
return answer;
} catch (InterpretationException e) {
logger.debug("Interpretation exception: {}", e.getMessage());
throw e;
exception = e;
}
}
throw exception;
}
if (hliIdList == null) {
@@ -177,6 +177,18 @@ public class VoiceManagerImplTest extends JavaOSGiTest {
assertThat(result, is("Interpreted text"));
}
@Test
public void interpretSomethingWithGivenMultipleHliIdsWhenFirstFails() throws InterpretationException {
hliStub = new HumanLanguageInterpreterStub();
registerService(hliStub);
hliStub.setExceptionExpected(true);
var anotherHLIStub = new HumanLanguageInterpreterStub();
registerService(anotherHLIStub);
String result = voiceManager.interpret("something",
String.join(",", List.of(hliStub.getId(), anotherHLIStub.getId())));
assertThat(result, is("Interpreted text"));
}
@Test
public void verifyThatADialogIsNotStartedWhenAnyOfTheRequiredServiceIsNull() {
sttService = new STTServiceStub();