Search in sources :

Example 1 with AudioRecorder

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

the class FormEntryMenuDelegateTest method setup.

@Before
public void setup() {
    activity = RobolectricHelpers.createThemedActivity(AppCompatActivity.class, R.style.Theme_MaterialComponents);
    FormController formController = mock(FormController.class);
    answersProvider = mock(AnswersProvider.class);
    formSaveViewModel = mock(FormSaveViewModel.class);
    audioRecorder = mock(AudioRecorder.class);
    when(audioRecorder.isRecording()).thenReturn(false);
    formEntryViewModel = mock(FormEntryViewModel.class);
    when(formEntryViewModel.hasBackgroundRecording()).thenReturn(new MutableNonNullLiveData<>(false));
    BackgroundLocationViewModel backgroundLocationViewModel = mock(BackgroundLocationViewModel.class);
    backgroundAudioViewModel = mock(BackgroundAudioViewModel.class);
    when(backgroundAudioViewModel.isBackgroundRecordingEnabled()).thenReturn(new MutableNonNullLiveData<>(true));
    formEntryMenuDelegate = new FormEntryMenuDelegate(activity, answersProvider, mock(FormIndexAnimationHandler.class), formSaveViewModel, formEntryViewModel, audioRecorder, backgroundLocationViewModel, backgroundAudioViewModel, TestSettingsProvider.getSettingsProvider());
    formEntryMenuDelegate.formLoaded(formController);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) BackgroundLocationViewModel(org.odk.collect.android.formentry.backgroundlocation.BackgroundLocationViewModel) FormSaveViewModel(org.odk.collect.android.formentry.saving.FormSaveViewModel) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) AnswersProvider(org.odk.collect.android.formentry.questions.AnswersProvider) Before(org.junit.Before)

Example 2 with AudioRecorder

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

the class FormSaveViewModelTest method setup.

@Before
public void setup() {
    // Useful given some methods will execute AsyncTasks
    Robolectric.getBackgroundThreadScheduler().pause();
    formController = mock(FormController.class);
    logger = mock(AuditEventLogger.class);
    mediaUtils = mock(MediaUtils.class);
    Analytics analytics = mock(Analytics.class);
    when(formController.getAuditEventLogger()).thenReturn(logger);
    when(logger.isChangeReasonRequired()).thenReturn(false);
    audioRecorder = mock(AudioRecorder.class);
    currentProjectProvider = mock(CurrentProjectProvider.class);
    when(currentProjectProvider.getCurrentProject()).thenReturn(Project.Companion.getDEMO_PROJECT());
    viewModel = new FormSaveViewModel(savedStateHandle, () -> CURRENT_TIME, formSaver, mediaUtils, analytics, scheduler, audioRecorder, currentProjectProvider);
    viewModel.formLoaded(formController);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) CurrentProjectProvider(org.odk.collect.android.projects.CurrentProjectProvider) FormSaveViewModel(org.odk.collect.android.formentry.saving.FormSaveViewModel) MediaUtils(org.odk.collect.android.utilities.MediaUtils) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) Analytics(org.odk.collect.analytics.Analytics) Before(org.junit.Before)

Example 3 with AudioRecorder

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

the class BackgroundAudioPermissionDialogFragmentTest method setup.

@Before
public void setup() {
    backgroundAudioViewModel = mock(BackgroundAudioViewModel.class);
    fakePermissionsProvider = new FakePermissionsProvider();
    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 PermissionsProvider providesPermissionsProvider(PermissionsChecker permissionsChecker) {
            return fakePermissionsProvider;
        }
    });
}
Also used : AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) Analytics(org.odk.collect.analytics.Analytics) PermissionsProvider(org.odk.collect.permissions.PermissionsProvider) FakePermissionsProvider(org.odk.collect.android.fakes.FakePermissionsProvider) SettingsProvider(org.odk.collect.settings.SettingsProvider) NonNull(androidx.annotation.NonNull) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) PermissionsChecker(org.odk.collect.permissions.PermissionsChecker) FakePermissionsProvider(org.odk.collect.android.fakes.FakePermissionsProvider) Before(org.junit.Before)

Example 4 with AudioRecorder

use of org.odk.collect.audiorecorder.recording.AudioRecorder 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 5 with AudioRecorder

use of org.odk.collect.audiorecorder.recording.AudioRecorder 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

AudioRecorder (org.odk.collect.audiorecorder.recording.AudioRecorder)6 Before (org.junit.Before)5 Analytics (org.odk.collect.analytics.Analytics)4 NonNull (androidx.annotation.NonNull)3 File (java.io.File)3 FormSaveViewModel (org.odk.collect.android.formentry.saving.FormSaveViewModel)3 AppDependencyModule (org.odk.collect.android.injection.config.AppDependencyModule)3 FormController (org.odk.collect.android.javarosawrapper.FormController)3 PermissionsChecker (org.odk.collect.permissions.PermissionsChecker)3 Application (android.app.Application)2 BackgroundAudioViewModel (org.odk.collect.android.formentry.BackgroundAudioViewModel)2 FormEntryViewModel (org.odk.collect.android.formentry.FormEntryViewModel)2 CurrentProjectProvider (org.odk.collect.android.projects.CurrentProjectProvider)2 StubAudioRecorder (org.odk.collect.audiorecorder.testsupport.StubAudioRecorder)2 SettingsProvider (org.odk.collect.settings.SettingsProvider)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 BUTTON_NEGATIVE (android.content.DialogInterface.BUTTON_NEGATIVE)1 BUTTON_POSITIVE (android.content.DialogInterface.BUTTON_POSITIVE)1