Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
fix: Null check for destroying Android ASR
Browse files Browse the repository at this point in the history
  • Loading branch information
space-pope committed Aug 12, 2020
1 parent 5747c42 commit c84393d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ public void reset() {
@Override
public void close() {
this.taskHandler.run(() -> {
this.speechRecognizer.destroy();
this.speechRecognizer = null;
if (this.speechRecognizer != null) {
this.speechRecognizer.destroy();
this.speechRecognizer = null;
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ private void configureRecognizer(SpeechRecognizer target,
).when(target).setRecognitionListener(any());
}

@Test
public void testClose() {
SpeechConfig config = new SpeechConfig();
config.put("trace-level", EventTracer.Level.DEBUG.value());
config.put("min-active", 500);
AndroidSpeechRecognizer speechRecognizer =
spy(new AndroidSpeechRecognizer(config, new TaskHandler(false)));
doReturn(null).when(speechRecognizer).createRecognitionIntent();

// closing before establishing a recognizer is safe
assertDoesNotThrow(speechRecognizer::close);
}

@Test
public void testProcess() {
SpeechConfig config = new SpeechConfig();
Expand Down

0 comments on commit c84393d

Please sign in to comment.