Search in sources :

Example 1 with RecordingSession

use of org.odk.collect.audiorecorder.recording.RecordingSession in project collect by opendatakit.

the class AudioRecorderRecordingStatusHandlerTest method onIsRecordingChangedBlocked_listensToCurrentSession.

@Test
public void onIsRecordingChangedBlocked_listensToCurrentSession() {
    MutableLiveData<RecordingSession> liveData = new MutableLiveData<>(null);
    when(audioRecorder.getCurrentSession()).thenReturn(liveData);
    Consumer<Boolean> listener = mock(Consumer.class);
    provider.onBlockedStatusChange(listener);
    verify(listener).accept(false);
    liveData.setValue(new RecordingSession("blah", null, 0, 0, false));
    verify(listener).accept(true);
}
Also used : MutableLiveData(androidx.lifecycle.MutableLiveData) RecordingSession(org.odk.collect.audiorecorder.recording.RecordingSession) Test(org.junit.Test)

Example 2 with RecordingSession

use of org.odk.collect.audiorecorder.recording.RecordingSession in project collect by opendatakit.

the class RecordingHandlerTest method whenBackgroundRecordingM4A_andRecordingAlreadySavedForReference_appendsAudioFiles.

@Test
public void whenBackgroundRecordingM4A_andRecordingAlreadySavedForReference_appendsAudioFiles() throws Exception {
    File recording = File.createTempFile("existing", ".m4a");
    File existingRecording = questionMediaManager.createAnswerFile(recording).getValue().getOrNull();
    assertThat(existingRecording, not(nullValue()));
    TreeReference treeReference = new TreeReference();
    when(formController.getAnswer(treeReference)).thenReturn(new StringData(existingRecording.getName()));
    File newRecording = File.createTempFile("new", ".m4a");
    RecordingSession recordingSession = new RecordingSession(new HashSet<TreeReference>() {

        {
            add(treeReference);
        }
    }, newRecording, 0, 0, false);
    recordingHandler.handle(formController, recordingSession, success -> {
    });
    verify(m4aAppender).append(existingRecording, questionMediaManager.getAnswerFile(newRecording.getName()));
}
Also used : TreeReference(org.javarosa.core.model.instance.TreeReference) StringData(org.javarosa.core.model.data.StringData) RecordingSession(org.odk.collect.audiorecorder.recording.RecordingSession) File(java.io.File) Test(org.junit.Test)

Example 3 with RecordingSession

use of org.odk.collect.audiorecorder.recording.RecordingSession in project collect by opendatakit.

the class RecordingHandlerTest method whenBackgroundRecording_andRecordingAlreadySavedForReference_deletesNewFile.

@Test
public void whenBackgroundRecording_andRecordingAlreadySavedForReference_deletesNewFile() throws Exception {
    File recording = File.createTempFile("existing", ".m4a");
    File existingRecording = questionMediaManager.createAnswerFile(recording).getValue().getOrNull();
    assertThat(existingRecording, not(nullValue()));
    TreeReference treeReference = new TreeReference();
    when(formController.getAnswer(treeReference)).thenReturn(new StringData(existingRecording.getName()));
    File newRecording = File.createTempFile("new", ".m4a");
    RecordingSession recordingSession = new RecordingSession(new HashSet<TreeReference>() {

        {
            add(treeReference);
        }
    }, newRecording, 0, 0, false);
    recordingHandler.handle(formController, recordingSession, success -> {
    });
    assertThat(questionMediaManager.getAnswerFile(newRecording.getName()).exists(), is(false));
}
Also used : TreeReference(org.javarosa.core.model.instance.TreeReference) StringData(org.javarosa.core.model.data.StringData) RecordingSession(org.odk.collect.audiorecorder.recording.RecordingSession) File(java.io.File) Test(org.junit.Test)

Example 4 with RecordingSession

use of org.odk.collect.audiorecorder.recording.RecordingSession in project collect by opendatakit.

the class RecordingHandlerTest method whenBackgroundRecordinAMR_andRecordingAlreadySavedForReference_appendsAudioFiles.

@Test
public void whenBackgroundRecordinAMR_andRecordingAlreadySavedForReference_appendsAudioFiles() throws Exception {
    File recording = File.createTempFile("existing", ".amr");
    File existingRecording = questionMediaManager.createAnswerFile(recording).getValue().getOrNull();
    assertThat(existingRecording, not(nullValue()));
    TreeReference treeReference = new TreeReference();
    when(formController.getAnswer(treeReference)).thenReturn(new StringData(existingRecording.getName()));
    File newRecording = File.createTempFile("new", ".amr");
    RecordingSession recordingSession = new RecordingSession(new HashSet<TreeReference>() {

        {
            add(treeReference);
        }
    }, newRecording, 0, 0, false);
    recordingHandler.handle(formController, recordingSession, success -> {
    });
    verify(amrAppender).append(existingRecording, questionMediaManager.getAnswerFile(newRecording.getName()));
}
Also used : TreeReference(org.javarosa.core.model.instance.TreeReference) StringData(org.javarosa.core.model.data.StringData) RecordingSession(org.odk.collect.audiorecorder.recording.RecordingSession) File(java.io.File) Test(org.junit.Test)

Example 5 with RecordingSession

use of org.odk.collect.audiorecorder.recording.RecordingSession in project collect by opendatakit.

the class AudioRecorderRecordingStatusHandlerTest method whenViewModelSessionUpdates_callsInProgressListener.

@Test
public void whenViewModelSessionUpdates_callsInProgressListener() {
    FormEntryPrompt prompt = promptWithAnswer(null);
    MutableLiveData<RecordingSession> sessionLiveData = new MutableLiveData<>(null);
    when(audioRecorder.getCurrentSession()).thenReturn(sessionLiveData);
    Consumer<Pair<Long, Integer>> listener = mock(Consumer.class);
    provider.onRecordingStatusChange(prompt, listener);
    verify(listener).accept(null);
    sessionLiveData.setValue(new RecordingSession(prompt.getIndex(), null, 1200L, 25, false));
    verify(listener).accept(new Pair<>(1200L, 25));
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) MutableLiveData(androidx.lifecycle.MutableLiveData) RecordingSession(org.odk.collect.audiorecorder.recording.RecordingSession) Pair(android.util.Pair) Test(org.junit.Test)

Aggregations

RecordingSession (org.odk.collect.audiorecorder.recording.RecordingSession)8 Test (org.junit.Test)6 TreeReference (org.javarosa.core.model.instance.TreeReference)4 MutableLiveData (androidx.lifecycle.MutableLiveData)3 File (java.io.File)3 StringData (org.javarosa.core.model.data.StringData)3 Pair (android.util.Pair)2 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)2 HashSet (java.util.HashSet)1