Search in sources :

Example 1 with StubAudioRecorder

use of org.odk.collect.audiorecorder.testsupport.StubAudioRecorder in project collect by opendatakit.

the class AudioRecordingControllerFragmentTest method setup.

@Before
public void setup() throws IOException {
    File stubRecording = File.createTempFile("test", ".m4a");
    stubRecording.deleteOnExit();
    audioRecorder = new StubAudioRecorder(stubRecording.getAbsolutePath());
    backgroundAudioViewModel = mock(BackgroundAudioViewModel.class);
    formEntryViewModel = mock(FormEntryViewModel.class);
    hasBackgroundRecording = new MutableNonNullLiveData<>(false);
    when(formEntryViewModel.hasBackgroundRecording()).thenReturn(hasBackgroundRecording);
    isBackgroundRecordingEnabled = new MutableNonNullLiveData<>(false);
    when(backgroundAudioViewModel.isBackgroundRecordingEnabled()).thenReturn(isBackgroundRecordingEnabled);
    externalWebPageHelper = mock(ExternalWebPageHelper.class);
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public BackgroundAudioViewModel.Factory providesBackgroundAudioViewModelFactory(AudioRecorder audioRecorder, SettingsProvider settingsProvider, PermissionsChecker permissionsChecker, Analytics analytics) {
            return new BackgroundAudioViewModel.Factory(audioRecorder, settingsProvider.getUnprotectedSettings(), permissionsChecker, System::currentTimeMillis) {

                @NonNull
                @Override
                public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
                    return (T) backgroundAudioViewModel;
                }
            };
        }

        @Override
        public FormEntryViewModel.Factory providesFormEntryViewModelFactory(Analytics analytics) {
            return new FormEntryViewModel.Factory(System::currentTimeMillis) {

                @NonNull
                @Override
                public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
                    return (T) formEntryViewModel;
                }
            };
        }

        @Override
        public AudioRecorder providesAudioRecorder(Application application) {
            return audioRecorder;
        }

        @Override
        public ExternalWebPageHelper providesExternalWebPageHelper() {
            return externalWebPageHelper;
        }
    });
}
Also used : StubAudioRecorder(org.odk.collect.audiorecorder.testsupport.StubAudioRecorder) FormEntryViewModel(org.odk.collect.android.formentry.FormEntryViewModel) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) Analytics(org.odk.collect.analytics.Analytics) SettingsProvider(org.odk.collect.settings.SettingsProvider) NonNull(androidx.annotation.NonNull) StubAudioRecorder(org.odk.collect.audiorecorder.testsupport.StubAudioRecorder) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) PermissionsChecker(org.odk.collect.permissions.PermissionsChecker) BackgroundAudioViewModel(org.odk.collect.android.formentry.BackgroundAudioViewModel) File(java.io.File) Application(android.app.Application) ExternalWebPageHelper(org.odk.collect.android.utilities.ExternalWebPageHelper) Before(org.junit.Before)

Example 2 with StubAudioRecorder

use of org.odk.collect.audiorecorder.testsupport.StubAudioRecorder in project collect by opendatakit.

the class AudioRecordingFormErrorDialogFragmentTest method setup.

@Before
public void setup() throws Exception {
    File stubRecording = File.createTempFile("test", ".m4a");
    stubRecording.deleteOnExit();
    audioRecorder = new StubAudioRecorder(stubRecording.getAbsolutePath());
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public AudioRecorder providesAudioRecorder(Application application) {
            return audioRecorder;
        }
    });
}
Also used : StubAudioRecorder(org.odk.collect.audiorecorder.testsupport.StubAudioRecorder) StubAudioRecorder(org.odk.collect.audiorecorder.testsupport.StubAudioRecorder) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) File(java.io.File) Application(android.app.Application) Before(org.junit.Before)

Aggregations

Application (android.app.Application)2 File (java.io.File)2 Before (org.junit.Before)2 AppDependencyModule (org.odk.collect.android.injection.config.AppDependencyModule)2 AudioRecorder (org.odk.collect.audiorecorder.recording.AudioRecorder)2 StubAudioRecorder (org.odk.collect.audiorecorder.testsupport.StubAudioRecorder)2 NonNull (androidx.annotation.NonNull)1 Analytics (org.odk.collect.analytics.Analytics)1 BackgroundAudioViewModel (org.odk.collect.android.formentry.BackgroundAudioViewModel)1 FormEntryViewModel (org.odk.collect.android.formentry.FormEntryViewModel)1 ExternalWebPageHelper (org.odk.collect.android.utilities.ExternalWebPageHelper)1 PermissionsChecker (org.odk.collect.permissions.PermissionsChecker)1 SettingsProvider (org.odk.collect.settings.SettingsProvider)1